ordinary/src/idx.c

48 lines
836 B
C

#include <ordinary.h>
struct ordinary_node *ordinary_list_at(struct ordinary_list *list, uint32_t idx) {
struct ordinary_node *node = list->head;
for(; node; node = node->next) {
idx -= 1;
if(!idx) {
return node;
}
}
return NULL;
}
struct ordinary_node *ordinary_list_find(struct ordinary_list *list, callback cb) {
struct ordinary_node *node = list->head;
uint32_t idx = 0;
for(; node; node = node->next) {
if(cb(node, idx)) {
return node;
}
if(list->limit) {
idx += 1;
}
}
return NULL;
}
uint8_t ordinary_list_for(struct ordinary_list *list, callback cb) {
struct ordinary_node *node = list->head;
uint32_t idx = 0, res = 0;
for(; node; node = node->next) {
res |= cb(node, idx);
if(list->limit) {
idx += 1;
}
}
return res;
}