ListFind
ListFind
Description
Find the first item equal to the searched value.
item_ptr must point to a value comparable with list elements. Use &LVAL(expr) when searching with a temporary expression.
Parameters
| Name | Direction | Description |
|---|---|---|
l |
in | List to search. |
item_ptr |
in | Pointer to searched value. |
compare |
in | Comparator returning 0 for equality. |
Success
Index of first matching item.
Failure
SIZE_MAX
Usage example (Cross-references)
Usage examples (Cross-references)
- In
List.Access.c:37:
static bool test_list_find_contains(void) {
WriteFmt("Testing ListFind and ListContains\n");
typedef List(int) IntList;- In
List.Access.c:44:
int needle = 20;
int missing = 99;
bool result = (ListFind(&list, &needle, compare_ints) == SIZE_MAX);
result = result && !ListContains(&list, &needle, compare_ints);- In
List.Access.c:52:
ListPushBackR(&list, 20);
result = result && (ListFind(&list, &needle, compare_ints) == 1);
result = result && ListContains(&list, &needle, compare_ints);
result = result && !ListContains(&list, &missing, compare_ints);- In
List.Access.c:55:
result = result && ListContains(&list, &needle, compare_ints);
result = result && !ListContains(&list, &missing, compare_ints);
result = result && (ListFind(&list, &missing, compare_ints) == SIZE_MAX);
ListDeinit(&list);- In
Access.h:104:
/// TAGS: List, Contains, Search, Compare
///
#define ListContains(l, item_ptr, compare) (ListFind((l), (item_ptr), (compare)) != SIZE_MAX)
///
Last updated on