tesseract 4.1.1
Loading...
Searching...
No Matches
oldlist.h File Reference

Go to the source code of this file.

Classes

struct  list_rec
 

Macros

#define NIL_LIST   static_cast<LIST>(nullptr)
 
#define list_rest(l)   ((l) ? (l)->next : NIL_LIST)
 
#define first_node(l)   ((l) ? (l)->node : NIL_LIST)
 
#define iterate(l)   for (; (l) != NIL_LIST; (l) = list_rest(l))
 
#define set_rest(l, cell)   ((l)->next = (cell))
 

Typedefs

using int_compare = int(*)(void *, void *)
 
using void_dest = void(*)(void *)
 
using LIST = list_rec *
 

Functions

int count (LIST var_list)
 
LIST delete_d (LIST list, void *key, int_compare is_equal)
 
LIST destroy (LIST list)
 
void destroy_nodes (LIST list, void_dest destructor)
 
void insert (LIST list, void *node)
 
LIST last (LIST var_list)
 
LIST pop (LIST list)
 
LIST push (LIST list, void *element)
 
LIST push_last (LIST list, void *item)
 
LIST reverse (LIST list)
 
LIST search (LIST list, void *key, int_compare is_equal)
 

Macro Definition Documentation

◆ first_node

#define first_node (   l)    ((l) ? (l)->node : NIL_LIST)

Definition at line 92 of file oldlist.h.

◆ iterate

#define iterate (   l)    for (; (l) != NIL_LIST; (l) = list_rest(l))

Definition at line 101 of file oldlist.h.

◆ list_rest

#define list_rest (   l)    ((l) ? (l)->next : NIL_LIST)

Definition at line 91 of file oldlist.h.

◆ NIL_LIST

#define NIL_LIST   static_cast<LIST>(nullptr)

Definition at line 76 of file oldlist.h.

◆ set_rest

#define set_rest (   l,
  cell 
)    ((l)->next = (cell))

Definition at line 111 of file oldlist.h.

Typedef Documentation

◆ int_compare

using int_compare = int (*)(void*, void*)

Definition at line 78 of file oldlist.h.

◆ LIST

using LIST = list_rec*

Definition at line 85 of file oldlist.h.

◆ void_dest

using void_dest = void (*)(void*)

Definition at line 79 of file oldlist.h.

Function Documentation

◆ count()

int count ( LIST  var_list)

Definition at line 95 of file oldlist.cpp.

95 {
96 int temp = 0;
97
98 iterate(var_list) temp += 1;
99 return (temp);
100}
#define iterate(l)
Definition: oldlist.h:101

◆ delete_d()

LIST delete_d ( LIST  list,
void *  key,
int_compare  is_equal 
)

Definition at line 110 of file oldlist.cpp.

110 {
111 LIST result = NIL_LIST;
112 LIST last_one = NIL_LIST;
113
114 if (is_equal == nullptr) is_equal = is_same;
115
116 while (list != NIL_LIST) {
117 if (!(*is_equal)(first_node(list), key)) {
118 if (last_one == NIL_LIST) {
119 last_one = list;
120 list = list_rest(list);
121 result = last_one;
122 set_rest(last_one, NIL_LIST);
123 } else {
124 set_rest(last_one, list);
125 last_one = list;
126 list = list_rest(list);
127 set_rest(last_one, NIL_LIST);
128 }
129 } else {
130 list = pop(list);
131 }
132 }
133 return (result);
134}
LIST pop(LIST list)
Definition: oldlist.cpp:201
#define set_rest(l, cell)
Definition: oldlist.h:111
#define first_node(l)
Definition: oldlist.h:92
#define list_rest(l)
Definition: oldlist.h:91
#define NIL_LIST
Definition: oldlist.h:76
#define is_equal(p1, p2)
Definition: outlines.h:105

◆ destroy()

LIST destroy ( LIST  list)

Definition at line 141 of file oldlist.cpp.

141 {
142 LIST next;
143
144 while (list != NIL_LIST) {
145 next = list_rest(list);
146 delete list;
147 list = next;
148 }
149 return (NIL_LIST);
150}

◆ destroy_nodes()

void destroy_nodes ( LIST  list,
void_dest  destructor 
)

Definition at line 157 of file oldlist.cpp.

157 {
158 ASSERT_HOST(destructor != nullptr);
159
160 while (list != NIL_LIST) {
161 if (first_node(list) != nullptr) (*destructor)(first_node(list));
162 list = pop(list);
163 }
164}
#define ASSERT_HOST(x)
Definition: errcode.h:88

◆ insert()

void insert ( LIST  list,
void *  node 
)

Definition at line 172 of file oldlist.cpp.

172 {
173 LIST element;
174
175 if (list != NIL_LIST) {
176 element = push(NIL_LIST, node);
177 set_rest(element, list_rest(list));
178 set_rest(list, element);
179 node = first_node(list);
180 list->node = first_node(list_rest(list));
181 list->next->node = (LIST)node;
182 }
183}
LIST push(LIST list, void *element)
Definition: oldlist.cpp:213
list_rec * LIST
Definition: oldlist.h:85
list_rec * node
Definition: oldlist.h:82
list_rec * next
Definition: oldlist.h:83

◆ last()

LIST last ( LIST  var_list)

Definition at line 190 of file oldlist.cpp.

190 {
191 while (list_rest(var_list) != NIL_LIST) var_list = list_rest(var_list);
192 return (var_list);
193}

◆ pop()

LIST pop ( LIST  list)

Definition at line 201 of file oldlist.cpp.

201 {
202 LIST temp = list_rest(list);
203 delete list;
204 return (temp);
205}

◆ push()

LIST push ( LIST  list,
void *  element 
)

Definition at line 213 of file oldlist.cpp.

213 {
214 LIST t;
215
216 t = new list_rec;
217 t->node = static_cast<LIST>(element);
218 set_rest(t, list);
219 return (t);
220}

◆ push_last()

LIST push_last ( LIST  list,
void *  item 
)

Definition at line 227 of file oldlist.cpp.

227 {
228 LIST t;
229
230 if (list != NIL_LIST) {
231 t = last(list);
232 t->next = push(NIL_LIST, item);
233 return (list);
234 } else
235 return (push(NIL_LIST, item));
236}
LIST last(LIST var_list)
Definition: oldlist.cpp:190

◆ reverse()

LIST reverse ( LIST  list)

Definition at line 244 of file oldlist.cpp.

244 {
245 LIST newlist = NIL_LIST;
246
247 iterate(list) copy_first(list, newlist);
248 return (newlist);
249}
#define copy_first(l1, l2)
Definition: oldlist.cpp:71

◆ search()

LIST search ( LIST  list,
void *  key,
int_compare  is_equal 
)

Definition at line 258 of file oldlist.cpp.

258 {
259 if (is_equal == nullptr) is_equal = is_same;
260
261 iterate(list) if ((*is_equal)(first_node(list), key)) return (list);
262 return (NIL_LIST);
263}