Wild Life  2.29
 All Data Structures Files Functions Variables Typedefs Macros
Functions
list.c File Reference

Go to the source code of this file.

Functions

void List_SetLinkProc (RefListHeader header, RefListGetLinksProc getLinks)
 
void List_InsertAhead (RefListHeader header, Ref atom)
 
void List_Append (RefListHeader header, Ref atom)
 
void List_InsertBefore (RefListHeader header, Ref atom, Ref mark)
 
void List_InsertAfter (RefListHeader header, Ref atom, Ref mark)
 
void List_Swap (RefListHeader header, Ref first, Ref second)
 
static long List_SwapLinks (RefListHeader header, Ref atom)
 
void List_Reverse (RefListHeader header)
 
void List_Remove (RefListHeader header, Ref atom)
 
void List_Concat (RefListHeader header1, RefListHeader header2)
 
long List_EnumFrom (RefListHeader header, Ref atom, RefListEnumProc proc, Ref closure)
 
long List_Enum (RefListHeader header, RefListEnumProc proc, Ref closure)
 
long List_EnumBackFrom (RefListHeader header, Ref atom, RefListEnumProc proc, Ref closure)
 
long List_EnumBack (RefListHeader header, RefListEnumProc proc, Ref closure)
 
static long List_CountAtom (Ref p, Ref nbR)
 
long List_Card (RefListHeader header)
 
long List_IsUnlink (RefListLinks links)
 
void List_Cut (RefListHeader header, Ref atom, RefListHeader newHeader)
 

Function Documentation

void List_Append ( RefListHeader  header,
Ref  atom 
)

Definition at line 63 of file list.c.

References NULL.

66 {
67  RefListGetLinksProc getLinks = header->GetLinks;
68 
69  /* Link to the end of list */
70 
71  if (header->Last != NULL)
72  (*getLinks)(header->Last)->Next = atom;
73 
74  else /* The list is empty */
75  header->First = atom;
76 
77  /* Update links of atom to insert */
78 
79  (*getLinks)(atom)->Prev = header->Last;
80  (*getLinks)(atom)->Next = NULL;
81 
82  /* Update last element of header */
83 
84  header->Last = atom;
85 }
RefListGetLinksProc GetLinks
Definition: def_struct.h:288
#define NULL
Definition: def_const.h:203
RefListLinks(* RefListGetLinksProc)()
Definition: def_struct.h:261
long List_Card ( RefListHeader  header)

Definition at line 410 of file list.c.

References List_CountAtom(), and List_Enum().

412 {
413  long n = 0;
414 
415  (void)List_Enum (header,(RefListEnumProc) List_CountAtom, &n);
416  return n;
417 }
int(* RefListEnumProc)()
Definition: def_struct.h:262
static long List_CountAtom(Ref p, Ref nbR)
Definition: list.c:400
long List_Enum(RefListHeader header, RefListEnumProc proc, Ref closure)
Definition: list.c:341
void List_Concat ( RefListHeader  header1,
RefListHeader  header2 
)

Definition at line 277 of file list.c.

References wl_ListHeader::First, wl_ListHeader::GetLinks, wl_ListHeader::Last, and NULL.

280 {
281  RefListGetLinksProc getLinks = header1->GetLinks;
282 
283  if (header1->GetLinks == header2->GetLinks)
284  {
285 #ifdef prlDEBUG
286  OS_PrintMessage ("List_Concat: ERROR concat different lists\n");
287 #endif
288  return;
289  }
290 
291  /* Concatenate only if the second list is not empty */
292 
293  if (header2->First != NULL)
294  {
295  /* Obvious concatenate when the first list is empty */
296 
297  if (header1->First == NULL)
298  header1->First = header2->First;
299 
300  else /* Concatenate the two non empty lists */
301  {
302  (*getLinks)(header1->Last)->Next = header2->First;
303  (*getLinks)(header2->First)->Prev = header1->Last;
304  }
305  header1->Last = header2->Last;
306  }
307 }
RefListGetLinksProc GetLinks
Definition: def_struct.h:288
#define NULL
Definition: def_const.h:203
RefListLinks(* RefListGetLinksProc)()
Definition: def_struct.h:261
static long List_CountAtom ( Ref  p,
Ref  nbR 
)
static

