tesseract  3.04.01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 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 ( )
inline

Definition at line 99 of file elst2.h.

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

Member Function Documentation

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

Definition at line 148 of file elst2.cpp.

149  {
150  // Check for adding at the end.
151  if (last == NULL || comparator(&last, &new_link) < 0) {
152  if (last == NULL) {
153  new_link->next = new_link;
154  new_link->prev = new_link;
155  } else {
156  new_link->next = last->next;
157  new_link->prev = last;
158  last->next = new_link;
159  new_link->next->prev = new_link;
160  }
161  last = new_link;
162  } else {
163  // Need to use an iterator.
164  ELIST2_ITERATOR it(this);
165  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
166  ELIST2_LINK* link = it.data();
167  if (comparator(&link, &new_link) > 0)
168  break;
169  }
170  if (it.cycled_list())
171  it.add_to_end(new_link);
172  else
173  it.add_before_then_move(new_link);
174  }
175 }
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, NULL);
81 
82  last = start_it->extract_sublist (end_it);
83 }
bool empty() const
Definition: elst2.h:107
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
Definition: errcode.h:30
bool ELIST2::empty ( ) const
inline

Definition at line 107 of file elst2.h.

107  { //is list empty?
108  return !last;
109  }
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 = NULL; //break circle
51  last = NULL; //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
void ELIST2::internal_deep_copy ( ELIST2_LINK *(*)(ELIST2_LINK *)  copier,
const ELIST2 list 
)
inT32 ELIST2::length ( ) const

Definition at line 92 of file elst2.cpp.

92  { // count elements
93  ELIST2_ITERATOR it(const_cast<ELIST2*>(this));
94  inT32 count = 0;
95 
96  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
97  count++;
98  return count;
99 }
int inT32
Definition: host.h:102
int count(LIST var_list)
Definition: oldlist.cpp:108
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  }
bool ELIST2::singleton ( ) const
inline

Definition at line 111 of file elst2.h.

111  {
112  return last ? (last == last->next) : false;
113  }
void ELIST2::sort ( int   comparatorconst void *, const void *)

Definition at line 111 of file elst2.cpp.

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

Friends And Related Function Documentation

friend class ELIST2_ITERATOR
friend

Definition at line 90 of file elst2.h.


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