src/cx/list.h

changeset 764
ccbdbd088455
parent 759
475335643af4
equal deleted inserted replaced
763:741a2040fa33 764:ccbdbd088455
134 struct cx_list_s const *list, 134 struct cx_list_s const *list,
135 size_t index 135 size_t index
136 ); 136 );
137 137
138 /** 138 /**
139 * Member function for finding an element. 139 * Member function for finding and optionally removing an element.
140 */ 140 */
141 ssize_t (*find)( 141 ssize_t (*find_remove)(
142 struct cx_list_s const *list, 142 struct cx_list_s *list,
143 void const *elem 143 void const *elem,
144 bool remove
144 ); 145 );
145 146
146 /** 147 /**
147 * Member function for sorting the list in-place. 148 * Member function for sorting the list in-place.
148 */ 149 */
577 __attribute__((__nonnull__)) 578 __attribute__((__nonnull__))
578 static inline ssize_t cxListFind( 579 static inline ssize_t cxListFind(
579 CxList const *list, 580 CxList const *list,
580 void const *elem 581 void const *elem
581 ) { 582 ) {
582 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);
583 } 602 }
584 603
585 /** 604 /**
586 * Sorts the list in-place. 605 * Sorts the list in-place.
587 * 606 *

mercurial