ListLen
Description
Number of items in list.
Parameters
| Name | Direction | Description |
|---|---|---|
l |
in | List to query. |
Success
Length of list.
Failure
Function cannot fail.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
ListInt.c:49:
case LIST_INT_POP_BACK : {
if (ListLen(list) > 0) {
i32 popped;
ListPopBack(list, &popped);- In
ListInt.c:57:
case LIST_INT_POP_FRONT : {
if (ListLen(list) > 0) {
i32 popped;
ListPopFront(list, &popped);- In
ListInt.c:68:
i32 value = (i32)extract_u32(data, offset, data_size);
if (idx <= ListLen(list)) {
ListInsertR(list, value, idx);
}- In
ListInt.c:76:
case LIST_INT_REMOVE : {
uint16_t idx = extract_u16(data, offset, data_size);
if (idx < ListLen(list)) {
i32 removed;
ListRemove(list, &removed, idx);- In
ListInt.c:85:
case LIST_INT_DELETE : {
uint16_t idx = extract_u16(data, offset, data_size);
if (idx < ListLen(list)) {
ListDelete(list, idx);
}- In
ListInt.c:93:
case LIST_INT_AT : {
uint16_t idx = extract_u16(data, offset, data_size);
if (idx < ListLen(list)) {
volatile i32 value = ListAt(list, idx);
(void)value; // Prevent optimization
- In
ListInt.c:101:
case LIST_INT_LEN : {
volatile uint64_t len = ListLen(list);
(void)len;
break;- In
ListInt.c:107:
case LIST_INT_FIRST : {
if (ListLen(list) > 0) {
volatile i32 first = ListFirst(list);
(void)first;- In
ListInt.c:115:
case LIST_INT_LAST : {
if (ListLen(list) > 0) {
volatile i32 last = ListLast(list);
(void)last;- In
ListInt.c:138:
uint16_t idx2 = extract_u16(data, offset, data_size);
if (ListLen(list) > 1 && idx1 < ListLen(list) && idx2 < ListLen(list)) {
ListSwapItems(list, idx1, idx2);
}- In
ListInt.c:150:
count = count % 16;
if (ListLen(list) > 0 && start < ListLen(list) && count > 0 && start + count <= ListLen(list)) {
i32 removed_items[16];
ListRemoveRange(list, removed_items, start, count);- In
ListInt.c:162:
count = count % 16;
if (ListLen(list) > 0 && start < ListLen(list) && count > 0 && start + count <= ListLen(list)) {
ListDeleteRange(list, start, count);
}- In
ListInt.c:191:
case LIST_INT_PTR_AT : {
uint16_t idx = extract_u16(data, offset, data_size);
if (idx < ListLen(list)) {
volatile i32 *ptr = ListPtrAt(list, idx);
if (ptr) {- In
ListInt.c:218:
// Foreach operations
case LIST_INT_FOREACH : {
if (ListLen(list) > 0) {
int sum = 0;
ListForeach(list, item) {- In
ListInt.c:229:
case LIST_INT_FOREACH_IDX : {
if (ListLen(list) > 0) {
int sum = 0;
ListForeachIdx(list, item, idx) {- In
ListInt.c:240:
case LIST_INT_FOREACH_PTR : {
if (ListLen(list) > 0) {
int sum = 0;
ListForeachPtr(list, item_ptr) {- In
ListInt.c:251:
case LIST_INT_FOREACH_PTR_IDX : {
if (ListLen(list) > 0) {
int sum = 0;
ListForeachPtrIdx(list, item_ptr, idx) {- In
ListInt.c:262:
case LIST_INT_FOREACH_REVERSE : {
if (ListLen(list) > 0) {
int sum = 0;
ListForeachReverse(list, item) {- In
ListInt.c:273:
case LIST_INT_FOREACH_REVERSE_IDX : {
if (ListLen(list) > 0) {
int sum = 0;
ListForeachReverseIdx(list, item, idx) {- In
ListInt.c:284:
case LIST_INT_FOREACH_PTR_REVERSE : {
if (ListLen(list) > 0) {
int sum = 0;
ListForeachPtrReverse(list, item_ptr) {- In
ListInt.c:295:
case LIST_INT_FOREACH_PTR_REVERSE_IDX : {
if (ListLen(list) > 0) {
int sum = 0;
ListForeachPtrReverseIdx(list, item_ptr, idx) {- In
ListInt.c:306:
case LIST_INT_FOREACH_IN_RANGE : {
if (ListLen(list) > 0 && *offset + 8 <= data_size) {
size_t start = extract_u32(data, offset, data_size) % ListLen(list);
size_t end = extract_u32(data, offset, data_size) % (ListLen(list) + 1);- In
ListInt.c:307:
case LIST_INT_FOREACH_IN_RANGE : {
if (ListLen(list) > 0 && *offset + 8 <= data_size) {
size_t start = extract_u32(data, offset, data_size) % ListLen(list);
size_t end = extract_u32(data, offset, data_size) % (ListLen(list) + 1);
if (start < end) {- In
ListInt.c:308:
if (ListLen(list) > 0 && *offset + 8 <= data_size) {
size_t start = extract_u32(data, offset, data_size) % ListLen(list);
size_t end = extract_u32(data, offset, data_size) % (ListLen(list) + 1);
if (start < end) {
int sum = 0;- In
ListInt.c:321:
case LIST_INT_FOREACH_PTR_IN_RANGE : {
if (ListLen(list) > 0 && *offset + 8 <= data_size) {
size_t start = extract_u32(data, offset, data_size) % ListLen(list);
size_t end = extract_u32(data, offset, data_size) % (ListLen(list) + 1);- In
ListInt.c:322:
case LIST_INT_FOREACH_PTR_IN_RANGE : {
if (ListLen(list) > 0 && *offset + 8 <= data_size) {
size_t start = extract_u32(data, offset, data_size) % ListLen(list);
size_t end = extract_u32(data, offset, data_size) % (ListLen(list) + 1);
if (start < end) {- In
ListInt.c:323:
if (ListLen(list) > 0 && *offset + 8 <= data_size) {
size_t start = extract_u32(data, offset, data_size) % ListLen(list);
size_t end = extract_u32(data, offset, data_size) % (ListLen(list) + 1);
if (start < end) {
int sum = 0;- In
ListInt.c:336:
case LIST_INT_FOREACH_REVERSE_IN_RANGE : {
if (ListLen(list) > 0 && *offset + 8 <= data_size) {
size_t start = extract_u32(data, offset, data_size) % ListLen(list);
size_t end = extract_u32(data, offset, data_size) % (ListLen(list) + 1);- In
ListInt.c:337:
case LIST_INT_FOREACH_REVERSE_IN_RANGE : {
if (ListLen(list) > 0 && *offset + 8 <= data_size) {
size_t start = extract_u32(data, offset, data_size) % ListLen(list);
size_t end = extract_u32(data, offset, data_size) % (ListLen(list) + 1);
if (start < end) {- In
ListInt.c:338:
if (ListLen(list) > 0 && *offset + 8 <= data_size) {
size_t start = extract_u32(data, offset, data_size) % ListLen(list);
size_t end = extract_u32(data, offset, data_size) % (ListLen(list) + 1);
if (start < end) {
int sum = 0;- In
ListInt.c:351:
case LIST_INT_FOREACH_PTR_REVERSE_IN_RANGE : {
if (ListLen(list) > 0 && *offset + 8 <= data_size) {
size_t start = extract_u32(data, offset, data_size) % ListLen(list);
size_t end = extract_u32(data, offset, data_size) % (ListLen(list) + 1);- In
ListInt.c:352:
case LIST_INT_FOREACH_PTR_REVERSE_IN_RANGE : {
if (ListLen(list) > 0 && *offset + 8 <= data_size) {
size_t start = extract_u32(data, offset, data_size) % ListLen(list);
size_t end = extract_u32(data, offset, data_size) % (ListLen(list) + 1);
if (start < end) {- In
ListInt.c:353:
if (ListLen(list) > 0 && *offset + 8 <= data_size) {
size_t start = extract_u32(data, offset, data_size) % ListLen(list);
size_t end = extract_u32(data, offset, data_size) % (ListLen(list) + 1);
if (start < end) {
int sum = 0;- In
List.Init.c:44:
ValidateList(&list_d);
bool result = (ListCopyInit(&list_a) == NULL) && (ListCopyDeinit(&list_a) == NULL) && (ListLen(&list_a) == 0);
result = result && (ListCopyInit(&list_b) == NULL) && (ListCopyDeinit(&list_b) == NULL) && (ListLen(&list_b) == 0);
result = result && (ListCopyInit(&list_c) == tracked_copy_init) && (ListCopyDeinit(&list_c) == tracked_copy_deinit);- In
List.Init.c:45:
bool result = (ListCopyInit(&list_a) == NULL) && (ListCopyDeinit(&list_a) == NULL) && (ListLen(&list_a) == 0);
result = result && (ListCopyInit(&list_b) == NULL) && (ListCopyDeinit(&list_b) == NULL) && (ListLen(&list_b) == 0);
result = result && (ListCopyInit(&list_c) == tracked_copy_init) && (ListCopyDeinit(&list_c) == tracked_copy_deinit);
result = result && (ListCopyInit(&list_d) == tracked_copy_init) && (ListCopyDeinit(&list_d) == tracked_copy_deinit);- In
List.Init.c:108:
result = result && (g_copy_deinit_count == 2);
result = result && (ListHead(&list) == NULL) && (ListTail(&list) == NULL) && (ListLen(&list) == 0);
// Verifying ListDeinit clears the hook fields.
result = result && (ListCopyInit(&list) == NULL) && (ListCopyDeinit(&list) == NULL);- In
List.Insert.c:30:
static bool list_matches(GenericList *list, const int *expected, size count) {
if (ListLen(list) != count) {
return false;
} bool result = (g_copy_init_count == 2);
result = result && list_matches(GENERIC_LIST(&dest), (const int[]) {1003, 1004}, 2);
result = result && (ListLen(&src) == 0) && (ListHead(&src) == NULL) && (ListTail(&src) == NULL);
result = result && (ListCopyInit(&src) == tracked_copy_init) && (ListCopyDeinit(&src) == tracked_copy_deinit);
bool result = list_matches(GENERIC_LIST(&dest_l), (const int[]) {1, 2, 3, 4}, 4);
result = result && (ListLen(&src_l) == 0) && (ListHead(&src_l) == NULL) && (ListTail(&src_l) == NULL);
result = result && list_matches(GENERIC_LIST(&dest_r), (const int[]) {1, 2, 3, 4}, 4);
result = result && list_matches(GENERIC_LIST(&src_r), (const int[]) {3, 4}, 2); result = result && list_matches(GENERIC_LIST(&src_r), (const int[]) {3, 4}, 2);
result = result && list_matches(GENERIC_LIST(&dest_a), (const int[]) {5, 6}, 2);
result = result && (ListLen(&src_a) == 0) && (ListHead(&src_a) == NULL) && (ListTail(&src_a) == NULL);
ListDeinit(&dest_l); result = result && list_matches(GENERIC_LIST(&deep_dest), (const int[]) {1011, 1012}, 2);
result = result && list_matches(GENERIC_LIST(&shallow_src), (const int[]) {11, 12}, 2);
result = result && (ListLen(&empty_dest) == 0) && (ListLen(&empty_src) == 0);
ListDeinit(&deep_dest);- In
List.Foreach.c:8:
static bool list_matches(GenericList *list, const int *expected, size count) {
if (ListLen(list) != count) {
return false;
}- In
List.Ops.c:35:
static bool list_matches(GenericList *list, const int *expected, size count) {
if (ListLen(list) != count) {
return false;
}- In
List.Ops.c:63:
ListClear(&list);
bool result = (ListLen(&list) == 0) && (ListHead(&list) == NULL) && (ListTail(&list) == NULL);
ListPushBackR(&list, 9);- In
List.Ops.c:113:
ListReverse(&singleton);
bool result = (ListLen(&empty) == 0) && (ListHead(&empty) == NULL) && (ListTail(&empty) == NULL);
result = result && list_matches(GENERIC_LIST(&singleton), (const int[]) {42}, 1);- In
List.Ops.c:138:
ListClear(&list);
result = result && (g_copy_deinit_count == 2);
result = result && (ListLen(&list) == 0) && (ListHead(&list) == NULL) && (ListTail(&list) == NULL);
ListPushBackR(&list, 9);- In
List.Access.c:15:
static bool list_matches(GenericList *list, const int *expected, size count) {
if (ListLen(list) != count) {
return false;
}- In
List.Access.c:30:
static bool test_list_len_empty(void) {
WriteFmt("Testing ListLen and ListEmpty\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
List.Access.c:37:
IntList list = ListInit(&alloc);
bool result = (ListLen(&list) == 0);
result = result && ListEmpty(&list);- In
List.Access.c:43:
ListPushBackR(&list, 20);
result = result && (ListLen(&list) == 2);
result = result && !ListEmpty(&list);- In
List.Access.c:47:
ListClear(&list);
result = result && (ListLen(&list) == 0);
result = result && ListEmpty(&list);
result = result && (ListHead(&list) == NULL) && (ListTail(&list) == NULL);- In
List.Remove.c:30:
static bool list_matches(GenericList *list, const int *expected, size count) {
if (ListLen(list) != count) {
return false;
}
ListDeleteRange(&list, 0, 2);
result = result && (ListLen(&list) == 0) && (ListHead(&list) == NULL) && (ListTail(&list) == NULL);
ListDeinit(&list);
bool result = (removed[0] == 7) && (removed[1] == 8) && (removed[2] == 9);
result = result && (ListLen(&list) == 0) && (ListHead(&list) == NULL) && (ListTail(&list) == NULL);
ListDeinit(&list);
ListRemoveRange(&list, NULL, 1, 0);
ListRemoveRange(&list, NULL, ListLen(&list), 0);
ListRemoveRange(&list, NULL, 9999, 0);
bool result = (g_copy_init_count == 3); ListClear(&list);
result = result && (g_copy_deinit_count == 2);
result = result && (ListLen(&list) == 0) && (ListHead(&list) == NULL) && (ListTail(&list) == NULL);
ListDeinit(&list);- In
List.Type.c:21:
// directly to confirm ListInit planted the right value.
bool result = (ListHead(&list) == NULL) && (ListTail(&list) == NULL) && (ListCopyInit(&list) == NULL) &&
(ListCopyDeinit(&list) == NULL) && (ListLen(&list) == 0) && MAGIC_MATCHES(list.__magic, LIST_MAGIC);
ListDeinit(&list);- In
Access.h:95:
/// TAGS: List, Empty, Query
///
#define ListEmpty(l) (ListLen(l) == 0)
///
Last updated on