My Project
Loading...
Searching...
No Matches
Macros | Functions
omList.c File Reference
#include "omConfig.h"
#include "omalloc.h"
#include "omDebug.h"

Go to the source code of this file.

Macros

#define NULL   ((void*) 0)
 
#define _VALUE(list, offset)   *((void**) ((char *)list + offset))
 
#define VALUE(list, offset)   (unsigned long) _VALUE(list, offset)
 
#define NEXT(list)   _VALUE(list, next)
 
#define ITER(list)   list = NEXT(list)
 

Functions

int _omListLength (void *list, int next)
 
void * _omListLast (void *list, int next)
 
void * _omListHasCycle (void *list, int next)
 
void * _omIsOnList (void *list, int next, void *addr)
 
void * _omRemoveFromList (void *list, int next, void *addr)
 
void * _omFindInList (void *list, int next, int long_field, unsigned long what)
 
void * _omFindInSortedList (void *list, int next, int long_field, unsigned long what)
 
void * _omRemoveFromSortedList (void *list, int next, int long_field, void *addr)
 
void * _omInsertInSortedList (void *list, int next, int long_field, void *addr)
 
omError_t _omCheckList (void *list, int next, int level, omError_t report, OM_FLR_DECL)
 
omError_t _omCheckSortedList (void *list, int next, int long_field, int level, omError_t report, OM_FLR_DECL)
 

Macro Definition Documentation

◆ _VALUE

#define _VALUE (   list,
  offset 
)    *((void**) ((char *)list + offset))

Definition at line 15 of file omList.c.

◆ ITER

#define ITER (   list)    list = NEXT(list)

Definition at line 18 of file omList.c.

◆ NEXT

#define NEXT (   list)    _VALUE(list, next)

Definition at line 17 of file omList.c.

◆ NULL

#define NULL   ((void*) 0)

Definition at line 12 of file omList.c.

◆ VALUE

#define VALUE (   list,
  offset 
)    (unsigned long) _VALUE(list, offset)

Definition at line 16 of file omList.c.

Function Documentation

◆ _omCheckList()

omError_t _omCheckList ( void *  list,
int  next,
int  level,
omError_t  report,
OM_FLR_DECL   
)

Definition at line 178 of file omList.c.

179{
180 if (level < 1) return omError_NoError;
181
182 if (level == 1)
183 {
184 while (list != NULL)
185 {
186 omCheckReturn(omCheckPtr(list, report, OM_FLR_VAL));
187 ITER(list);
188 }
189 }
190 else
191 {
192 void* l1 = list;
193 void* l2;
194 int l = 0, i;
195
196 l1 = list;
197 while (l1 != NULL)
198 {
199 omCheckReturn(omCheckPtr(l1, report, OM_FLR_VAL));
200 i = 0;
201 l2 = list;
202 while (l1 != l2)
203 {
204 i++;
205 ITER(l2);
206 }
207 if (i != l)
208 return omReportError(omError_ListCycleError, report, OM_FLR_VAL, "");
209 ITER(l1);
210 l++;
211 }
212 }
213 return omError_NoError;
214}
int level(const CanonicalForm &f)
int l
Definition: cfEzgcd.cc:100
int i
Definition: cfEzgcd.cc:132
omError_t omCheckPtr(const void *ptr, omError_t report, OM_FLR_DECL)
Definition: omDebugCheck.c:136
#define omCheckReturn(cond)
Definition: omDebug.h:170
omError_t omReportError(omError_t error, omError_t report_error, OM_FLR_DECL, const char *fmt,...)
Definition: omError.c:80
@ omError_ListCycleError
Definition: omError.h:34
@ omError_NoError
Definition: omError.h:18
#define NULL
Definition: omList.c:12
#define ITER(list)
Definition: omList.c:18

◆ _omCheckSortedList()

omError_t _omCheckSortedList ( void *  list,
int  next,
int  long_field,
int  level,
omError_t  report,
OM_FLR_DECL   
)

Definition at line 216 of file omList.c.

217{
218 void* prev = NULL;
219
220 if (level <= 1) return omError_NoError;
221
222 if (level == 1)
223 {
224 while (list != NULL)
225 {
226 omCheckReturn(omCheckPtr(list, report, OM_FLR_VAL));
227 if (prev != NULL && VALUE(prev, long_field) > VALUE(list, long_field))
228 return omReportError(omError_SortedListError, report, OM_FLR_VAL,
229 "%d > %d", VALUE(prev, long_field), VALUE(list, long_field));
230 prev = list;
231 ITER(list);
232 }
233 }
234 else
235 {
236 void* l1 = list;
237 void* l2;
238 int l = 0, i;
239
240 while (l1 != NULL)
241 {
242 omCheckReturn(omCheckPtr(l1, report, OM_FLR_VAL));
243 if (prev != NULL && VALUE(prev, long_field) > VALUE(l1, long_field))
244 return omReportError(omError_SortedListError, report, OM_FLR_VAL,
245 "%d > %d", VALUE(prev, long_field), VALUE(l1, long_field));
246 i = 0;
247 l2 = list;
248 while (l1 != l2)
249 {
250 i++;
251 ITER(l2);
252 }
254 prev = l1;
255 ITER(l1);
256 l++;
257 }
258 }
259 return omError_NoError;
260}
#define omCheckReturnError(cond, error)
Definition: omDebug.h:172
@ omError_SortedListError
Definition: omError.h:35
#define VALUE(list, offset)
Definition: omList.c:16

