Easy to use single linked list data structure. Fifo and stack usage, as well as concatenation in O(1)
Usage example:
// allocates an integerint*alloc_int(inti)
{
int*tmp=malloc(sizeof(int));
if(!tmp)
abort();
*tmp=i;
returntmp;
}
// selector function for picking ints larger than 100 boolgt100(cpitem, void*_moot)
{
return*(int*)item>100;
}
voidusage_example(void)
{
// create a ringRingr=ring_create();
// append 4 itemsfor(inti=0; i<4; ++i)
ring_append(r, alloc_int(42*i));
// push 4 itemsfor(inti=0; i<4; ++i)
ring_push(r, alloc_int(67*i));
// insert at specific positionring_insert_at(r, alloc_int(300), 4);
// remove at specific positionint*a=ring_extract(r, 4);
printf("At pos 4: %d\n", *a);
free(a);
// ring iterator usagefor(ring_iterator(r))
{
int*c=ring_index;
printf("Contend: %d\n", *c);
}
// remove a subgroup of elements. here ints larger then 100Ringb=ring_remove_selected(r, gt100, NULL);
// concat them back togetherr=ring_concat(r, b);
// destroy the ring, releasing memory simple with stdlib free()ring_destroy(r, free);
}