]>
Dogcows Code - chaz/rasterize/blob - list.h
3 * CS5600 University of Utah
5 * mcgarvey@eng.utah.edu
15 * A linked-list with a stack-like interface.
16 * The value of each node can be any pointer.
24 typedef struct list list_t
;
28 * Add a value to the list. It will become the first item.
29 * This is a O(1) operation.
32 void list_push2(list_t
** l
, void* value
, void (*destructor
)(void*))
34 list_t
* n
= (list_t
*)mem_alloc(sizeof(list_t
));
42 * Add a value to the list with no destructor set.
45 void list_push(list_t
** l
, void* value
)
47 list_push2(l
, value
, NULL
);
52 * Create a new list with a single value.
55 list_t
* list_new2(void* value
, void (*destructor
)(void*))
58 list_push2(&l
, value
, destructor
);
63 * Create a new list with a single value without a destructor set.
66 list_t
* list_new(void* value
)
69 list_push2(&l
, value
, 0);
75 * Remove a value from the front of the list. If the node has dtor set, it
76 * will be used to destroy the value.
77 * This is a O(1) operation.
80 void list_pop(list_t
** l
)
82 list_t
* n
= (*l
)->link
;
85 (*l
)->dtor((*l
)->val
);
93 * Destroy the list, freeing up all of its memory.
94 * This is a O(n) operation.
97 void list_destroy(list_t
** l
)
106 * Reverse the order of the items in the list.
107 * This is a O(n) operation.
109 void list_reverse(list_t
** l
);
This page took 0.040593 seconds and 4 git commands to generate.