Definition at line 400 of file list.c.

References TRUE.

403 {
404  long *nb = (long *)nbR;
405 
406  ++*nb;
407  return TRUE;
408 }
#define TRUE
Definition: def_const.h:127
void List_Cut ( RefListHeader  header,
Ref  atom,
RefListHeader  newHeader 
)

Definition at line 429 of file list.c.

References wl_ListHeader::First, wl_ListHeader::Last, List_Last, List_Next, and NULL.

433 {
434  RefListGetLinksProc getLinks = header->GetLinks;
435 
436  if (atom != List_Last (header))
437  {
438  newHeader->First = List_Next (header, atom);
439  newHeader->Last = header->Last;
440 
441  header->Last = atom;
442 
443  /* Update the links */
444  (*getLinks)(atom)->Next = NULL;
445  (*getLinks)(newHeader->First)->Prev = NULL;
446  }
447 }
RefListGetLinksProc GetLinks
Definition: def_struct.h:288
#define NULL
Definition: def_const.h:203
RefListLinks(* RefListGetLinksProc)()
Definition: def_struct.h:261
#define List_Next(header, RefAtom)
Definition: def_macro.h:156
#define List_Last(header)
Definition: def_macro.h:155
long List_Enum ( RefListHeader  header,
RefListEnumProc  proc,
Ref  closure 
)

Definition at line 341 of file list.c.

References List_EnumFrom().

353 {
354  return (List_EnumFrom (header, header->First, proc, closure));
355 }
long List_EnumFrom(RefListHeader header, Ref atom, RefListEnumProc proc, Ref closure)
Definition: list.c:311
long List_EnumBack ( RefListHeader  header,
RefListEnumProc  proc,
Ref  closure 
)

Definition at line 389 of file list.c.

References List_EnumBackFrom().

393 {
394  return (List_EnumBackFrom (header, header->Last, proc, closure));
395 }
long List_EnumBackFrom(RefListHeader header, Ref atom, RefListEnumProc proc, Ref closure)
Definition: list.c:359
long List_EnumBackFrom ( RefListHeader  header,
Ref  atom,
RefListEnumProc  proc,
Ref  closure 
)

Definition at line 359 of file list.c.

References List_Prev, NULL, and TRUE.

364 {
365  Ref cur, prev;
366  int notInterrupted = TRUE;
367 
368 #ifdef prlDEBUG
369  header->Lock += 1;
370 #endif
371 
372  cur = atom;
373  while (cur != NULL && notInterrupted)
374  {
375  prev = List_Prev (header, cur);
376  notInterrupted = (*proc)(cur, closure);
377  cur = prev;
378  }
379 
380 #ifdef prlDEBUG
381  header->Lock -=1;
382 #endif
383 
384  return (notInterrupted);
385 }
#define List_Prev(header, RefAtom)
Definition: def_macro.h:157
#define NULL
Definition: def_const.h:203
#define TRUE
Definition: def_const.h:127
void * Ref
Definition: def_struct.h:258
long List_EnumFrom ( RefListHeader  header,
Ref  atom,
RefListEnumProc  proc,
Ref  closure 
)

Definition at line 311 of file list.c.

References List_Next, NULL, and TRUE.

316 {
317  Ref cur, next;
318  int notInterrupted = TRUE;
319 
320 #ifdef prlDEBUG
321  header->Lock += 1;
322 #endif
323 
324  cur = atom;
325  while (cur != NULL && notInterrupted)
326  {
327  next = List_Next (header, cur);
328  notInterrupted = (*proc)(cur, closure);
329  cur = next;
330  }
331 
332 #ifdef prlDEBUG
333  header->Lock -=1;
334 #endif
335 
336  return (notInterrupted);
337 }
#define NULL
Definition: def_const.h:203
#define List_Next(header, RefAtom)
Definition: def_macro.h:156
#define TRUE
Definition: def_const.h:127
void * Ref
Definition: def_struct.h:258
void List_InsertAfter ( RefListHeader  header,
Ref  atom,
Ref  mark 
)

Definition at line 119 of file list.c.

References List_InsertAhead(), and NULL.

