File: RNQueue.I

package info (click to toggle)
concavity 0.1%2Bdfsg.1-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,988 kB
  • sloc: cpp: 40,945; makefile: 143; sh: 38
file content (249 lines) | stat: -rw-r--r-- 3,820 bytes parent folder | download | duplicates (5)
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/* Inline functions for GAPS queue class */



inline const RNBoolean RNVQueue::
IsEmpty(void) const
{
    // Return whether queue is empty
    return (nentries == 0);
}



inline const int RNVQueue::
NEntries(void) const
{
    // Return number of entries in queue
    return nentries;
}



inline const int RNVQueue::
NAllocated(void) const
{
    // Return number of entries have allocated memory for
    return entries.NEntries();
}



inline const int RNVQueue::
EntryIndex(const RNQueueEntry *entry) const
{
    // Return index of entry in queue
    return KIndex(entries.EntryIndex(entry));
}



inline void *&RNVQueue::
EntryContents(RNQueueEntry *entry) const
{
    // Return pointer to data in entry
    return *entry;
}



inline RNQueueEntry *RNVQueue::
HeadEntry(void) const
{
    // Return pointer to head entry
    return entries.KthEntry(head);
}



inline RNQueueEntry *RNVQueue::
TailEntry(void) const
{
    // Return pointer to tail entry
    return entries.KthEntry(KOffarray(nentries-1));
}



inline RNQueueEntry *RNVQueue::
KthEntry(int k) const
{
    // Return kth entry
    return entries.KthEntry(KOffarray(k));
}



inline RNQueueEntry *RNVQueue::
PrevEntry(const RNQueueEntry *entry) const
{
    // Return pointer to previous entry
    return (entry == entries.HeadEntry()) ? entries.TailEntry() : entries.PrevEntry(entry);
}



inline RNQueueEntry *RNVQueue::
NextEntry(const RNQueueEntry *entry) const
{
    // Return pointer to next entry
    return (entry == entries.TailEntry()) ? entries.HeadEntry() : entries.NextEntry(entry);
}



inline void *RNVQueue::
Kth(int k) const
{
    // Return kth data element
    assert(nentries >= 0);
    assert((k >= 0) && (k < nentries));
    return EntryContents(KthEntry(k));
}



inline void *RNVQueue::
Head(void) const
{
    // Return head data element
    return Kth(0);
}



inline void *RNVQueue::
Tail(void) const
{
    // Return tail data element
    return Kth(nentries-1);
}



inline void *RNVQueue::
operator[](int k) const
{
    // Return kth data element
    return Kth(k);
}



inline RNQueueEntry *RNVQueue::
InsertHead(void *data)
{
    // Insert data into queue at head
    return InternalInsert(data, 0);
}



inline RNQueueEntry *RNVQueue::
InsertTail(void *data)
{
    // Insert data into queue at tail
    return InternalInsert(data, nentries);
}



inline RNQueueEntry *RNVQueue::
InsertKth(void *data, int k)
{
    // Insert data into queue in kth position
    return InternalInsert(data, k);
}



inline RNQueueEntry *RNVQueue::
InsertBefore(void *data, RNQueueEntry *entry)
{
    // Insert data into queue before entry
    return InternalInsert(data, EntryIndex(entry));
}



inline RNQueueEntry *RNVQueue::
InsertAfter(void *data, RNQueueEntry *entry)
{
    // Insert data into queue after entry
    return InternalInsert(data, EntryIndex(entry)+1);
}



inline RNQueueEntry *RNVQueue::
Insert(void *data)
{
    // Insert data into queue at default position (head)
    return InsertTail(data);
}



inline void RNVQueue::
RemoveHead(void)
{
    // Remove head entry from queue
    InternalRemove(0);
}



inline void RNVQueue::
RemoveTail(void)
{
    // Remove tail entry from queue
    InternalRemove(nentries-1);
}



inline void RNVQueue::
RemoveKth(int k) 
{
    // Remove kth entry
    InternalRemove(k);
}



inline void RNVQueue::
RemoveEntry(RNQueueEntry *entry)
{
    // Remove data from queue
    InternalRemove(EntryIndex(entry));
}



inline void RNVQueue::
Remove(const void *data)
{
    // Remove data from queue
    RemoveEntry(FindEntry(data));
}



inline RNQueueEntry *RNVQueue::
Push(void *data)
{
    // Add data to head of queue
    return InsertTail(data);
}



inline void *RNVQueue::
Peek(void)
{
    // Return data from head of queue
    return (IsEmpty()) ? NULL : EntryContents(HeadEntry());
}