tesseract  5.0.0-alpha-619-ge9db
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)
 
LIST last (LIST var_list)
 
LIST pop (LIST list)
 
LIST push (LIST list, void *element)
 
LIST push_last (LIST list, void *item)
 
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 84 of file oldlist.h.

◆ iterate

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

Definition at line 92 of file oldlist.h.

◆ list_rest

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

Definition at line 83 of file oldlist.h.

◆ NIL_LIST

#define NIL_LIST   static_cast<LIST>(nullptr)

Definition at line 68 of file oldlist.h.

◆ set_rest

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

Definition at line 101 of file oldlist.h.

Typedef Documentation

◆ int_compare

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

Definition at line 70 of file oldlist.h.

◆ LIST

using LIST = list_rec*

Definition at line 77 of file oldlist.h.

◆ void_dest

using void_dest = void (*)(void*)

Definition at line 71 of file oldlist.h.

Function Documentation

◆ count()

int count ( LIST  var_list)

Definition at line 79 of file oldlist.cpp.

81  {
82  int temp = 0;
83 
84  iterate(var_list) temp += 1;

◆ delete_d()

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

Definition at line 93 of file oldlist.cpp.

96  {
97  LIST result = NIL_LIST;
98  LIST last_one = NIL_LIST;
99 
100  if (is_equal == nullptr) is_equal = is_same;
101 
102  while (list != NIL_LIST) {
103  if (!(*is_equal)(first_node(list), key)) {
104  if (last_one == NIL_LIST) {
105  last_one = list;
106  list = list_rest(list);
107  result = last_one;
108  set_rest(last_one, NIL_LIST);
109  } else {
110  set_rest(last_one, list);
111  last_one = list;
112  list = list_rest(list);
113  set_rest(last_one, NIL_LIST);
114  }
115  } else {
116  list = pop(list);
117  }

◆ destroy()

LIST destroy ( LIST  list)

Definition at line 123 of file oldlist.cpp.

127  {
128  LIST next;
129 
130  while (list != NIL_LIST) {
131  next = list_rest(list);
132  delete list;

◆ destroy_nodes()

void destroy_nodes ( LIST  list,
void_dest  destructor 
)

Definition at line 138 of file oldlist.cpp.

143  {
144  ASSERT_HOST(destructor != nullptr);
145 

◆ last()

LIST last ( LIST  var_list)

Definition at line 151 of file oldlist.cpp.

157  {

◆ pop()

LIST pop ( LIST  list)

Definition at line 161 of file oldlist.cpp.

168  {

◆ push()

LIST push ( LIST  list,
void *  element 
)

Definition at line 172 of file oldlist.cpp.

180  {

◆ push_last()

LIST push_last ( LIST  list,
void *  item 
)

Definition at line 185 of file oldlist.cpp.

194  {

◆ search()

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

Definition at line 202 of file oldlist.cpp.

212  {
first_node
#define first_node(l)
Definition: oldlist.h:84
ASSERT_HOST
#define ASSERT_HOST(x)
Definition: errcode.h:87
list_rec
Definition: oldlist.h:73
list_rest
#define list_rest(l)
Definition: oldlist.h:83
NIL_LIST
#define NIL_LIST
Definition: oldlist.h:68
is_equal
#define is_equal(p1, p2)
Definition: outlines.h:97
iterate
#define iterate(l)
Definition: oldlist.h:92
pop
LIST pop(LIST list)
Definition: oldlist.cpp:161
set_rest
#define set_rest(l, cell)
Definition: oldlist.h:101