tesseract  4.1.0
oldlist.cpp File Reference
#include "oldlist.h"
#include <cstdio>
#include <cstring>
#include "errcode.h"
#include "structures.h"

Go to the source code of this file.

Macros

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

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

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

Definition at line 72 of file oldlist.cpp.

Function Documentation

int count ( LIST  var_list)

Definition at line 96 of file oldlist.cpp.

96  {
97  int temp = 0;
98 
99  iterate(var_list) temp += 1;
100  return (temp);
101 }
#define iterate(l)
Definition: oldlist.h:101
LIST delete_d ( LIST  list,
void *  key,
int_compare  is_equal 
)

Definition at line 111 of file oldlist.cpp.

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

Definition at line 142 of file oldlist.cpp.

142  {
143  LIST next;
144 
145  while (list != NIL_LIST) {
146  next = list_rest(list);
147  free_cell(list);
148  list = next;
149  }
150  return (NIL_LIST);
151 }
#define list_rest(l)
Definition: oldlist.h:91
#define NIL_LIST
Definition: oldlist.h:76
void free_cell(LIST)
void destroy_nodes ( LIST  list,
void_dest  destructor 
)

Definition at line 158 of file oldlist.cpp.

158  {
159  ASSERT_HOST(destructor != nullptr);
160 
161  while (list != NIL_LIST) {
162  if (first_node(list) != nullptr) (*destructor)(first_node(list));
163  list = pop(list);
164  }
165 }
#define NIL_LIST
Definition: oldlist.h:76
#define first_node(l)
Definition: oldlist.h:92
#define ASSERT_HOST(x)
Definition: errcode.h:88
LIST pop(LIST list)
Definition: oldlist.cpp:202
void insert ( LIST  list,
void *  node 
)

Definition at line 173 of file oldlist.cpp.

173  {
174  LIST element;
175 
176  if (list != NIL_LIST) {
177  element = push(NIL_LIST, node);
178  set_rest(element, list_rest(list));
179  set_rest(list, element);
180  node = first_node(list);
181  list->node = first_node(list_rest(list));
182  list->next->node = (LIST)node;
183  }
184 }
#define set_rest(l, cell)
Definition: oldlist.h:120
list_rec * LIST
Definition: oldlist.h:85
LIST push(LIST list, void *element)
Definition: oldlist.cpp:219
#define list_rest(l)
Definition: oldlist.h:91
#define NIL_LIST
Definition: oldlist.h:76
struct list_rec * node
Definition: oldlist.h:82
#define first_node(l)
Definition: oldlist.h:92
struct list_rec * next
Definition: oldlist.h:83
LIST last ( LIST  var_list)

Definition at line 191 of file oldlist.cpp.

191  {
192  while (list_rest(var_list) != NIL_LIST) var_list = list_rest(var_list);
193  return (var_list);
194 }
#define list_rest(l)
Definition: oldlist.h:91
#define NIL_LIST
Definition: oldlist.h:76
LIST pop ( LIST  list)

Definition at line 202 of file oldlist.cpp.

202  {
203  LIST temp;
204 
205  temp = list_rest(list);
206 
207  if (list != NIL_LIST) {
208  free_cell(list);
209  }
210  return (temp);
211 }
#define list_rest(l)
Definition: oldlist.h:91
#define NIL_LIST
Definition: oldlist.h:76
void free_cell(LIST)
LIST push ( LIST  list,
void *  element 
)

Definition at line 219 of file oldlist.cpp.

219  {
220  LIST t;
221 
222  t = new_cell();
223  t->node = static_cast<LIST>(element);
224  set_rest(t, list);
225  return (t);
226 }
#define set_rest(l, cell)
Definition: oldlist.h:120
LIST new_cell()
struct list_rec * node
Definition: oldlist.h:82
LIST push_last ( LIST  list,
void *  item 
)

Definition at line 233 of file oldlist.cpp.

233  {
234  LIST t;
235 
236  if (list != NIL_LIST) {
237  t = last(list);
238  t->next = push(NIL_LIST, item);
239  return (list);
240  } else
241  return (push(NIL_LIST, item));
242 }
LIST last(LIST var_list)
Definition: oldlist.cpp:191
LIST push(LIST list, void *element)
Definition: oldlist.cpp:219
#define NIL_LIST
Definition: oldlist.h:76
struct list_rec * next
Definition: oldlist.h:83
LIST reverse ( LIST  list)

Definition at line 250 of file oldlist.cpp.

250  {
251  LIST newlist = NIL_LIST;
252 
253  iterate(list) copy_first(list, newlist);
254  return (newlist);
255 }
#define NIL_LIST
Definition: oldlist.h:76
#define copy_first(l1, l2)
Definition: oldlist.cpp:72
#define iterate(l)
Definition: oldlist.h:101
LIST search ( LIST  list,
void *  key,
int_compare  is_equal 
)

Definition at line 264 of file oldlist.cpp.

264  {
265  if (is_equal == nullptr) is_equal = is_same;
266 
267  iterate(list) if ((*is_equal)(first_node(list), key)) return (list);
268  return (NIL_LIST);
269 }
#define is_equal(p1, p2)
Definition: outlines.h:105
#define NIL_LIST
Definition: oldlist.h:76
#define first_node(l)
Definition: oldlist.h:92
#define iterate(l)
Definition: oldlist.h:101