tesseract 4.1.1
Loading...
Searching...
No Matches
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 86 of file elst2.h.

Constructor & Destructor Documentation

◆ ELIST2()

ELIST2::ELIST2 ( )
inline

Definition at line 97 of file elst2.h.

97 { //constructor
98 last = nullptr;
99 }

Member Function Documentation

◆ add_sorted()

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

Definition at line 144 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())
167 it.add_to_end(new_link);
168 else
169 it.add_before_then_move(new_link);
170 }
171}

◆ assign_to_sublist()

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

Definition at line 71 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);
79
80 last = start_it->extract_sublist (end_it);
81}
@ ABORT
Definition: errcode.h:29
bool empty() const
Definition: elst2.h:105

◆ empty()

bool ELIST2::empty ( ) const
inline

Definition at line 105 of file elst2.h.

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

◆ internal_clear()

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

Definition at line 40 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 }
55 }
56}

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

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

◆ shallow_copy()

void ELIST2::shallow_copy ( ELIST2 from_list)
inline

Definition at line 113 of file elst2.h.

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

◆ singleton()

bool ELIST2::singleton ( ) const
inline

Definition at line 109 of file elst2.h.

109 {
110 return last ? (last == last->next) : false;
111 }
LIST last(LIST var_list)
Definition: oldlist.cpp:190
list_rec * next
Definition: oldlist.h:83

◆ sort()

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

Definition at line 107 of file elst2.cpp.

109 {
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++) {
133 it.add_to_end (*current);
134 current++;
135 }
136 free(base);
137}
int32_t length() const
Definition: elst2.cpp:89

Friends And Related Function Documentation

◆ ELIST2_ITERATOR

friend class ELIST2_ITERATOR
friend

Definition at line 88 of file elst2.h.


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