ucx/cx/list.h

branch
newapi
changeset 253
087cc9216f28
parent 187
24ce2c326d85
equal deleted inserted replaced
252:7d176764756d 253:087cc9216f28
28 /** 28 /**
29 * \file list.h 29 * \file list.h
30 * \brief Interface for list implementations. 30 * \brief Interface for list implementations.
31 * \author Mike Becker 31 * \author Mike Becker
32 * \author Olaf Wintermann 32 * \author Olaf Wintermann
33 * \version 3.0
34 * \copyright 2-Clause BSD License 33 * \copyright 2-Clause BSD License
35 */ 34 */
36 35
37 #ifndef UCX_LIST_H 36 #ifndef UCX_LIST_H
38 #define UCX_LIST_H 37 #define UCX_LIST_H
135 struct cx_list_s const *list, 134 struct cx_list_s const *list,
136 size_t index 135 size_t index
137 ); 136 );
138 137
139 /** 138 /**
140 * Member function for finding an element. 139 * Member function for finding and optionally removing an element.
141 */ 140 */
142 ssize_t (*find)( 141 ssize_t (*find_remove)(
143 struct cx_list_s const *list, 142 struct cx_list_s *list,
144 void const *elem 143 void const *elem,
144 bool remove
145 ); 145 );
146 146
147 /** 147 /**
148 * Member function for sorting the list in-place. 148 * Member function for sorting the list in-place.
149 */ 149 */
578 __attribute__((__nonnull__)) 578 __attribute__((__nonnull__))
579 static inline ssize_t cxListFind( 579 static inline ssize_t cxListFind(
580 CxList const *list, 580 CxList const *list,
581 void const *elem 581 void const *elem
582 ) { 582 ) {
583 return list->cl->find(list, elem); 583 return list->cl->find_remove((CxList*)list, elem, false);
584 }
585
586 /**
587 * Removes and returns the index of the first element that equals \p elem.
588 *
589 * Determining equality is performed by the list's comparator function.
590 *
591 * @param list the list
592 * @param elem the element to find and remove
593 * @return the index of the now removed element or a negative
594 * value when the element is not found or could not be removed
595 */
596 __attribute__((__nonnull__))
597 static inline ssize_t cxListFindRemove(
598 CxList *list,
599 void const *elem
600 ) {
601 return list->cl->find_remove(list, elem, true);
584 } 602 }
585 603
586 /** 604 /**
587 * Sorts the list in-place. 605 * Sorts the list in-place.
588 * 606 *

mercurial