817 * |
817 * |
818 * Determining equality is performed by the list's comparator function. |
818 * Determining equality is performed by the list's comparator function. |
819 * |
819 * |
820 * @param list the list |
820 * @param list the list |
821 * @param elem the element to find |
821 * @param elem the element to find |
822 * @return the index of the element or a negative |
822 * @return the index of the element or the size of the list when the element is not found |
823 * value when the element is not found |
823 * @see cxListIndexValid() |
824 */ |
824 */ |
825 cx_attr_nonnull |
825 cx_attr_nonnull |
826 cx_attr_nodiscard |
826 cx_attr_nodiscard |
827 static inline ssize_t cxListFind( |
827 static inline size_t cxListFind( |
828 const CxList *list, |
828 const CxList *list, |
829 const void *elem |
829 const void *elem |
830 ) { |
830 ) { |
831 return list->cl->find_remove((CxList*)list, elem, false); |
831 return list->cl->find_remove((CxList*)list, elem, false); |
832 } |
832 } |
833 |
833 |
834 /** |
834 /** |
|
835 * Checks if the specified index is within bounds. |
|
836 * |
|
837 * @param list the list |
|
838 * @param index the index |
|
839 * @retval true if the index is within bounds |
|
840 * @retval false if the index is out of bounds |
|
841 */ |
|
842 cx_attr_nonnull |
|
843 cx_attr_nodiscard |
|
844 static inline bool cxListIndexValid(const CxList *list, size_t index) { |
|
845 return index < list->collection.size; |
|
846 } |
|
847 |
|
848 /** |
835 * Removes and returns the index of the first element that equals @p elem. |
849 * Removes and returns the index of the first element that equals @p elem. |
836 * |
850 * |
837 * Determining equality is performed by the list's comparator function. |
851 * Determining equality is performed by the list's comparator function. |
838 * |
852 * |
839 * @param list the list |
853 * @param list the list |
840 * @param elem the element to find and remove |
854 * @param elem the element to find and remove |
841 * @return the index of the now removed element or a negative |
855 * @return the index of the now removed element or the list size |
842 * value when the element is not found or could not be removed |
856 * when the element is not found or could not be removed |
843 */ |
857 * @see cxListIndexValid() |
844 cx_attr_nonnull |
858 */ |
845 static inline ssize_t cxListFindRemove( |
859 cx_attr_nonnull |
|
860 static inline size_t cxListFindRemove( |
846 CxList *list, |
861 CxList *list, |
847 const void *elem |
862 const void *elem |
848 ) { |
863 ) { |
849 return list->cl->find_remove(list, elem, true); |
864 return list->cl->find_remove(list, elem, true); |
850 } |
865 } |