tesseract  4.0.0-1-g2a2b
oldlist.h File Reference
#include "cutil.h"
#include "tesscallback.h"

Go to the source code of this file.

Classes

struct  list_rec
 

Macros

#define NIL_LIST   ((LIST)nullptr)
 
#define list_rest(l)   ((l) ? (l)->next : NIL_LIST)
 
#define first_node(l)   ((l) ? (l)->node : NIL_LIST)
 
#define copy_first(l1, l2)   (l2=push(l2, first_node(l1)))
 
#define iterate(l)   for (; (l) != NIL_LIST; (l) = list_rest (l))
 
#define iterate_list(x, l)   for ((x)=(l); (x)!=0; (x)=list_rest(x))
 
#define JOIN_ON(list1, list2)   ((list1) = join ((list1), (list2)))
 
#define pop_off(list)   ((list) = pop (list))
 
#define push_on(list, thing)   ((list) = push (list, (LIST) (thing)))
 
#define second_node(l)   first_node (list_rest (l))
 
#define set_rest(l, cell)   ((l)->next = (cell))
 
#define third(l)   first_node (list_rest (list_rest (l)))
 

Typedefs

using LIST = list_rec *
 

Functions

int count (LIST var_list)
 
LIST delete_d (LIST list, void *key, int_compare is_equal)
 
LIST delete_d (LIST list, void *key, TessResultCallback2< int, void *, void *> *is_equal)
 
LIST destroy (LIST list)
 
void destroy_nodes (LIST list, void_dest destructor)
 
void insert (LIST list, void *node)
 
int is_same (void *item1, void *item2)
 
LIST join (LIST list1, LIST list2)
 
LIST last (LIST var_list)
 
void * nth_cell (LIST var_list, int item_num)
 
LIST pop (LIST list)
 
LIST push (LIST list, void *element)
 
LIST push_last (LIST list, void *item)
 
LIST reverse (LIST list)
 
LIST reverse_d (LIST list)
 
LIST s_adjoin (LIST var_list, void *variable, int_compare compare)
 
LIST search (LIST list, void *key, int_compare is_equal)
 
LIST search (LIST list, void *key, TessResultCallback2< int, void *, void *> *)
 

Macro Definition Documentation

◆ copy_first

#define copy_first (   l1,
  l2 
)    (l2=push(l2, first_node(l1)))

Definition at line 151 of file oldlist.h.

◆ first_node

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

Definition at line 141 of file oldlist.h.

◆ iterate

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

Definition at line 161 of file oldlist.h.

◆ iterate_list

#define iterate_list (   x,
 
)    for ((x)=(l); (x)!=0; (x)=list_rest(x))

Definition at line 172 of file oldlist.h.

◆ JOIN_ON

#define JOIN_ON (   list1,
  list2 
)    ((list1) = join ((list1), (list2)))

Definition at line 182 of file oldlist.h.

◆ list_rest

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

Definition at line 140 of file oldlist.h.

◆ NIL_LIST

#define NIL_LIST   ((LIST)nullptr)

Definition at line 127 of file oldlist.h.

◆ pop_off

#define pop_off (   list)    ((list) = pop (list))

Definition at line 192 of file oldlist.h.

◆ push_on

#define push_on (   list,
  thing 
)    ((list) = push (list, (LIST) (thing)))

Definition at line 202 of file oldlist.h.

◆ second_node

#define second_node (   l)    first_node (list_rest (l))

Definition at line 213 of file oldlist.h.

◆ set_rest

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

Definition at line 224 of file oldlist.h.

◆ third

#define third (   l)    first_node (list_rest (list_rest (l)))

Definition at line 235 of file oldlist.h.

Typedef Documentation

◆ LIST

using LIST = list_rec *

Definition at line 134 of file oldlist.h.

Function Documentation

◆ count()

int count ( LIST  var_list)

Definition at line 98 of file oldlist.cpp.

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

◆ delete_d() [1/2]

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

Definition at line 114 of file oldlist.cpp.

114  {
115  LIST result = NIL_LIST;
116  LIST last_one = NIL_LIST;
117 
118  if (is_equal == nullptr) is_equal = is_same;
119 
120  while (list != NIL_LIST) {
121  if (!(*is_equal)(first_node(list), key)) {
122  if (last_one == NIL_LIST) {
123  last_one = list;
124  list = list_rest(list);
125  result = last_one;
126  set_rest(last_one, NIL_LIST);
127  } else {
128  set_rest(last_one, list);
129  last_one = list;
130  list = list_rest(list);
131  set_rest(last_one, NIL_LIST);
132  }
133  } else {
134  list = pop(list);
135  }
136  }
137  return (result);
138 }
#define set_rest(l, cell)
Definition: oldlist.h:224
LIST pop(LIST list)
Definition: oldlist.cpp:266
#define list_rest(l)
Definition: oldlist.h:140
#define is_equal(p1, p2)
Definition: outlines.h:110
#define first_node(l)
Definition: oldlist.h:141
#define NIL_LIST
Definition: oldlist.h:127
int is_same(void *item1, void *item2)
Definition: oldlist.cpp:220

