tesseract  5.0.0-alpha-619-ge9db
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 82 of file elst2.h.

Constructor & Destructor Documentation

◆ ELIST2()

ELIST2::ELIST2 ( )
inline

Definition at line 96 of file elst2.h.

96  :
97  ELIST2() { //constructor
98  last = nullptr;

Member Function Documentation

◆ add_sorted()

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

Definition at line 139 of file elst2.cpp.

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

◆ assign_to_sublist()

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

Definition at line 68 of file elst2.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 ())
78  LIST_NOT_EMPTY.error ("ELIST2.assign_to_sublist", ABORT, nullptr);

◆ empty()

bool ELIST2::empty ( ) const
inline

Definition at line 104 of file elst2.h.

105  { //is list empty?
106  return !last;

◆ internal_clear()

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

Definition at line 38 of file elst2.cpp.

41  {
42  //ptr to zapper functn
43  ELIST2_LINK *ptr;
44  ELIST2_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;
54  }

◆ 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 85 of file elst2.cpp.

89  { // count elements
90  ELIST2_ITERATOR it(const_cast<ELIST2*>(this));
91  int32_t count = 0;
92 

◆ shallow_copy()

void ELIST2::shallow_copy ( ELIST2 from_list)
inline

Definition at line 112 of file elst2.h.

114  { //beware destructors!!
115  last = from_list->last;

◆ singleton()

bool ELIST2::singleton ( ) const
inline

Definition at line 108 of file elst2.h.

109  {
110  return last ? (last == last->next) : false;

◆ sort()

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

Definition at line 102 of file elst2.cpp.

102  :
103  * (int (*)(const void *, const void *)
104  **********************************************************************/
105 
106 void
107 ELIST2::sort ( //sort elements
108 int comparator ( //comparison routine
109 const void *, const void *)) {
110  ELIST2_ITERATOR it(this);
111  int32_t count;
112  ELIST2_LINK **base; //ptr array to sort
113  ELIST2_LINK **current;
114  int32_t i;
115 
116  /* Allocate an array of pointers, one per list element */
117  count = length ();
118  base = static_cast<ELIST2_LINK **>(malloc (count * sizeof (ELIST2_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;
132  for (i = 0; i < count; i++) {

Friends And Related Function Documentation

◆ ELIST2_ITERATOR

friend class ELIST2_ITERATOR
friend

Definition at line 87 of file elst2.h.


The documentation for this class was generated from the following files:
ELIST2::ELIST2
ELIST2()
Definition: elst2.h:96
list_rec::next
list_rec * next
Definition: oldlist.h:75
ERRCODE
Definition: errcode.h:67
ELIST2::sort
void sort(int comparator(const void *, const void *))
Definition: elst2.cpp:102
ELIST2::empty
bool empty() const
Definition: elst2.h:104
ELIST2::length
int32_t length() const
Definition: elst2.cpp:85
last
LIST last(LIST var_list)
Definition: oldlist.cpp:151
tesstrain_utils.int
int
Definition: tesstrain_utils.py:154
count
int count(LIST var_list)
Definition: oldlist.cpp:79
ELIST2_ITERATOR
Definition: elst2.h:144
ELIST2_LINK
Definition: elst2.h:53
ABORT
Definition: errcode.h:43