aboutsummaryrefslogtreecommitdiffstats
path: root/utils/Burg/queue.c
blob: 76e5ea9b57b401b0c6810023de35f22fe233e3db (plain)
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
char rcsid_queue[] = "$Id$";

#include "b.h"
#include <stdio.h>

Queue globalQ;

Queue
newQ()
{
	Queue q;

	q = (Queue) zalloc(sizeof(struct queue));
	assert(q);
	q->head = 0;
	q->tail = 0;

	return q;
}

void
addQ(q, ts) Queue q; Item_Set ts;
{
	List qe;

	assert(q);
	assert(ts);

	qe = newList(ts, 0);
	if (q->head) {
		assert(q->tail);
		q->tail->next = qe;
		q->tail = qe;
	} else {
		q->head = q->tail = qe;
	}
}

Item_Set
popQ(q) Queue q;
{
	List qe;
	Item_Set ts;

	assert(q);

	if (q->head) {
		qe = q->head;
		q->head = q->head->next;
		ts = (Item_Set) qe->x;
		zfree(qe);
		return ts;
	} else {
		return 0;
	}
}

void
dumpQ(q) Queue q;
{
	printf("Begin Queue\n");
	foreachList((ListFn)dumpItem_Set, q->head);
	printf("End Queue\n");
}