◆ delete_d() [2/2]

LIST delete_d ( LIST  list,
void *  key,
TessResultCallback2< int, void *, void *> *  is_equal 
)

Definition at line 140 of file oldlist.cpp.

141  {
142  LIST result = NIL_LIST;
143  LIST last_one = NIL_LIST;
144 
145  while (list != NIL_LIST) {
146  if (!(*is_equal).Run(first_node(list), key)) {
147  if (last_one == NIL_LIST) {
148  last_one = list;
149  list = list_rest(list);
150  result = last_one;
151  set_rest(last_one, NIL_LIST);
152  } else {
153  set_rest(last_one, list);
154  last_one = list;
155  list = list_rest(list);
156  set_rest(last_one, NIL_LIST);
157  }
158  } else {
159  list = pop(list);
160  }
161  }
162  return (result);
163 }
#define set_rest(l, cell)
Definition: oldlist.h:224
LIST pop(LIST list)
Definition: oldlist.cpp:266
#define list_rest(l)
Definition: oldlist.h:140
#define first_node(l)
Definition: oldlist.h:141
#define NIL_LIST
Definition: oldlist.h:127

◆ destroy()

LIST destroy ( LIST  list)

Definition at line 170 of file oldlist.cpp.

170  {
171  LIST next;
172 
173  while (list != NIL_LIST) {
174  next = list_rest(list);
175  free_cell(list);
176  list = next;
177  }
178  return (NIL_LIST);
179 }
#define list_rest(l)
Definition: oldlist.h:140
#define NIL_LIST
Definition: oldlist.h:127
void free_cell(LIST)

◆ destroy_nodes()

void destroy_nodes ( LIST  list,
void_dest  destructor 
)

Definition at line 186 of file oldlist.cpp.

186  {
187  ASSERT_HOST(destructor != nullptr);
188 
189  while (list != NIL_LIST) {
190  if (first_node(list) != nullptr) (*destructor)(first_node(list));
191  list = pop(list);
192  }
193 }
LIST pop(LIST list)
Definition: oldlist.cpp:266
#define first_node(l)
Definition: oldlist.h:141
#define NIL_LIST
Definition: oldlist.h:127
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ insert()

void insert ( LIST  list,
void *  node 
)

Definition at line 201 of file oldlist.cpp.

201  {
202  LIST element;
203 
204  if (list != NIL_LIST) {
205  element = push(NIL_LIST, node);
206  set_rest(element, list_rest(list));
207  set_rest(list, element);
208  node = first_node(list);
209  list->node = first_node(list_rest(list));
210  list->next->node = (LIST)node;
211  }
212 }
#define set_rest(l, cell)
Definition: oldlist.h:224
LIST push(LIST list, void *element)
Definition: oldlist.cpp:283
#define list_rest(l)
Definition: oldlist.h:140
struct list_rec * next
Definition: oldlist.h:132
#define first_node(l)
Definition: oldlist.h:141
#define NIL_LIST
Definition: oldlist.h:127
list_rec * LIST
Definition: oldlist.h:134
struct list_rec * node
Definition: oldlist.h:131

◆ is_same()

int is_same ( void *  item1,
void *  item2 
)

Definition at line 220 of file oldlist.cpp.

220  {
221  return strcmp((char *)item1, (char *)item2) == 0 ? 1 : 0;
222 }

◆ join()

LIST join ( LIST  list1,
LIST  list2 
)

Definition at line 231 of file oldlist.cpp.

231  {
232  if (list1 == NIL_LIST) return (list2);
233  set_rest(last(list1), list2);
234  return (list1);
235 }
LIST last(LIST var_list)
Definition: oldlist.cpp:242
#define set_rest(l, cell)
Definition: oldlist.h:224
#define NIL_LIST
Definition: oldlist.h:127

◆ last()

LIST last ( LIST  var_list)

Definition at line 242 of file oldlist.cpp.

242  {
243  while (list_rest(var_list) != NIL_LIST) var_list = list_rest(var_list);
244  return (var_list);
245 }
#define list_rest(l)
Definition: oldlist.h:140
#define NIL_LIST
Definition: oldlist.h:127

◆ nth_cell()