123 {
124  RefListGetLinksProc getLinks = header->GetLinks;
125 
126 #ifdef prlDEBUG
127  if (header->Lock > 1)
128  OS_PrintMessage ("List_InsertAfter: Warning insert after on recursive List_Enum call !!\n");
129 #endif
130 
131  if (mark != NULL)
132  {
133  (*getLinks)(atom)->Prev = mark;
134 
135  if (mark != header->Last)
136  {
137  (*getLinks)(atom)->Next = (*getLinks)(mark)->Next;
138  (*getLinks)((*getLinks)(mark)->Next)->Prev = atom;
139  }
140  else /* Insert at the end of the list */
141  {
142  (*getLinks)(atom)->Next = NULL;
143  header->Last = atom;
144  }
145 
146  (*getLinks)(mark)->Next = atom;
147  }
148  else /* Insert ahead the list */
149  List_InsertAhead (header, atom);
150 }
RefListGetLinksProc GetLinks
Definition: def_struct.h:288
#define NULL
Definition: def_const.h:203
RefListLinks(* RefListGetLinksProc)()
Definition: def_struct.h:261
void List_InsertAhead(RefListHeader header, Ref atom)
Definition: list.c:39
void List_InsertAhead ( RefListHeader  header,
Ref  atom 
)

Definition at line 39 of file list.c.

References NULL.

42 {
43  RefListGetLinksProc getLinks = header->GetLinks;
44 
45  /* Update links of atom to insert */
46 
47  (*getLinks)(atom)->Next = header->First;
48  (*getLinks)(atom)->Prev = NULL;
49 
50  /* Link to the head of list */
51 
52  if (header->First != NULL)
53  (*getLinks)(header->First)->Prev = atom;
54 
55  else /* The list is empty */
56  header->Last = atom;
57 
58  header->First = atom;
59 }
RefListGetLinksProc GetLinks
Definition: def_struct.h:288
#define NULL
Definition: def_const.h:203
RefListLinks(* RefListGetLinksProc)()
Definition: def_struct.h:261
void List_InsertBefore ( RefListHeader  header,
Ref  atom,
Ref  mark 
)

Definition at line 89 of file list.c.

References List_Append(), wl_ListLinks::Next, and NULL.

93 {
94  RefListGetLinksProc getLinks = header->GetLinks;
95 
96  if (mark != NULL)
97  {
98  (*getLinks)(atom)->Next = mark;
99 
100  if (mark != header->First)
101  {
102  (*getLinks)(atom)->Prev = (*getLinks)(mark)->Prev;
103  (*getLinks)((*getLinks)(mark)->Prev)->Next = atom;
104  }
105  else /* Insert ahead the list */
106  {
107  (*getLinks)(atom)->Prev = NULL;
108  header->First = atom;
109  }
110 
111  (*getLinks)(mark)->Prev = atom;
112  }
113  else /* Append to the list */
114  List_Append (header, atom);
115 }
RefListGetLinksProc GetLinks
Definition: def_struct.h:288
#define NULL
Definition: def_const.h:203
RefListLinks(* RefListGetLinksProc)()
Definition: def_struct.h:261
void List_Append(RefListHeader header, Ref atom)
Definition: list.c:63
long List_IsUnlink ( RefListLinks  links)

Definition at line 421 of file list.c.

References NULL.

423 {
424  return (links->Next == NULL && links->Prev == NULL);
425 }
#define NULL
Definition: def_const.h:203
void List_Remove ( RefListHeader  header,
Ref  atom 
)

Definition at line 230 of file list.c.

References NULL.

