src/cx/list.h

Mon, 18 Dec 2023 14:14:47 +0100

author
Mike Becker <universe@uap-core.de>
date
Mon, 18 Dec 2023 14:14:47 +0100
changeset 759
475335643af4
parent 741
1210ee2d755f
child 764
ccbdbd088455
permissions
-rw-r--r--

increase version number to 3.1

remove per-file version information
from Doxygen output

universe@390 1 /*
universe@390 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
universe@390 3 *
universe@390 4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
universe@390 5 *
universe@390 6 * Redistribution and use in source and binary forms, with or without
universe@390 7 * modification, are permitted provided that the following conditions are met:
universe@390 8 *
universe@390 9 * 1. Redistributions of source code must retain the above copyright
universe@390 10 * notice, this list of conditions and the following disclaimer.
universe@390 11 *
universe@390 12 * 2. Redistributions in binary form must reproduce the above copyright
universe@390 13 * notice, this list of conditions and the following disclaimer in the
universe@390 14 * documentation and/or other materials provided with the distribution.
universe@390 15 *
universe@390 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
universe@390 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
universe@390 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
universe@390 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
universe@390 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
universe@390 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
universe@390 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
universe@390 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
universe@390 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
universe@390 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
universe@390 26 * POSSIBILITY OF SUCH DAMAGE.
universe@390 27 */
universe@453 28 /**
universe@453 29 * \file list.h
universe@453 30 * \brief Interface for list implementations.
universe@453 31 * \author Mike Becker
universe@453 32 * \author Olaf Wintermann
universe@453 33 * \copyright 2-Clause BSD License
universe@453 34 */
universe@390 35
universe@390 36 #ifndef UCX_LIST_H
universe@390 37 #define UCX_LIST_H
universe@390 38
universe@681 39 #include "common.h"
universe@677 40 #include "collection.h"
universe@398 41
universe@415 42 #ifdef __cplusplus
universe@415 43 extern "C" {
universe@415 44 #endif
universe@415 45
universe@464 46 /**
universe@500 47 * List class type.
universe@464 48 */
universe@500 49 typedef struct cx_list_class_s cx_list_class;
universe@435 50
universe@464 51 /**
universe@464 52 * Structure for holding the base data of a list.
universe@464 53 */
universe@435 54 struct cx_list_s {
universe@677 55 CX_COLLECTION_MEMBERS
universe@464 56 /**
universe@464 57 * The list class definition.
universe@464 58 */
universe@641 59 cx_list_class const *cl;
universe@641 60 /**
universe@641 61 * The actual implementation in case the list class is delegating.
universe@641 62 */
universe@641 63 cx_list_class const *climpl;
universe@435 64 };
universe@398 65
universe@464 66 /**
universe@500 67 * The class definition for arbitrary lists.
universe@500 68 */
universe@500 69 struct cx_list_class_s {
universe@500 70 /**
universe@524 71 * Destructor function.
universe@708 72 *
universe@708 73 * Implementations SHALL invoke the content destructor functions if provided
universe@708 74 * and SHALL deallocate the list memory, if an allocator is provided.
universe@524 75 */
universe@524 76 void (*destructor)(struct cx_list_s *list);
universe@524 77
universe@524 78 /**
olaf@739 79 * Member function for inserting a single element.
universe@641 80 * Implementors SHOULD see to performant implementations for corner cases.
universe@641 81 */
universe@641 82 int (*insert_element)(
universe@641 83 struct cx_list_s *list,
universe@641 84 size_t index,
universe@641 85 void const *data
universe@641 86 );
universe@641 87
universe@641 88 /**
universe@638 89 * Member function for inserting multiple elements.
universe@640 90 * Implementors SHOULD see to performant implementations for corner cases.
universe@638 91 */
universe@638 92 size_t (*insert_array)(
universe@638 93 struct cx_list_s *list,
universe@638 94 size_t index,
universe@638 95 void const *data,
universe@638 96 size_t n
universe@638 97 );
universe@638 98
universe@638 99 /**
universe@500 100 * Member function for inserting an element relative to an iterator position.
universe@500 101 */
universe@500 102 int (*insert_iter)(
universe@630 103 struct cx_mut_iterator_s *iter,
universe@500 104 void const *elem,
universe@500 105 int prepend
universe@500 106 );
universe@500 107
universe@500 108 /**
universe@500 109 * Member function for removing an element.
universe@500 110 */
universe@500 111 int (*remove)(
universe@500 112 struct cx_list_s *list,
universe@500 113 size_t index
universe@500 114 );
universe@500 115
universe@500 116 /**
universe@664 117 * Member function for removing all elements.
universe@664 118 */
universe@664 119 void (*clear)(struct cx_list_s *list);
universe@664 120
universe@664 121 /**
universe@647 122 * Member function for swapping two elements.
universe@647 123 */
universe@647 124 int (*swap)(
universe@647 125 struct cx_list_s *list,
universe@647 126 size_t i,
universe@647 127 size_t j
universe@647 128 );
universe@647 129
universe@647 130 /**
universe@500 131 * Member function for element lookup.
universe@500 132 */
universe@500 133 void *(*at)(
universe@500 134 struct cx_list_s const *list,
universe@500 135 size_t index
universe@500 136 );
universe@500 137
universe@500 138 /**
universe@500 139 * Member function for finding an element.
universe@500 140 */
universe@699 141 ssize_t (*find)(
universe@500 142 struct cx_list_s const *list,
universe@500 143 void const *elem
universe@500 144 );
universe@500 145
universe@500 146 /**
olaf@741 147 * Member function for sorting the list in-place.
universe@500 148 */
universe@500 149 void (*sort)(struct cx_list_s *list);
universe@500 150
universe@500 151 /**
universe@500 152 * Member function for comparing this list to another list of the same type.
universe@500 153 */
universe@500 154 int (*compare)(
universe@500 155 struct cx_list_s const *list,
universe@500 156 struct cx_list_s const *other
universe@500 157 );
universe@500 158
universe@500 159 /**
universe@500 160 * Member function for reversing the order of the items.
universe@500 161 */
universe@500 162 void (*reverse)(struct cx_list_s *list);
universe@500 163
universe@500 164 /**
universe@640 165 * Member function for returning an iterator pointing to the specified index.
universe@500 166 */
universe@500 167 struct cx_iterator_s (*iterator)(
universe@630 168 struct cx_list_s const *list,
universe@655 169 size_t index,
universe@655 170 bool backward
universe@630 171 );
universe@500 172 };
universe@500 173
universe@500 174 /**
universe@464 175 * Common type for all list implementations.
universe@464 176 */
universe@500 177 typedef struct cx_list_s CxList;
universe@398 178
universe@464 179 /**
universe@641 180 * Advises the list to store copies of the objects (default mode of operation).
universe@641 181 *
universe@641 182 * Retrieving objects from this list will yield pointers to the copies stored
universe@641 183 * within this list.
universe@641 184 *
universe@641 185 * @param list the list
universe@641 186 * @see cxListStorePointers()
universe@641 187 */
universe@641 188 __attribute__((__nonnull__))
universe@641 189 void cxListStoreObjects(CxList *list);
universe@641 190
universe@641 191 /**
universe@641 192 * Advises the list to only store pointers to the objects.
universe@641 193 *
universe@641 194 * Retrieving objects from this list will yield the original pointers stored.
universe@641 195 *
universe@641 196 * @note This function forcibly sets the element size to the size of a pointer.
universe@641 197 * Invoking this function on a non-empty list that already stores copies of
universe@641 198 * objects is undefined.
universe@641 199 *
universe@641 200 * @param list the list
universe@641 201 * @see cxListStoreObjects()
universe@641 202 */
universe@641 203 __attribute__((__nonnull__))
universe@641 204 void cxListStorePointers(CxList *list);
universe@641 205
universe@641 206 /**
universe@641 207 * Returns true, if this list is storing pointers instead of the actual data.
universe@641 208 *
universe@641 209 * @param list
universe@677 210 * @return true, if this list is storing pointers
universe@641 211 * @see cxListStorePointers()
universe@641 212 */
universe@641 213 __attribute__((__nonnull__))
universe@677 214 static inline bool cxListIsStoringPointers(CxList const *list) {
universe@677 215 return list->store_pointer;
universe@677 216 }
universe@677 217
universe@677 218 /**
universe@677 219 * Returns the number of elements currently stored in the list.
universe@677 220 *
universe@677 221 * @param list the list
universe@677 222 * @return the number of currently stored elements
universe@677 223 */
universe@677 224 __attribute__((__nonnull__))
universe@677 225 static inline size_t cxListSize(CxList const *list) {
universe@677 226 return list->size;
universe@677 227 }
universe@641 228
universe@641 229 /**
universe@464 230 * Adds an item to the end of the list.
universe@464 231 *
universe@464 232 * @param list the list
universe@464 233 * @param elem a pointer to the element to add
universe@464 234 * @return zero on success, non-zero on memory allocation failure
universe@629 235 * @see cxListAddArray()
universe@464 236 */
universe@508 237 __attribute__((__nonnull__))
universe@489 238 static inline int cxListAdd(
universe@500 239 CxList *list,
universe@489 240 void const *elem
universe@489 241 ) {
universe@641 242 return list->cl->insert_element(list, list->size, elem);
universe@469 243 }
universe@398 244
universe@464 245 /**
universe@629 246 * Adds multiple items to the end of the list.
universe@629 247 *
universe@629 248 * This method is more efficient than invoking cxListAdd() multiple times.
universe@629 249 *
universe@629 250 * If there is not enough memory to add all elements, the returned value is
universe@629 251 * less than \p n.
universe@629 252 *
universe@641 253 * If this list is storing pointers instead of objects \p array is expected to
universe@641 254 * be an array of pointers.
universe@641 255 *
universe@629 256 * @param list the list
universe@629 257 * @param array a pointer to the elements to add
universe@629 258 * @param n the number of elements to add
universe@629 259 * @return the number of added elements
universe@629 260 */
universe@629 261 __attribute__((__nonnull__))
universe@629 262 static inline size_t cxListAddArray(
universe@629 263 CxList *list,
universe@629 264 void const *array,
universe@629 265 size_t n
universe@629 266 ) {
universe@640 267 return list->cl->insert_array(list, list->size, array, n);
universe@629 268 }
universe@629 269
universe@629 270 /**
universe@464 271 * Inserts an item at the specified index.
universe@464 272 *
universe@464 273 * If \p index equals the list \c size, this is effectively cxListAdd().
universe@464 274 *
universe@464 275 * @param list the list
universe@464 276 * @param index the index the element shall have
universe@464 277 * @param elem a pointer to the element to add
universe@464 278 * @return zero on success, non-zero on memory allocation failure
universe@464 279 * or when the index is out of bounds
universe@499 280 * @see cxListInsertAfter()
universe@499 281 * @see cxListInsertBefore()
universe@464 282 */
universe@508 283 __attribute__((__nonnull__))
universe@489 284 static inline int cxListInsert(
universe@500 285 CxList *list,
universe@489 286 size_t index,
universe@489 287 void const *elem
universe@489 288 ) {
universe@641 289 return list->cl->insert_element(list, index, elem);
universe@469 290 }
universe@398 291
universe@464 292 /**
universe@638 293 * Inserts multiple items to the list at the specified index.
universe@638 294 * If \p index equals the list size, this is effectively cxListAddArray().
universe@638 295 *
universe@638 296 * This method is usually more efficient than invoking cxListInsert()
universe@638 297 * multiple times.
universe@638 298 *
universe@638 299 * If there is not enough memory to add all elements, the returned value is
universe@638 300 * less than \p n.
universe@638 301 *
universe@641 302 * If this list is storing pointers instead of objects \p array is expected to
universe@641 303 * be an array of pointers.
universe@641 304 *
universe@638 305 * @param list the list
universe@638 306 * @param index the index where to add the elements
universe@638 307 * @param array a pointer to the elements to add
universe@638 308 * @param n the number of elements to add
universe@638 309 * @return the number of added elements
universe@638 310 */
universe@638 311 __attribute__((__nonnull__))
universe@638 312 static inline size_t cxListInsertArray(
universe@638 313 CxList *list,
universe@638 314 size_t index,
universe@638 315 void const *array,
universe@638 316 size_t n
universe@638 317 ) {
universe@638 318 return list->cl->insert_array(list, index, array, n);
universe@638 319 }
universe@638 320
universe@638 321 /**
universe@499 322 * Inserts an element after the current location of the specified iterator.
universe@499 323 *
universe@499 324 * The used iterator remains operational, but all other active iterators should
universe@499 325 * be considered invalidated.
universe@499 326 *
universe@499 327 * If \p iter is not a list iterator, the behavior is undefined.
universe@499 328 * If \p iter is a past-the-end iterator, the new element gets appended to the list.
universe@499 329 *
universe@499 330 * @param iter an iterator
universe@499 331 * @param elem the element to insert
universe@499 332 * @return zero on success, non-zero on memory allocation failure
universe@499 333 * @see cxListInsert()
universe@499 334 * @see cxListInsertBefore()
universe@499 335 */
universe@508 336 __attribute__((__nonnull__))
universe@499 337 static inline int cxListInsertAfter(
universe@630 338 CxMutIterator *iter,
universe@499 339 void const *elem
universe@499 340 ) {
universe@500 341 return ((struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 0);
universe@499 342 }
universe@499 343
universe@499 344 /**
universe@499 345 * Inserts an element before the current location of the specified iterator.
universe@499 346 *
universe@499 347 * The used iterator remains operational, but all other active iterators should
universe@499 348 * be considered invalidated.
universe@499 349 *
universe@499 350 * If \p iter is not a list iterator, the behavior is undefined.
universe@499 351 * If \p iter is a past-the-end iterator, the new element gets appended to the list.
universe@499 352 *
universe@499 353 * @param iter an iterator
universe@499 354 * @param elem the element to insert
universe@499 355 * @return zero on success, non-zero on memory allocation failure
universe@499 356 * @see cxListInsert()
universe@499 357 * @see cxListInsertAfter()
universe@499 358 */
universe@508 359 __attribute__((__nonnull__))
universe@499 360 static inline int cxListInsertBefore(
universe@630 361 CxMutIterator *iter,
universe@499 362 void const *elem
universe@499 363 ) {
universe@500 364 return ((struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 1);
universe@499 365 }
universe@499 366
universe@499 367 /**
universe@464 368 * Removes the element at the specified index.
universe@664 369 *
universe@664 370 * If an element destructor function is specified, it is called before
universe@664 371 * removing the element.
universe@664 372 *
universe@464 373 * @param list the list
universe@464 374 * @param index the index of the element
universe@464 375 * @return zero on success, non-zero if the index is out of bounds
universe@464 376 */
universe@508 377 __attribute__((__nonnull__))
universe@489 378 static inline int cxListRemove(
universe@500 379 CxList *list,
universe@489 380 size_t index
universe@489 381 ) {
universe@469 382 return list->cl->remove(list, index);
universe@469 383 }
universe@398 384
universe@464 385 /**
universe@664 386 * Removes all elements from this list.
universe@664 387 *
universe@664 388 * If an element destructor function is specified, it is called for each
universe@664 389 * element before removing them.
universe@664 390 *
universe@664 391 * @param list the list
universe@664 392 */
universe@664 393 __attribute__((__nonnull__))
universe@664 394 static inline void cxListClear(CxList *list) {
universe@664 395 list->cl->clear(list);
universe@664 396 }
universe@664 397
universe@664 398 /**
universe@647 399 * Swaps two items in the list.
universe@647 400 *
universe@647 401 * Implementations should only allocate temporary memory for the swap, if
universe@647 402 * it is necessary.
universe@647 403 *
universe@647 404 * @param list the list
universe@647 405 * @param i the index of the first element
universe@647 406 * @param j the index of the second element
universe@647 407 * @return zero on success, non-zero if one of the indices is out of bounds
universe@647 408 */
universe@647 409 __attribute__((__nonnull__))
universe@647 410 static inline int cxListSwap(
universe@647 411 CxList *list,
universe@647 412 size_t i,
universe@647 413 size_t j
universe@647 414 ) {
universe@647 415 return list->cl->swap(list, i, j);
universe@647 416 }
universe@647 417
universe@647 418 /**
universe@464 419 * Returns a pointer to the element at the specified index.
universe@464 420 *
universe@464 421 * @param list the list
universe@464 422 * @param index the index of the element
universe@464 423 * @return a pointer to the element or \c NULL if the index is out of bounds
universe@464 424 */
universe@508 425 __attribute__((__nonnull__))
universe@489 426 static inline void *cxListAt(
universe@500 427 CxList *list,
universe@489 428 size_t index
universe@489 429 ) {
universe@469 430 return list->cl->at(list, index);
universe@469 431 }
universe@439 432
universe@464 433 /**
universe@494 434 * Returns an iterator pointing to the item at the specified index.
universe@494 435 *
universe@494 436 * The returned iterator is position-aware.
universe@494 437 *
universe@494 438 * If the index is out of range, a past-the-end iterator will be returned.
universe@494 439 *
universe@494 440 * @param list the list
universe@494 441 * @param index the index where the iterator shall point at
universe@494 442 * @return a new iterator
universe@494 443 */
universe@508 444 __attribute__((__nonnull__, __warn_unused_result__))
universe@655 445 static inline CxIterator cxListIteratorAt(
universe@630 446 CxList const *list,
universe@630 447 size_t index
universe@630 448 ) {
universe@655 449 return list->cl->iterator(list, index, false);
universe@655 450 }
universe@655 451
universe@655 452 /**
universe@655 453 * Returns a backwards iterator pointing to the item at the specified index.
universe@655 454 *
universe@655 455 * The returned iterator is position-aware.
universe@655 456 *
universe@655 457 * If the index is out of range, a past-the-end iterator will be returned.
universe@655 458 *
universe@655 459 * @param list the list
universe@655 460 * @param index the index where the iterator shall point at
universe@655 461 * @return a new iterator
universe@655 462 */
universe@655 463 __attribute__((__nonnull__, __warn_unused_result__))
universe@655 464 static inline CxIterator cxListBackwardsIteratorAt(
universe@655 465 CxList const *list,
universe@655 466 size_t index
universe@655 467 ) {
universe@655 468 return list->cl->iterator(list, index, true);
universe@630 469 }
universe@630 470
universe@630 471 /**
universe@630 472 * Returns a mutating iterator pointing to the item at the specified index.
universe@630 473 *
universe@630 474 * The returned iterator is position-aware.
universe@630 475 *
universe@630 476 * If the index is out of range, a past-the-end iterator will be returned.
universe@630 477 *
universe@630 478 * @param list the list
universe@630 479 * @param index the index where the iterator shall point at
universe@630 480 * @return a new iterator
universe@630 481 */
universe@630 482 __attribute__((__nonnull__, __warn_unused_result__))
universe@655 483 CxMutIterator cxListMutIteratorAt(
universe@655 484 CxList *list,
universe@655 485 size_t index
universe@655 486 );
universe@655 487
universe@655 488 /**
universe@655 489 * Returns a mutating backwards iterator pointing to the item at the
universe@655 490 * specified index.
universe@655 491 *
universe@655 492 * The returned iterator is position-aware.
universe@655 493 *
universe@655 494 * If the index is out of range, a past-the-end iterator will be returned.
universe@655 495 *
universe@655 496 * @param list the list
universe@655 497 * @param index the index where the iterator shall point at
universe@655 498 * @return a new iterator
universe@655 499 */
universe@655 500 __attribute__((__nonnull__, __warn_unused_result__))
universe@655 501 CxMutIterator cxListMutBackwardsIteratorAt(
universe@500 502 CxList *list,
universe@494 503 size_t index
universe@640 504 );
universe@494 505
universe@494 506 /**
universe@494 507 * Returns an iterator pointing to the first item of the list.
universe@494 508 *
universe@494 509 * The returned iterator is position-aware.
universe@494 510 *
universe@494 511 * If the list is empty, a past-the-end iterator will be returned.
universe@494 512 *
universe@494 513 * @param list the list
universe@494 514 * @return a new iterator
universe@494 515 */
universe@508 516 __attribute__((__nonnull__, __warn_unused_result__))
universe@655 517 static inline CxIterator cxListIterator(CxList const *list) {
universe@655 518 return list->cl->iterator(list, 0, false);
universe@494 519 }
universe@494 520
universe@494 521 /**
universe@630 522 * Returns a mutating iterator pointing to the first item of the list.
universe@630 523 *
universe@630 524 * The returned iterator is position-aware.
universe@630 525 *
universe@630 526 * If the list is empty, a past-the-end iterator will be returned.
universe@630 527 *
universe@630 528 * @param list the list
universe@630 529 * @return a new iterator
universe@630 530 */
universe@630 531 __attribute__((__nonnull__, __warn_unused_result__))
universe@655 532 static inline CxMutIterator cxListMutIterator(CxList *list) {
universe@655 533 return cxListMutIteratorAt(list, 0);
universe@655 534 }
universe@655 535
universe@655 536
universe@655 537 /**
universe@655 538 * Returns a backwards iterator pointing to the last item of the list.
universe@655 539 *
universe@655 540 * The returned iterator is position-aware.
universe@655 541 *
universe@655 542 * If the list is empty, a past-the-end iterator will be returned.
universe@655 543 *
universe@655 544 * @param list the list
universe@655 545 * @return a new iterator
universe@655 546 */
universe@655 547 __attribute__((__nonnull__, __warn_unused_result__))
universe@655 548 static inline CxIterator cxListBackwardsIterator(CxList const *list) {
universe@655 549 return list->cl->iterator(list, list->size - 1, true);
universe@655 550 }
universe@655 551
universe@655 552 /**
universe@655 553 * Returns a mutating backwards iterator pointing to the last item of the list.
universe@655 554 *
universe@655 555 * The returned iterator is position-aware.
universe@655 556 *
universe@655 557 * If the list is empty, a past-the-end iterator will be returned.
universe@655 558 *
universe@655 559 * @param list the list
universe@655 560 * @return a new iterator
universe@655 561 */
universe@655 562 __attribute__((__nonnull__, __warn_unused_result__))
universe@655 563 static inline CxMutIterator cxListMutBackwardsIterator(CxList *list) {
universe@655 564 return cxListMutBackwardsIteratorAt(list, list->size - 1);
universe@630 565 }
universe@630 566
universe@630 567 /**
universe@464 568 * Returns the index of the first element that equals \p elem.
universe@464 569 *
universe@464 570 * Determining equality is performed by the list's comparator function.
universe@464 571 *
universe@464 572 * @param list the list
universe@464 573 * @param elem the element to find
universe@699 574 * @return the index of the element or a negative
universe@699 575 * value when the element is not found
universe@464 576 */
universe@508 577 __attribute__((__nonnull__))
universe@699 578 static inline ssize_t cxListFind(
universe@621 579 CxList const *list,
universe@489 580 void const *elem
universe@489 581 ) {
universe@469 582 return list->cl->find(list, elem);
universe@469 583 }
universe@398 584
universe@464 585 /**
olaf@741 586 * Sorts the list in-place.
universe@469 587 *
universe@469 588 * \remark The underlying sort algorithm is implementation defined.
universe@469 589 *
universe@469 590 * @param list the list
universe@469 591 */
universe@508 592 __attribute__((__nonnull__))
universe@500 593 static inline void cxListSort(CxList *list) {
universe@469 594 list->cl->sort(list);
universe@469 595 }
universe@404 596
universe@488 597 /**
universe@490 598 * Reverses the order of the items.
universe@490 599 *
universe@490 600 * @param list the list
universe@490 601 */
universe@508 602 __attribute__((__nonnull__))
universe@500 603 static inline void cxListReverse(CxList *list) {
universe@490 604 list->cl->reverse(list);
universe@490 605 }
universe@490 606
universe@490 607 /**
universe@488 608 * Compares a list to another list of the same type.
universe@488 609 *
universe@618 610 * First, the list sizes are compared.
universe@618 611 * If they match, the lists are compared element-wise.
universe@488 612 *
universe@488 613 * @param list the list
universe@488 614 * @param other the list to compare to
universe@618 615 * @return zero, if both lists are equal element wise,
universe@618 616 * negative if the first list is smaller, positive if the first list is larger
universe@488 617 */
universe@508 618 __attribute__((__nonnull__))
universe@618 619 int cxListCompare(
universe@618 620 CxList const *list,
universe@618 621 CxList const *other
universe@618 622 );
universe@488 623
universe@503 624 /**
universe@528 625 * Deallocates the memory of the specified list structure.
universe@528 626 *
universe@528 627 * Also calls content a destructor function, depending on the configuration
universe@528 628 * in CxList.content_destructor_type.
universe@503 629 *
universe@503 630 * This function itself is a destructor function for the CxList.
universe@503 631 *
universe@528 632 * @param list the list which shall be destroyed
universe@503 633 */
universe@503 634 __attribute__((__nonnull__))
universe@528 635 void cxListDestroy(CxList *list);
universe@503 636
universe@704 637 /**
universe@704 638 * A shared instance of an empty list.
universe@704 639 *
universe@704 640 * Writing to that list is undefined.
universe@704 641 */
universe@704 642 extern CxList * const cxEmptyList;
universe@704 643
universe@704 644
universe@415 645 #ifdef __cplusplus
universe@628 646 } // extern "C"
universe@415 647 #endif
universe@415 648
universe@628 649 #endif // UCX_LIST_H

mercurial