Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | /* $Id: dlist.c,v 1.1.2.2 2002/10/02 14:38:37 armin Exp $ */ #include "platform.h" #include "dlist.h" /* ** Initialize linked list */ void diva_q_init (diva_entity_queue_t* q) { memset (q, 0x00, sizeof(*q)); } /* ** Remove element from linked list */ void diva_q_remove (diva_entity_queue_t* q, diva_entity_link_t* what) { if(!what->prev) { if ((q->head = what->next)) { q->head->prev = 0; } else { q->tail = 0; } } else if (!what->next) { q->tail = what->prev; q->tail->next = 0; } else { what->prev->next = what->next; what->next->prev = what->prev; } what->prev = what->next = 0; } /* ** Add element to the tail of linked list */ void diva_q_add_tail (diva_entity_queue_t* q, diva_entity_link_t* what) { what->next = 0; if (!q->head) { what->prev = 0; q->head = q->tail = what; } else { what->prev = q->tail; q->tail->next = what; q->tail = what; } } diva_entity_link_t* diva_q_find (const diva_entity_queue_t* q, const void* what, diva_q_cmp_fn_t cmp_fn) { diva_entity_link_t* diva_current = q->head; while (diva_current) { if (!(*cmp_fn)(what, diva_current)) { break; } diva_current = diva_current->next; } return (diva_current); } diva_entity_link_t* diva_q_get_head (diva_entity_queue_t* q) { return (q->head); } diva_entity_link_t* diva_q_get_tail (diva_entity_queue_t* q) { return (q->tail); } diva_entity_link_t* diva_q_get_next (diva_entity_link_t* what) { return ((what) ? what->next : 0); } diva_entity_link_t* diva_q_get_prev (diva_entity_link_t* what) { return ((what) ? what->prev : 0); } int diva_q_get_nr_of_entries (const diva_entity_queue_t* q) { int i = 0; const diva_entity_link_t* diva_current = q->head; while (diva_current) { i++; diva_current = diva_current->next; } return (i); } |