233 {
234 /*-----------------------------------------------------------------------------
235 
236 WARNING
237  - The container is 'updated' two times if the first and last atom
238  of list is the only one to remove.
239 
240 -----------------------------------------------------------------------------*/
241 
242  RefListGetLinksProc getLinks = header->GetLinks;
243 
244 #ifdef prlDEBUG
245  if (header->Lock > 1)
246  OS_PrintMessage ("List_Remove: Warning remove on recursive List_Enum call !!\n");
247 #endif
248 
249  /* Update the DownStream links */
250 
251  if ((*getLinks)(atom)->Prev != NULL)
252  {
253  (*getLinks)((*getLinks)(atom)->Prev)->Next =
254  (*getLinks)(atom)->Next;
255  }
256  else /* Atom is the first of list */
257  header->First = (*getLinks)(atom)->Next;
258 
259  /* Update the UpStream links */
260 
261  if ((*getLinks)(atom)->Next != NULL)
262  {
263  (*getLinks)((*getLinks)(atom)->Next)->Prev =
264  (*getLinks)(atom)->Prev;
265  }
266  else /* Atom is the last of list */
267  header->Last = (*getLinks)(atom)->Prev;
268 
269  /* Reset the atom links */
270 
271  (*getLinks)(atom)->Prev = NULL;
272  (*getLinks)(atom)->Next = NULL;
273 }
RefListGetLinksProc GetLinks
Definition: def_struct.h:288
#define NULL
Definition: def_const.h:203
RefListLinks(* RefListGetLinksProc)()
Definition: def_struct.h:261
void List_Reverse ( RefListHeader  header)

Definition at line 206 of file list.c.

References List_SwapLinks(), and NULL.

208 {
209  Ref cur, next;
210  RefListGetLinksProc getLinks = header->GetLinks;
211 
212  /* This traverse cannot be done with function List_Enum() */
213 
214  cur = header->First;
215 
216  /* Swap the headers */
217  header->First = header->Last;
218  header->Last = cur;
219 
220  while (cur != NULL)
221  {
222  next = (*getLinks)(cur)->Next;
223  (void)List_SwapLinks (header, cur);
224  cur = next;
225  }
226 }
RefListGetLinksProc GetLinks
Definition: def_struct.h:288
static long List_SwapLinks(RefListHeader header, Ref atom)
Definition: list.c:193
#define NULL
Definition: def_const.h:203
RefListLinks(* RefListGetLinksProc)()
Definition: def_struct.h:261
void * Ref
Definition: def_struct.h:258
void List_SetLinkProc ( RefListHeader  header,
RefListGetLinksProc  getLinks 
)

Definition at line 21 of file list.c.

References NULL.

24 {
25  header->First = NULL;
26  header->Last = NULL;
27 
28 #ifdef prlDEBUG
29  header->Lock = 0;
30 #endif
31 
32  header->GetLinks = getLinks;
33 }
RefListGetLinksProc GetLinks
Definition: def_struct.h:288
#define NULL
Definition: def_const.h:203
void List_Swap ( RefListHeader  header,
Ref  first,
Ref  second 
)

Definition at line 154 of file list.c.

158 {
159  RefListGetLinksProc getLinks = header->GetLinks;
160 
161  /* Don't swap if the input is wrong */
162 
163  if ((*getLinks)(first)->Next != second)
164  {
165 #ifdef prlDEBUG
166  OS_PrintMessage ("List_Swap: WARNING wrong input data, swap not done..\n");
167 #endif
168  return;
169  }
170 
171  /* Special Cases */
172 
173  if (header->First == first)
174  header->First = second;
175  else
176  (*getLinks)((*getLinks)(first)->Prev)->Next = second;
177 
178  if (header->Last == second)
179  header->Last = first;
180  else
181  (*getLinks)((*getLinks)(second)->Next)->Prev = first;
182 
183  /* Swap the atoms */
184 
185  (*getLinks)(second)->Prev = (*getLinks)(first)->Prev;
186  (*getLinks)(first)->Next = (*getLinks)(second)->Next;
187  (*getLinks)(first)->Prev = second;
188  (*getLinks)(second)->Next = first;
189 }
RefListGetLinksProc GetLinks
Definition: def_struct.h:288
RefListLinks(* RefListGetLinksProc)()
Definition: def_struct.h:261
static long List_SwapLinks ( RefListHeader  header,
Ref  atom 
)
static

Definition at line 193 of file list.c.

References TRUE.

196 {
197  Ref save;
198 
199  save = (*header->GetLinks)(atom)->Next;
200  (*header->GetLinks)(atom)->Next = (*header->GetLinks)(atom)->Prev;
201  (*header->GetLinks)(atom)->Prev = save;
202 
203  return TRUE;
204 }
RefListGetLinksProc GetLinks
Definition: def_struct.h:288
#define TRUE
Definition: def_const.h:127
void * Ref
Definition: def_struct.h:258