tesseract  5.0.0-alpha-619-ge9db
ELIST Class Reference

#include <elst.h>

Public Member Functions

 ELIST ()
 
void internal_clear (void(*zapper)(ELIST_LINK *))
 
bool empty () const
 
bool singleton () const
 
void shallow_copy (ELIST *from_list)
 
void internal_deep_copy (ELIST_LINK *(*copier)(ELIST_LINK *), const ELIST *list)
 
void assign_to_sublist (ELIST_ITERATOR *start_it, ELIST_ITERATOR *end_it)
 
int32_t length () const
 
void sort (int comparator(const void *, const void *))
 
ELIST_LINKadd_sorted_and_find (int comparator(const void *, const void *), bool unique, ELIST_LINK *new_link)
 
bool add_sorted (int comparator(const void *, const void *), bool unique, ELIST_LINK *new_link)
 

Friends

class ELIST_ITERATOR
 

Detailed Description

Definition at line 102 of file elst.h.

Constructor & Destructor Documentation

◆ ELIST()

ELIST::ELIST ( )
inline

Definition at line 116 of file elst.h.

116  :
117  ELIST() { //constructor
118  last = nullptr;

Member Function Documentation

◆ add_sorted()

bool ELIST::add_sorted ( int   comparatorconst void *, const void *,
bool  unique,
ELIST_LINK new_link 
)
inline

Definition at line 166 of file elst.h.

168  {
169  return (add_sorted_and_find(comparator, unique, new_link) == new_link);

◆ add_sorted_and_find()

ELIST_LINK * ELIST::add_sorted_and_find ( int   comparatorconst void *, const void *,
bool  unique,
ELIST_LINK new_link 
)

Definition at line 143 of file elst.cpp.

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

◆ assign_to_sublist()

void ELIST::assign_to_sublist ( ELIST_ITERATOR start_it,
ELIST_ITERATOR end_it 
)

Definition at line 67 of file elst.cpp.

73  { //from list end
74  constexpr ERRCODE LIST_NOT_EMPTY(
75  "Destination list must be empty before extracting a sublist");
76 
77  if (!empty ())

◆ empty()

bool ELIST::empty ( ) const
inline

Definition at line 124 of file elst.h.

125  { //is list empty?
126  return !last;

◆ internal_clear()

void ELIST::internal_clear ( void(*)(ELIST_LINK *)  zapper)

Definition at line 37 of file elst.cpp.

41  {
42  //ptr to zapper functn
43  ELIST_LINK *ptr;
44  ELIST_LINK *next;
45 
46  if (!empty ()) {
47  ptr = last->next; //set to first
48  last->next = nullptr; //break circle
49  last = nullptr; //set list empty
50  while (ptr) {
51  next = ptr->next;
52  zapper(ptr);
53  ptr = next;

◆ internal_deep_copy()

void ELIST::internal_deep_copy ( ELIST_LINK *(*)(ELIST_LINK *)  copier,
const ELIST list 
)

◆ length()

int32_t ELIST::length ( ) const

Definition at line 84 of file elst.cpp.

89  { // count elements
90  ELIST_ITERATOR it(const_cast<ELIST*>(this));
91  int32_t count = 0;

◆ shallow_copy()

void ELIST::shallow_copy ( ELIST from_list)
inline

Definition at line 132 of file elst.h.

134  { //beware destructors!!
135  last = from_list->last;

◆ singleton()

bool ELIST::singleton ( ) const
inline

Definition at line 128 of file elst.h.

129  {
130  return last ? (last == last->next) : false;

◆ sort()

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

Definition at line 101 of file elst.cpp.

102  :
103  * ( int (*)(const void *, const void *)
104  **********************************************************************/
105 
106 void
107 ELIST::sort ( //sort elements
108 int comparator ( //comparison routine
109 const void *, const void *)) {
110  ELIST_ITERATOR it(this);
111  int32_t count;
112  ELIST_LINK **base; //ptr array to sort
113  ELIST_LINK **current;
114  int32_t i;
115 
116  /* Allocate an array of pointers, one per list element */
117  count = length ();
118  base = static_cast<ELIST_LINK **>(malloc (count * sizeof (ELIST_LINK *)));
119 
120  /* Extract all elements, putting the pointers in the array */
121  current = base;
122  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
123  *current = it.extract ();
124  current++;
125  }
126 
127  /* Sort the pointer array */
128  qsort(base, count, sizeof(*base), comparator);
129 
130  /* Rebuild the list from the sorted pointers */
131  current = base;

Friends And Related Function Documentation

◆ ELIST_ITERATOR

friend class ELIST_ITERATOR
friend

Definition at line 107 of file elst.h.


The documentation for this class was generated from the following files:
list_rec::next
list_rec * next
Definition: oldlist.h:75
ELIST_ITERATOR
Definition: elst.h:175
ERRCODE
Definition: errcode.h:67
ELIST::length
int32_t length() const
Definition: elst.cpp:84
ELIST::sort
void sort(int comparator(const void *, const void *))
Definition: elst.cpp:101
last
LIST last(LIST var_list)
Definition: oldlist.cpp:151
tesstrain_utils.int
int
Definition: tesstrain_utils.py:154
ELIST::add_sorted_and_find
ELIST_LINK * add_sorted_and_find(int comparator(const void *, const void *), bool unique, ELIST_LINK *new_link)
Definition: elst.cpp:143
count
int count(LIST var_list)
Definition: oldlist.cpp:79
ELIST::ELIST
ELIST()
Definition: elst.h:116
ELIST_LINK
Definition: elst.h:74
ELIST::empty
bool empty() const
Definition: elst.h:124