docs/Writerside/topics/list.h.md

changeset 1618
ef7cab6eb131
parent 1605
55b13f583356
equal deleted inserted replaced
1617:d4385f35f8b0 1618:ef7cab6eb131
472 ## Implement own List Structures 472 ## Implement own List Structures
473 473
474 If you want to create your own list implementation, this is extremely easy. 474 If you want to create your own list implementation, this is extremely easy.
475 475
476 You need to define a function for creating your list and assign a `cx_list_class` structure with the pointers to your implementation. 476 You need to define a function for creating your list and assign a `cx_list_class` structure with the pointers to your implementation.
477 Then you call the `cx_list_init()` helper function to initialize the collection sture. 477 Then you call the `cx_list_init()` helper function to initialize the collection structure.
478 This also automatically adds support for `CX_STORE_POINTERS` to your list. 478 This also automatically adds support for `CX_STORE_POINTERS` to your list.
479 479
480 ```C 480 ```C
481 // define the class with pointers to your functions 481 // define the class with pointers to your functions
482 static cx_list_class my_list_class = { 482 static cx_list_class my_list_class = {
542 | `compare` | This function pointer can be `NULL`, in which case an unoptimized fallback is used. You can implement an optimized compare function that compares the list of another list of the same class. | 542 | `compare` | This function pointer can be `NULL`, in which case an unoptimized fallback is used. You can implement an optimized compare function that compares the list of another list of the same class. |
543 | `reverse` | Reorder all elements in the list so that they appear in exactly the opposite order. | 543 | `reverse` | Reorder all elements in the list so that they appear in exactly the opposite order. |
544 | `change_capacity` | When your list supports overallocation, the capacity shall be changed to the specified value. Return non-zero on error and zero on success. When the list does not support overallocation, this function pointer can be `NULL`. | 544 | `change_capacity` | When your list supports overallocation, the capacity shall be changed to the specified value. Return non-zero on error and zero on success. When the list does not support overallocation, this function pointer can be `NULL`. |
545 | `iterator` | Create an iterator starting at the specified index. The Boolean argument indicates whether iteration is supposed to traverse backwards. | 545 | `iterator` | Create an iterator starting at the specified index. The Boolean argument indicates whether iteration is supposed to traverse backwards. |
546 546
547 > If you initialize your list with `cx_list_init()`, you do not have to worry about making a
548 > difference between storing pointers and storing elements, because your implementation will
549 > be automatically wrapped.
550 > This means you only have to handle the one single case described above.
551 547
552 ### Default Class Function Implementations 548 ### Default Class Function Implementations
553 549
554 If you are satisfied with some of the default implementations, you can use some pre-defined functions. 550 If you are satisfied with some of the default implementations, you can use some pre-defined functions.
555 Note, however, that those are not optimized for any specific list structure 551 Note, however, that those are not optimized for any specific list structure

mercurial