source: trunk/module-datastruct-llist.h @ 5375

Last change on this file since 5375 was 5255, checked in by schlocke, 8 years ago

cccam: good/bad sid list fix

File size: 2.4 KB
Line 
1
2/* singularly linked-list */
3
4#ifndef DATASTRUCT_LLIST_H_
5#define DATASTRUCT_LLIST_H_
6
7#include <pthread.h>
8
9typedef struct llnode LL_NODE;
10struct llnode {
11    void *obj;
12    LL_NODE *nxt;
13    unsigned char flag;
14};
15
16typedef struct llist LLIST;
17struct llist {
18//    void *obj;
19    LL_NODE *initial;
20    LL_NODE *last;
21    int32_t count;
22    pthread_mutex_t lock;
23    int32_t flag;
24};
25
26typedef struct lliter LL_ITER;
27struct lliter {
28    LLIST *l;
29    LL_NODE *cur, *prv;
30};
31
32LLIST *ll_create();             // create llist, return ptr to llist
33void ll_destroy(LLIST *l);      // same as ll_clear_abstract() but frees up LLIST mem as well
34void ll_destroy_data(LLIST *l); // same as ll_clear_data() but frees up obj allocations as well
35void ll_clear(LLIST *l);        // frees up all llnodes nodes but not data held in obj ptrs
36void ll_clear_data(LLIST *l);   // same as ll_clear_data() but frees up obj allocations as well
37
38void ll_sort(LLIST *l, void *compare); // sorts the list, compare = int func(const T *a, const T *b)
39LL_NODE *ll_append(LLIST *l, void *obj);                // append obj to llist
40LL_NODE *ll_prepend(LLIST *l, void *obj);               // prepend obj to llist
41
42LL_ITER ll_iter_create(LLIST *l);              // return ptr to iterator obj
43void *ll_iter_next(LL_ITER *it);                // iterate to and return next llnode obj, returns NULL at end
44void *ll_iter_peek(LL_ITER *it, int32_t offset);    // return obj at offset from iterator but do not iterate
45void ll_iter_reset(LL_ITER *it);                // reset itrerator to first llnode
46void ll_iter_insert(LL_ITER *it, void *obj);    // insert obj at iterator node
47void *ll_iter_remove(LL_ITER *it);              // remove llnode at iterator, returns ptr to the llnode obj removed
48void ll_iter_remove_data(LL_ITER *it);          // remove llnode and free llnode obj
49void *ll_iter_move(LL_ITER *it, int32_t offset);    // moves the iterator position
50int32_t ll_iter_move_first(LL_ITER *it);            // moves an entry to top
51int32_t ll_count(LLIST *l);                 // return number of items in list
52void *ll_has_elements(LLIST *l);        // returns first obj if has one
53
54int32_t ll_contains(LLIST *l, void *obj);
55void *ll_contains_data(LLIST *l, void *obj, uint32_t size);
56int32_t ll_remove(LLIST *l, void *obj);
57void ll_remove_data(LLIST *l, void *obj);
58int32_t ll_remove_all(LLIST *l, LLIST *elements_to_remove); // removes all elements from l where elements are in elements_to_remove
59#endif
Note: See TracBrowser for help on using the repository browser.