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 109 110 111 112 113 114 115
|
/* struct::tree - critcl - support - stack/queue of nodes.
* definitions.
*/
#include "tcl.h"
#include <util.h>
static NL* nlq_newitem (void* n);
/* Initialize queue data structure.
*/
void
nlq_init (NLQ* q)
{
q->start = q->end = NULL;
}
/* Add item to end of the list
*/
void
nlq_append (NLQ* q, void* n)
{
NL* qi = nlq_newitem (n);
if (!q->end) {
q->start = q->end = qi;
} else {
q->end->next = qi;
q->end = qi;
}
}
/* Add item to the front of the list
*/
void
nlq_push (NLQ* q, void* n)
{
NL* qi = nlq_newitem (n);
if (!q->end) {
q->start = q->end = qi;
} else {
qi->next = q->start;
q->start = qi;
}
}
/* Return item at front of the list.
*/
void*
nlq_pop (NLQ* q)
{
NL* qi = NULL;
void* n = NULL;
if (!q->start) {
return NULL;
}
qi = q->start;
n = qi->n;
q->start = qi->next;
if (q->end == qi) {
q->end = NULL;
}
ckfree ((char*) qi);
return n;
}
/* Delete all items in the list.
*/
void*
nlq_clear (NLQ* q)
{
NL* next;
NL* qi = q->start;
while (qi) {
next = qi->next;
ckfree ((char*) qi);
qi = next;
}
q->start = NULL;
q->end = NULL;
}
/* INTERNAL - Create new item to put into the list.
*/
static NL*
nlq_newitem (void* n)
{
NL* qi = (NL*) ckalloc (sizeof (NL));
qi->n = n;
qi->next = NULL;
return qi;
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 4
* fill-column: 78
* End:
*/
|