tesseract  4.1.1
oldlist.cpp File Reference
#include "oldlist.h"
#include <cstdio>
#include <cstring>
#include "errcode.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

◆ copy_first

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

Definition at line 71 of file oldlist.cpp.

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 }
#define set_rest(l, cell)
Definition: oldlist.h:111
#define list_rest(l)
Definition: oldlist.h:91
#define NIL_LIST
Definition: oldlist.h:76
LIST pop(LIST list)
Definition: oldlist.cpp:201
#define first_node(l)
Definition: oldlist.h:92
#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 }
#define list_rest(l)
Definition: oldlist.h:91
#define NIL_LIST
Definition: oldlist.h:76

◆ 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 NIL_LIST
Definition: oldlist.h:76
LIST pop(LIST list)
Definition: oldlist.cpp:201
#define first_node(l)
Definition: oldlist.h:92
#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_rec * next
Definition: oldlist.h:83
list_rec * node
Definition: oldlist.h:82
LIST push(LIST list, void *element)
Definition: oldlist.cpp:213
#define set_rest(l, cell)
Definition: oldlist.h:111
#define list_rest(l)
Definition: oldlist.h:91
#define NIL_LIST
Definition: oldlist.h:76
#define first_node(l)
Definition: oldlist.h:92
list_rec * LIST
Definition: oldlist.h:85

◆ 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 }
#define list_rest(l)
Definition: oldlist.h:91
#define NIL_LIST
Definition: oldlist.h:76

◆ 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 }
#define list_rest(l)
Definition: oldlist.h:91

◆ 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 }
list_rec * node
Definition: oldlist.h:82
#define set_rest(l, cell)
Definition: oldlist.h:111

◆ 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_rec * next
Definition: oldlist.h:83
LIST push(LIST list, void *element)
Definition: oldlist.cpp:213
LIST last(LIST var_list)
Definition: oldlist.cpp:190
#define NIL_LIST
Definition: oldlist.h:76

◆ 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 iterate(l)
Definition: oldlist.h:101
#define copy_first(l1, l2)
Definition: oldlist.cpp:71
#define NIL_LIST
Definition: oldlist.h:76

◆ 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 }
#define iterate(l)
Definition: oldlist.h:101
#define NIL_LIST
Definition: oldlist.h:76
#define first_node(l)
Definition: oldlist.h:92
#define is_equal(p1, p2)
Definition: outlines.h:105