1 2 /* Author : Stephen Smalley, <sds (at) epoch.ncsc.mil> */ 3 4 /* FLASK */ 5 6 /* 7 * A double-ended queue is a singly linked list of 8 * elements of arbitrary type that may be accessed 9 * at either end. 10 */ 11 12 #ifndef _QUEUE_H_ 13 #define _QUEUE_H_ 14 15 typedef void *queue_element_t; 16 17 typedef struct queue_node *queue_node_ptr_t; 18 19 typedef struct queue_node { 20 queue_element_t element; 21 queue_node_ptr_t next; 22 } queue_node_t; 23 24 typedef struct queue_info { 25 queue_node_ptr_t head; 26 queue_node_ptr_t tail; 27 } queue_info_t; 28 29 typedef queue_info_t *queue_t; 30 31 queue_t queue_create(void); 32 int queue_insert(queue_t, queue_element_t); 33 int queue_push(queue_t, queue_element_t); 34 queue_element_t queue_remove(queue_t); 35 queue_element_t queue_head(queue_t); 36 void queue_destroy(queue_t); 37 38 /* 39 Applies the specified function f to each element in the 40 specified queue. 41 42 In addition to passing the element to f, queue_map 43 passes the specified void* pointer to f on each invocation. 44 45 If f returns a non-zero status, then queue_map will cease 46 iterating through the hash table and will propagate the error 47 return to its caller. 48 */ 49 int queue_map(queue_t, int (*f) (queue_element_t, void *), void *); 50 51 /* 52 Same as queue_map, except that if f returns a non-zero status, 53 then the element will be removed from the queue and the g 54 function will be applied to the element. 55 */ 56 void queue_map_remove_on_error(queue_t, 57 int (*f) (queue_element_t, void *), 58 void (*g) (queue_element_t, void *), void *); 59 60 #endif 61 62 /* FLASK */ 63