support limit

This commit is contained in:
Rongsong Shen 2026-01-12 15:20:51 +08:00
parent bef32ace38
commit ecf1916d78
33 changed files with 3036 additions and 243 deletions

View file

@ -46,6 +46,7 @@ static int xlist_ensure(xlist_t* l)
int xlist_store(xlist_t* l, void* data)
{
int rc;
int idx;
if (l == NULL) {
return -EINVAL;
@ -56,10 +57,26 @@ int xlist_store(xlist_t* l, void* data)
return rc;
}
l->data[l->count] = data;
idx = l->count;
l->data[idx] = data;
l->count++;
return 1;
return idx;
}
void* xlist_get(xlist_t* l, int idx)
{
if ((l == NULL) || (idx < 0)) {
errno = EINVAL;
return NULL;
}
if (idx >= l->caps) {
errno = 0;
return NULL;
}
return (void*)l->data[idx];
}
void xlist_clear(xlist_t* l)
@ -86,6 +103,31 @@ int xlist_iter(xlist_t* l, xlist_iter_fn_t fn, void* data)
return 0;
}
int xlist_del(xlist_t* l, void* data)
{
int i, j;
if (l == NULL) {
return -EINVAL;
}
j = -1;
i = 0;
while (i < l->count) {
if (l->data[i] == data) {
for (j = i + 1; j < l->count; j++) {
l->data[j - 1] = l->data[j];
}
l->count--;
} else {
i++;
}
}
return 1;
}
void* xlist_find(xlist_t* l, xlist_find_fn_t fn, ...)
{
int i;