◆ _omFindInList()

void * _omFindInList ( void *  list,
int  next,
int  long_field,
unsigned long  what 
)

Definition at line 100 of file omList.c.

101{
102 while (list != NULL)
103 {
104 if (VALUE(list, long_field) == what) return list;
105 ITER(list);
106 }
107 return NULL;
108}

◆ _omFindInSortedList()

void * _omFindInSortedList ( void *  list,
int  next,
int  long_field,
unsigned long  what 
)

Definition at line 110 of file omList.c.

112{
113 while (list != NULL)
114 {
115 if (VALUE(list, long_field) >= what)
116 {
117 if (VALUE(list, long_field) == what) return list;
118 return NULL;
119 }
120 ITER(list);
121 }
122 return NULL;
123}

◆ _omInsertInSortedList()

void * _omInsertInSortedList ( void *  list,
int  next,
int  long_field,
void *  addr 
)

Definition at line 148 of file omList.c.

149{
150 unsigned long what = VALUE(addr, long_field);
151
152 if (list == NULL || what <= VALUE(list, long_field))
153 {
154 NEXT(addr) = list;
155 return addr;
156 }
157 else
158 {
159 void* prev = list;
160 void* curr = NEXT(list);
161
162 while (curr != NULL && VALUE(curr, long_field) < what)
163 {
164 prev = curr;
165 ITER(curr);
166 }
167 NEXT(prev) = addr;
168 NEXT(addr) = curr;
169 return list;
170 }
171}
#define NEXT(list)
Definition: omList.c:17

◆ _omIsOnList()

void * _omIsOnList ( void *  list,
int  next,
void *  addr 
)

Definition at line 66 of file omList.c.

67{
68 if (addr == NULL)
69 return (NULL);
70
71 while (list != NULL)
72 {
73 if (addr == list) return addr;
74 ITER(list);
75 }
76 return 0;
77}

◆ _omListHasCycle()

void * _omListHasCycle ( void *  list,
int  next 
)

Definition at line 42 of file omList.c.

43{
44 void* l1 = list;
45 void* l2;
46
47 int l = 0, i;
48
49 while (l1 != NULL)
50 {
51 i = 0;
52 l2 = list;
53 while (l1 != l2)
54 {
55 i++;
56 ITER(l2);
57 }
58 if (i != l) return l1;
59 ITER(l1);
60 l++;
61 }
62 return NULL;
63}

◆ _omListLast()

void * _omListLast ( void *  list,
int  next 
)

Definition at line 32 of file omList.c.

33{
34 if (list == NULL) return NULL;
35
36 while (NEXT(list) != NULL) ITER(list);
37
38 return list;
39}

◆ _omListLength()

int _omListLength ( void *  list,
int  next 
)

Definition at line 20 of file omList.c.

21{
22 int l = 0;
23 while (list != NULL)
24 {
25 l++;
26 ITER(list);
27 }
28 return l;
29}

◆ _omRemoveFromList()

void * _omRemoveFromList ( void *  list,
int  next,
void *  addr 
)

Definition at line 79 of file omList.c.

80{
81 void* nlist;
82 void* olist;
83
84 if (list == NULL) return NULL;
85
86 nlist = NEXT(list);
87 if (list == addr) return nlist;
88
89 olist = list;
90 while (nlist != NULL && nlist != addr)
91 {
92 list = nlist;
93 ITER(nlist);
94 }
95
96 if (nlist != NULL) NEXT(list) = NEXT(nlist);
97 return olist;
98}

◆ _omRemoveFromSortedList()

void * _omRemoveFromSortedList ( void *  list,
int  next,
int  long_field,
void *  addr 
)

Definition at line 125 of file omList.c.

126{
127 void* nlist;
128 void* olist;
129 unsigned long what = VALUE(addr, long_field);
130
131 if (list == NULL) return NULL;
132 nlist = NEXT(list);
133 if (list == addr) return nlist;
134 if (VALUE(list, long_field) > what) return list;
135
136 olist = list;
137 while (nlist != NULL && nlist != addr)
138 {
139 if (VALUE(list, long_field) > what) return olist;
140 list = nlist;
141 ITER(nlist);
142 }
143
144 if (nlist != NULL) NEXT(list) = NEXT(nlist);
145 return olist;
146}