tesseract  4.0.0-1-g2a2b
ELIST2 Class Reference

#include <elst2.h>

Public Member Functions

 ELIST2 ()
 
void internal_clear (void(*zapper)(ELIST2_LINK *))
 
bool empty () const
 
bool singleton () const
 
void shallow_copy (ELIST2 *from_list)
 
void internal_deep_copy (ELIST2_LINK *(*copier)(ELIST2_LINK *), const ELIST2 *list)
 
void assign_to_sublist (ELIST2_ITERATOR *start_it, ELIST2_ITERATOR *end_it)
 
int32_t length () const
 
void sort (int comparator(const void *, const void *))
 
void add_sorted (int comparator(const void *, const void *), ELIST2_LINK *new_link)
 

Friends

class ELIST2_ITERATOR
 

Detailed Description

Definition at line 88 of file elst2.h.

Constructor & Destructor Documentation

◆ ELIST2()

ELIST2::ELIST2 ( )
inline

Definition at line 99 of file elst2.h.

99  { //constructor
100  last = nullptr;
101  }

Member Function Documentation

◆ add_sorted()

void ELIST2::add_sorted ( int   comparatorconst void *, const void *,
ELIST2_LINK new_link 
)

Definition at line 146 of file elst2.cpp.

147  {
148  // Check for adding at the end.
149  if (last == nullptr || comparator(&last, &new_link) < 0) {
150  if (last == nullptr) {
151  new_link->next = new_link;
152  new_link->prev = new_link;
153  } else {
154  new_link->next = last->next;
155  new_link->prev = last;
156  last->next = new_link;
157  new_link->next->prev = new_link;
158  }
159  last = new_link;
160  } else {
161  // Need to use an iterator.
162  ELIST2_ITERATOR it(this);
163  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
164  ELIST2_LINK* link = it.data();
165  if (comparator(&link, &new_link) > 0)
166  break;
167  }
168  if (it.cycled_list())
169  it.add_to_end(new_link);
170  else
171  it.add_before_then_move(new_link);
172  }
173 }

◆ assign_to_sublist()

void ELIST2::assign_to_sublist ( ELIST2_ITERATOR start_it,
ELIST2_ITERATOR end_it 
)

Definition at line 73 of file elst2.cpp.

75  { //from list end
76  const ERRCODE LIST_NOT_EMPTY =
77  "Destination list must be empty before extracting a sublist";
78 
79  if (!empty ())
80  LIST_NOT_EMPTY.error ("ELIST2.assign_to_sublist", ABORT, nullptr);
81 
82  last = start_it->extract_sublist (end_it);
83 }
bool empty() const
Definition: elst2.h:107
Definition: errcode.h:30
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:37

◆ empty()

bool ELIST2::empty ( ) const
inline

Definition at line 107 of file elst2.h.

107  { //is list empty?
108  return !last;
109  }

◆ internal_clear()

void ELIST2::internal_clear ( void(*)(ELIST2_LINK *)  zapper)

Definition at line 42 of file elst2.cpp.

43  {
44  //ptr to zapper functn
45  ELIST2_LINK *ptr;
46  ELIST2_LINK *next;
47 
48  if (!empty ()) {
49  ptr = last->next; //set to first
50  last->next = nullptr; //break circle
51  last = nullptr; //set list empty
52  while (ptr) {
53  next = ptr->next;
54  zapper(ptr);
55  ptr = next;
56  }
57  }
58 }
bool empty() const
Definition: elst2.h:107

◆ internal_deep_copy()

void ELIST2::internal_deep_copy ( ELIST2_LINK *(*)(ELIST2_LINK *)  copier,
const ELIST2 list 
)

◆ length()

int32_t ELIST2::length ( ) const

Definition at line 91 of file elst2.cpp.

91  { // count elements
92  ELIST2_ITERATOR it(const_cast<ELIST2*>(this));
93  int32_t count = 0;
94 
95  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
96  count++;
97  return count;
98 }
int count(LIST var_list)
Definition: oldlist.cpp:98

◆ shallow_copy()

void ELIST2::shallow_copy ( ELIST2 from_list)
inline

Definition at line 115 of file elst2.h.

116  { //beware destructors!!
117  last = from_list->last;
118  }

◆ singleton()

bool ELIST2::singleton ( ) const
inline

Definition at line 111 of file elst2.h.

111  {
112  return last ? (last == last->next) : false;
113  }
LIST last(LIST var_list)
Definition: oldlist.cpp:242
struct list_rec * next
Definition: oldlist.h:132

◆ sort()

void ELIST2::sort ( int   comparator const void *, const void *)

Definition at line 109 of file elst2.cpp.

111  {
112  ELIST2_ITERATOR it(this);
113  int32_t count;
114  ELIST2_LINK **base; //ptr array to sort
115  ELIST2_LINK **current;
116  int32_t i;
117 
118  /* Allocate an array of pointers, one per list element */
119  count = length ();
120  base = (ELIST2_LINK **) malloc (count * sizeof (ELIST2_LINK *));
121 
122  /* Extract all elements, putting the pointers in the array */
123  current = base;
124  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
125  *current = it.extract ();
126  current++;
127  }
128 
129  /* Sort the pointer array */
130  qsort(base, count, sizeof(*base), comparator);
131 
132  /* Rebuild the list from the sorted pointers */
133  current = base;
134  for (i = 0; i < count; i++) {
135  it.add_to_end (*current);
136  current++;
137  }
138  free(base);
139 }
int count(LIST var_list)
Definition: oldlist.cpp:98
int32_t length() const
Definition: elst2.cpp:91

Friends And Related Function Documentation

◆ ELIST2_ITERATOR

friend class ELIST2_ITERATOR
friend

Definition at line 90 of file elst2.h.


The documentation for this class was generated from the following files: