Chris Thomasson said:
Types:
clc_slist, clc_slink
clc_dlist, clc_dlink
API:
void* clc_slink_init(clc_slink*, clc_slink*);
void* clc_slink_next(clc_slink const*);
void* clc_slist_init(clc_slist*, clc_slink*);
void* clc_slist_head(clc_slist const*);
void* clc_slist_push(clc_slist*, clc_slink*);
void* clc_slist_pop(clc_slist*);
void* clc_dlink_init(clc_dlink*, clc_dlink*, clc_dlink*);
void* clc_dlink_next(clc_dlink const*);
void* clc_dlink_prev(clc_dlist const*);
void* clc_dlist_init(clc_dlist*, clc_dlink*, clc_dlink*);
void* clc_dlist_head(clc_dlist const*);
void* clc_dlist_tail(clc_dlist const*);
void* clc_dlist_push_head(clc_dlist*, clc_dlink*);
void* clc_dlist_push_tail(clc_dlist*, clc_dlink*);
void* clc_dlist_pop_head(clc_dlist*, clc_dlink*);
void* clc_dlist_pop_tail(clc_dlist*, clc_dlink*);
void* clc_dlist_pop(clc_dlist*);
Firstly, why not make that
ll_pop()
ll_next();
etc.
No one wants to write out all those words. Remember that quite often these
calls will be used in expressions. A for loop with three four-word
identifiers will rapidly get unreadable.
Also, if you are using the linked list as a queue, why not take void *s? Why
are you returning void *s when the returns in the code are clc_slink *consts
?
Finally, do we need singly linked lists? You seem to be doubling the size of
the api for no added functionality.
The snag you've got is that people want a linked list with data in it.
They want to go
for(ptr = head(list); ptr != 0; ptr = next(list))
{
/* forget all about linked lists, use ptr */
}
they also want
ptr = head(list);
while(ptr)
{
/* maybe we need to add something */
if( someconditon)
insertafter(list, ptr, newdata);
/* or maybe delete */
if( anothercodition )
delete(list, ptr);
/* and we want to trot through the list doing this in each place */
ptr = next(list);
}
unfortunately even one of these is difficult to provide. Supporting both
cleanly is virtually impossible. However the closer you get to it, the more
usable the library will be.