tesseract  4.00.00dev
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) 0
 
#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

typedef list_recLIST
 

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 149 of file oldlist.h.

◆ first_node

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

Definition at line 139 of file oldlist.h.

◆ iterate

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

Definition at line 159 of file oldlist.h.

◆ iterate_list

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

Definition at line 170 of file oldlist.h.

◆ JOIN_ON

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

Definition at line 180 of file oldlist.h.

◆ list_rest

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

Definition at line 138 of file oldlist.h.

◆ NIL_LIST

#define NIL_LIST   (LIST) 0

Definition at line 126 of file oldlist.h.

◆ pop_off

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

Definition at line 190 of file oldlist.h.

◆ push_on

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

Definition at line 200 of file oldlist.h.

◆ second_node

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

Definition at line 211 of file oldlist.h.

◆ set_rest

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

Definition at line 222 of file oldlist.h.

◆ third

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

Definition at line 233 of file oldlist.h.

Typedef Documentation

◆ LIST

typedef list_rec* LIST

Definition at line 132 of file oldlist.h.

Function Documentation

◆ count()

int count ( LIST  var_list)

Definition at line 103 of file oldlist.cpp.

103  {
104  int temp = 0;
105 
106  iterate(var_list) temp += 1;
107  return (temp);
108 }
#define iterate(l)
Definition: oldlist.h:159

◆ delete_d() [1/2]

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

Definition at line 119 of file oldlist.cpp.

119  {
120  LIST result = NIL_LIST;
121  LIST last_one = NIL_LIST;
122 
123  if (is_equal == NULL) is_equal = is_same;
124 
125  while (list != NIL_LIST) {
126  if (!(*is_equal)(first_node(list), key)) {
127  if (last_one == NIL_LIST) {
128  last_one = list;
129  list = list_rest(list);
130  result = last_one;
131  set_rest(last_one, NIL_LIST);
132  } else {
133  set_rest(last_one, list);
134  last_one = list;
135  list = list_rest(list);
136  set_rest(last_one, NIL_LIST);
137  }
138  } else {
139  list = pop(list);
140  }
141  }
142  return (result);
143 }
LIST pop(LIST list)
Definition: oldlist.cpp:271
int is_same(void *item1, void *item2)
Definition: oldlist.cpp:225
#define list_rest(l)
Definition: oldlist.h:138
#define is_equal(p1, p2)
Definition: outlines.h:109
#define set_rest(l, cell)
Definition: oldlist.h:222
#define NIL_LIST
Definition: oldlist.h:126
#define first_node(l)
Definition: oldlist.h:139

◆ delete_d() [2/2]

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

Definition at line 145 of file oldlist.cpp.

146  {
147  LIST result = NIL_LIST;
148  LIST last_one = NIL_LIST;
149 
150  while (list != NIL_LIST) {
151  if (!(*is_equal).Run(first_node(list), key)) {
152  if (last_one == NIL_LIST) {
153  last_one = list;
154  list = list_rest(list);
155  result = last_one;
156  set_rest(last_one, NIL_LIST);
157  } else {
158  set_rest(last_one, list);
159  last_one = list;
160  list = list_rest(list);
161  set_rest(last_one, NIL_LIST);
162  }
163  } else {
164  list = pop(list);
165  }
166  }
167  return (result);
168 }
LIST pop(LIST list)
Definition: oldlist.cpp:271
#define list_rest(l)
Definition: oldlist.h:138
#define set_rest(l, cell)
Definition: oldlist.h:222
#define NIL_LIST
Definition: oldlist.h:126
#define first_node(l)
Definition: oldlist.h:139

◆ destroy()

LIST destroy ( LIST  list)

Definition at line 175 of file oldlist.cpp.

175  {
176  LIST next;
177 
178  while (list != NIL_LIST) {
179  next = list_rest(list);
180  free_cell(list);
181  list = next;
182  }
183  return (NIL_LIST);
184 }
#define list_rest(l)
Definition: oldlist.h:138
void free_cell(LIST)
#define NIL_LIST
Definition: oldlist.h:126

◆ destroy_nodes()

void destroy_nodes ( LIST  list,
void_dest  destructor 
)

Definition at line 191 of file oldlist.cpp.

191  {
192  ASSERT_HOST(destructor != nullptr);
193 
194  while (list != NIL_LIST) {
195  if (first_node(list) != NULL) (*destructor)(first_node(list));
196  list = pop(list);
197  }
198 }
LIST pop(LIST list)
Definition: oldlist.cpp:271
#define NIL_LIST
Definition: oldlist.h:126
#define ASSERT_HOST(x)
Definition: errcode.h:84
#define first_node(l)
Definition: oldlist.h:139

◆ insert()

void insert ( LIST  list,
void *  node 
)

Definition at line 206 of file oldlist.cpp.

206  {
207  LIST element;
208 
209  if (list != NIL_LIST) {
210  element = push(NIL_LIST, node);
211  set_rest(element, list_rest(list));
212  set_rest(list, element);
213  node = first_node(list);
214  list->node = first_node(list_rest(list));
215  list->next->node = (LIST)node;
216  }
217 }
LIST push(LIST list, void *element)
Definition: oldlist.cpp:288
#define list_rest(l)
Definition: oldlist.h:138
list_rec * LIST
Definition: oldlist.h:132
#define set_rest(l, cell)
Definition: oldlist.h:222
#define NIL_LIST
Definition: oldlist.h:126
#define first_node(l)
Definition: oldlist.h:139
struct list_rec * next
Definition: oldlist.h:130
struct list_rec * node
Definition: oldlist.h:129

