tesseract  3.04.01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 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 113 of file elst.h.

Constructor & Destructor Documentation

ELIST::ELIST ( )
inline

Definition at line 124 of file elst.h.

124  { //constructor
125  last = NULL;
126  }

Member Function Documentation

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

Definition at line 174 of file elst.h.

175  {
176  return (add_sorted_and_find(comparator, unique, new_link) == new_link);
177  }
ELIST_LINK * add_sorted_and_find(int comparator(const void *, const void *), bool unique, ELIST_LINK *new_link)
Definition: elst.cpp:152
ELIST_LINK * ELIST::add_sorted_and_find ( int   comparatorconst void *, const void *,
bool  unique,
ELIST_LINK new_link 
)

Definition at line 152 of file elst.cpp.

154  {
155  // Check for adding at the end.
156  if (last == NULL || comparator(&last, &new_link) < 0) {
157  if (last == NULL) {
158  new_link->next = new_link;
159  } else {
160  new_link->next = last->next;
161  last->next = new_link;
162  }
163  last = new_link;
164  } else {
165  // Need to use an iterator.
166  ELIST_ITERATOR it(this);
167  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
168  ELIST_LINK* link = it.data();
169  int compare = comparator(&link, &new_link);
170  if (compare > 0) {
171  break;
172  } else if (unique && compare == 0) {
173  return link;
174  }
175  }
176  if (it.cycled_list())
177  it.add_to_end(new_link);
178  else
179  it.add_before_then_move(new_link);
180  }
181  return new_link;
182 }
void ELIST::assign_to_sublist ( ELIST_ITERATOR start_it,
ELIST_ITERATOR end_it 
)

Definition at line 72 of file elst.cpp.

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

Definition at line 132 of file elst.h.

132  { //is list empty?
133  return !last;
134  }
void ELIST::internal_clear ( void(*)(ELIST_LINK *)  zapper)

Definition at line 41 of file elst.cpp.

42  {
43  //ptr to zapper functn
44  ELIST_LINK *ptr;
45  ELIST_LINK *next;
46 
47  if (!empty ()) {
48  ptr = last->next; //set to first
49  last->next = NULL; //break circle
50  last = NULL; //set list empty
51  while (ptr) {
52  next = ptr->next;
53  zapper(ptr);
54  ptr = next;
55  }
56  }
57 }
bool empty() const
Definition: elst.h:132
void ELIST::internal_deep_copy ( ELIST_LINK *(*)(ELIST_LINK *)  copier,
const ELIST list 
)
inT32 ELIST::length ( ) const

Definition at line 91 of file elst.cpp.

91  { // count elements
92  ELIST_ITERATOR it(const_cast<ELIST*>(this));
93  inT32 count = 0;
94 
95  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
96  count++;
97  return count;
98 }
int inT32
Definition: host.h:102
int count(LIST var_list)
Definition: oldlist.cpp:108
void ELIST::shallow_copy ( ELIST from_list)
inline

Definition at line 140 of file elst.h.

141  { //beware destructors!!
142  last = from_list->last;
143  }
bool ELIST::singleton ( ) const
inline

Definition at line 136 of file elst.h.

136  {
137  return last ? (last == last->next) : false;
138  }
void ELIST::sort ( int   comparatorconst void *, const void *)

Definition at line 110 of file elst.cpp.

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

Friends And Related Function Documentation

friend class ELIST_ITERATOR
friend

Definition at line 115 of file elst.h.


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