aboutsummaryrefslogtreecommitdiff
path: root/Src/replicant/nu/nodelist.c
blob: f1c21ea402b1f5dce2a0663a5bb955d6588f27f3 (plain) (blame)
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
#include "nodelist.h"

void nodelist_init(nodelist_t nodelist)
{
	nodelist->head=0;
	nodelist->tail=0;
}

void nodelist_push_back(nodelist_t nodelist, queue_node_t *item)
{
	if (!nodelist->head)
	{
		nodelist->head=item;
		nodelist->tail=item;
	}
	else
	{
		nodelist->tail->Next=item;
		nodelist->tail=item;
	}
	item->Next = 0;
}

void nodelist_push_front(nodelist_t nodelist, queue_node_t *item)
{
	if (!nodelist->head)
	{
		nodelist->head=item;
		nodelist->tail=item;
		item->Next=0;
	}
	else
	{
		item->Next = nodelist->head;
		nodelist->head = item;
	}
}

queue_node_t *nodelist_pop_front(nodelist_t nodelist)
{
	queue_node_t *ret;
	if (!nodelist->head)
		return 0;

	ret = nodelist->head;
	nodelist->head = nodelist->head->Next;
	ret->Next = 0; // so we don't confuse anyone

	if (ret == nodelist->tail)
	{
		nodelist->tail = 0;
	}
	return ret;
}

void nodelist_push_back_list(nodelist_t nodelist, queue_node_t *item)
{
	if (!nodelist->head)
	{
		nodelist->head=item;
	}
	else
	{
		nodelist->tail->Next=item;
	}

	while (item->Next)
		item = item->Next;

	nodelist->tail = item;
}