◆ is_same()

int is_same ( void *  item1,
void *  item2 
)

Definition at line 225 of file oldlist.cpp.

225  {
226  return strcmp((char *)item1, (char *)item2) == 0 ? 1 : 0;
227 }

◆ join()

LIST join ( LIST  list1,
LIST  list2 
)

Definition at line 236 of file oldlist.cpp.

236  {
237  if (list1 == NIL_LIST) return (list2);
238  set_rest(last(list1), list2);
239  return (list1);
240 }
LIST last(LIST var_list)
Definition: oldlist.cpp:247
#define set_rest(l, cell)
Definition: oldlist.h:222
#define NIL_LIST
Definition: oldlist.h:126

◆ last()

LIST last ( LIST  var_list)

Definition at line 247 of file oldlist.cpp.

247  {
248  while (list_rest(var_list) != NIL_LIST) var_list = list_rest(var_list);
249  return (var_list);
250 }
#define list_rest(l)
Definition: oldlist.h:138
#define NIL_LIST
Definition: oldlist.h:126

◆ nth_cell()

void* nth_cell ( LIST  var_list,
int  item_num 
)

Definition at line 257 of file oldlist.cpp.

257  {
258  int x = 0;
259  iterate(var_list) {
260  if (x++ == item_num) return (var_list);
261  }
262  return (var_list);
263 }
#define iterate(l)
Definition: oldlist.h:159

◆ pop()

LIST pop ( LIST  list)

Definition at line 271 of file oldlist.cpp.

271  {
272  LIST temp;
273 
274  temp = list_rest(list);
275 
276  if (list != NIL_LIST) {
277  free_cell(list);
278  }
279  return (temp);
280 }
#define list_rest(l)
Definition: oldlist.h:138
void free_cell(LIST)
#define NIL_LIST
Definition: oldlist.h:126

◆ push()

LIST push ( LIST  list,
void *  element 
)

Definition at line 288 of file oldlist.cpp.

288  {
289  LIST t;
290 
291  t = new_cell();
292  t->node = (LIST)element;
293  set_rest(t, list);
294  return (t);
295 }
LIST new_cell()
list_rec * LIST
Definition: oldlist.h:132
#define set_rest(l, cell)
Definition: oldlist.h:222
struct list_rec * node
Definition: oldlist.h:129

◆ push_last()

LIST push_last ( LIST  list,
void *  item 
)

Definition at line 302 of file oldlist.cpp.

302  {
303  LIST t;
304 
305  if (list != NIL_LIST) {
306  t = last(list);
307  t->next = push(NIL_LIST, item);
308  return (list);
309  } else
310  return (push(NIL_LIST, item));
311 }
LIST push(LIST list, void *element)
Definition: oldlist.cpp:288
LIST last(LIST var_list)
Definition: oldlist.cpp:247
#define NIL_LIST
Definition: oldlist.h:126
struct list_rec * next
Definition: oldlist.h:130

◆ reverse()

LIST reverse ( LIST  list)

Definition at line 319 of file oldlist.cpp.

319  {
320  LIST newlist = NIL_LIST;
321 
322  iterate(list) copy_first(list, newlist);
323  return (newlist);
324 }
#define copy_first(l1, l2)
Definition: oldlist.h:149
#define NIL_LIST
Definition: oldlist.h:126
#define iterate(l)
Definition: oldlist.h:159

◆ reverse_d()

LIST reverse_d ( LIST  list)

Definition at line 332 of file oldlist.cpp.

332  {
333  LIST result = reverse(list);
334  destroy(list);
335  return (result);
336 }
LIST destroy(LIST list)
Definition: oldlist.cpp:175
LIST reverse(LIST list)
Definition: oldlist.cpp:319

◆ s_adjoin()

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

Definition at line 344 of file oldlist.cpp.

344  {
345  LIST l;
346  int result;
347 
348  if (compare == NULL) compare = (int_compare)strcmp;
349 
350  l = var_list;
351  iterate(l) {
352  result = (*compare)(variable, first_node(l));
353  if (result == 0)
354  return (var_list);
355  else if (result < 0) {
356  insert(l, variable);
357  return (var_list);
358  }
359  }
360  return (push_last(var_list, variable));
361 }
int(* int_compare)(void *, void *)
Definition: cutil.h:71
LIST push_last(LIST list, void *item)
Definition: oldlist.cpp:302
void insert(LIST list, void *node)
Definition: oldlist.cpp:206
#define first_node(l)
Definition: oldlist.h:139
#define iterate(l)
Definition: oldlist.h:159

◆ search() [1/2]

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

Definition at line 371 of file oldlist.cpp.

371  {
372  if (is_equal == NULL) is_equal = is_same;
373 
374  iterate(list) if ((*is_equal)(first_node(list), key)) return (list);
375  return (NIL_LIST);
376 }
int is_same(void *item1, void *item2)
Definition: oldlist.cpp:225
#define is_equal(p1, p2)
Definition: outlines.h:109
#define NIL_LIST
Definition: oldlist.h:126
#define first_node(l)
Definition: oldlist.h:139
#define iterate(l)
Definition: oldlist.h:159

◆ search() [2/2]

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

Definition at line 378 of file oldlist.cpp.

379  {
380  iterate(list) if ((*is_equal).Run(first_node(list), key)) return (list);
381  return (NIL_LIST);
382 }
#define NIL_LIST
Definition: oldlist.h:126
#define first_node(l)
Definition: oldlist.h:139
#define iterate(l)
Definition: oldlist.h:159