-
Notifications
You must be signed in to change notification settings - Fork 0
/
enet_list.pas
145 lines (101 loc) · 3.42 KB
/
enet_list.pas
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
unit enet_list;
(**
@file list.c
@brief ENet linked list functions
freepascal
1.3.6
*)
(**
@defgroup list ENet linked list utility functions
@ingroup private
@{
*)
interface
uses enet_consts;
function enet_list_begin(list:pointer):pENetListNode;
function enet_list_end(list:pointer):pENetListNode;
function enet_list_empty(list:pointer):boolean;
function enet_list_next(iterator:pENetListNode):pENetListNode;
function enet_list_previous(iterator:pENetListNode):pENetListNode;
function enet_list_front(list:pointer):pENetListNode;
function enet_list_back(list:pointer):pENetListNode;
procedure enet_list_clear (list : pointer);
function enet_list_insert (position : ENetListIterator; data : pointer):ENetListIterator;
function enet_list_remove (position : ENetListIterator):pENetListNode;
function enet_list_move (position : ENetListIterator; dataFirst, dataLast : Pointer):ENetListIterator;
function enet_list_size (list : pENetList):enet_size_t;
implementation
function enet_list_begin(list:pointer):pENetListNode;
begin
result := pENetlist(list)^.sentinel.next;
end;
function enet_list_end(list:pointer):pENetListNode;
begin
result := @(pEnetList(list)^.sentinel);
end;
function enet_list_empty(list:pointer):boolean;
begin
result := enet_list_begin (list) = enet_list_end (list);
end;
function enet_list_next(iterator:pENetListNode):pENetListNode;
begin
result := iterator ^. next;
end;
function enet_list_previous(iterator:pENetListNode):pENetListNode;
begin
result := iterator ^. previous;
end;
function enet_list_front(list:pointer):pENetListNode;
begin
result := pENetList(list)^.sentinel.next;
end;
function enet_list_back(list:pointer):pENetListNode;
begin
result := pENetList (list) ^. sentinel.previous;
end;
procedure enet_list_clear (list : pointer);
begin
pENetList(list)^.sentinel.next := @(pENetList(list)^. sentinel);
pEnetList(list)^.sentinel.previous := @(pENetList(list)^. sentinel);
end;
function enet_list_insert (position : ENetListIterator; data : pointer):ENetListIterator;
begin
result := ENetListIterator(data);
result ^. previous := position ^. previous;
result ^. next := pENetListNode(position);
result ^. previous ^. next := pENetListNode(result);
position ^. previous := pENetListNode(result);
end;
function enet_list_remove (position : ENetListIterator):pENetListNode;
begin
position ^. previous ^. next := position ^. next;
position ^. next ^. previous := position ^. previous;
result := pENetListNode(position);
end;
function enet_list_move (position : ENetListIterator; dataFirst, dataLast : Pointer):ENetListIterator;
var
first, last : ENetListIterator;
begin
first := ENetListIterator(dataFirst);
last := ENetListIterator(dataLast);
first^ . previous^ . next := last^ . next;
last^ . next^ . previous := first^ . previous;
first^ . previous := position^ . previous;
last^ . next := position;
first^ . previous^ . next := first;
position^ . previous := last;
result := first;
end;
function enet_list_size (list : pENetList):enet_size_t;
var
position : pENetListNode; // ENetListIterator
begin
result :=0;
position := enet_list_begin(list);
while position <> enet_list_end(list) do begin
inc(result);
position := enet_list_next(position);
end;
end;
(** @} *)
end.