void* nth_cell ( LIST  var_list,
int  item_num 
)

Definition at line 252 of file oldlist.cpp.

252  {
253  int x = 0;
254  iterate(var_list) {
255  if (x++ == item_num) return (var_list);
256  }
257  return (var_list);
258 }
#define iterate(l)
Definition: oldlist.h:161

◆ pop()

LIST pop ( LIST  list)

Definition at line 266 of file oldlist.cpp.

266  {
267  LIST temp;
268 
269  temp = list_rest(list);
270 
271  if (list != NIL_LIST) {
272  free_cell(list);
273  }
274  return (temp);
275 }
#define list_rest(l)
Definition: oldlist.h:140
#define NIL_LIST
Definition: oldlist.h:127
void free_cell(LIST)

◆ push()

LIST push ( LIST  list,
void *  element 
)

Definition at line 283 of file oldlist.cpp.

283  {
284  LIST t;
285 
286  t = new_cell();
287  t->node = (LIST)element;
288  set_rest(t, list);
289  return (t);
290 }
#define set_rest(l, cell)
Definition: oldlist.h:224
list_rec * LIST
Definition: oldlist.h:134
struct list_rec * node
Definition: oldlist.h:131
LIST new_cell()

◆ push_last()

LIST push_last ( LIST  list,
void *  item 
)

Definition at line 297 of file oldlist.cpp.

297  {
298  LIST t;
299 
300  if (list != NIL_LIST) {
301  t = last(list);
302  t->next = push(NIL_LIST, item);
303  return (list);
304  } else
305  return (push(NIL_LIST, item));
306 }
LIST last(LIST var_list)
Definition: oldlist.cpp:242
LIST push(LIST list, void *element)
Definition: oldlist.cpp:283
struct list_rec * next
Definition: oldlist.h:132
#define NIL_LIST
Definition: oldlist.h:127

◆ reverse()

LIST reverse ( LIST  list)

Definition at line 314 of file oldlist.cpp.

314  {
315  LIST newlist = NIL_LIST;
316 
317  iterate(list) copy_first(list, newlist);
318  return (newlist);
319 }
#define copy_first(l1, l2)
Definition: oldlist.h:151
#define NIL_LIST
Definition: oldlist.h:127
#define iterate(l)
Definition: oldlist.h:161

◆ reverse_d()

LIST reverse_d ( LIST  list)

Definition at line 327 of file oldlist.cpp.

327  {
328  LIST result = reverse(list);
329  destroy(list);
330  return (result);
331 }
LIST reverse(LIST list)
Definition: oldlist.cpp:314
LIST destroy(LIST list)
Definition: oldlist.cpp:170

◆ s_adjoin()

LIST s_adjoin ( LIST  var_list,
void *  variable,
int_compare  compare 
)

Definition at line 339 of file oldlist.cpp.

339  {
340  LIST l;
341  int result;
342 
343  if (compare == nullptr) compare = (int_compare)strcmp;
344 
345  l = var_list;
346  iterate(l) {
347  result = (*compare)(variable, first_node(l));
348  if (result == 0)
349  return (var_list);
350  else if (result < 0) {
351  insert(l, variable);
352  return (var_list);
353  }
354  }
355  return (push_last(var_list, variable));
356 }
void insert(LIST list, void *node)
Definition: oldlist.cpp:201
LIST push_last(LIST list, void *item)
Definition: oldlist.cpp:297
#define first_node(l)
Definition: oldlist.h:141
int(* int_compare)(void *, void *)
Definition: cutil.h:32
#define iterate(l)
Definition: oldlist.h:161

◆ search() [1/2]

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

Definition at line 366 of file oldlist.cpp.

366  {
367  if (is_equal == nullptr) is_equal = is_same;
368 
369  iterate(list) if ((*is_equal)(first_node(list), key)) return (list);
370  return (NIL_LIST);
371 }
#define is_equal(p1, p2)
Definition: outlines.h:110
#define first_node(l)
Definition: oldlist.h:141
#define NIL_LIST
Definition: oldlist.h:127
#define iterate(l)
Definition: oldlist.h:161
int is_same(void *item1, void *item2)
Definition: oldlist.cpp:220

◆ search() [2/2]

LIST search ( LIST  list,
void *  key,
TessResultCallback2< int, void *, void *> *   
)

Definition at line 373 of file oldlist.cpp.

374  {
375  iterate(list) if ((*is_equal).Run(first_node(list), key)) return (list);
376  return (NIL_LIST);
377 }
#define first_node(l)
Definition: oldlist.h:141
#define NIL_LIST
Definition: oldlist.h:127
#define iterate(l)
Definition: oldlist.h:161