Tesseract
3.02
|
#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 |
void ELIST2::add_sorted | ( | int | comparatorconst void *, const void *, |
ELIST2_LINK * | new_link | ||
) |
Definition at line 169 of file elst2.cpp.
{ // Check for adding at the end. if (last == NULL || comparator(&last, &new_link) < 0) { if (last == NULL) { new_link->next = new_link; new_link->prev = new_link; } else { new_link->next = last->next; new_link->prev = last; last->next = new_link; new_link->next->prev = new_link; } last = new_link; } else { // Need to use an iterator. ELIST2_ITERATOR it(this); for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) { ELIST2_LINK* link = it.data(); if (comparator(&link, &new_link) > 0) break; } if (it.cycled_list()) it.add_to_end(new_link); else it.add_before_then_move(new_link); } }
void ELIST2::assign_to_sublist | ( | ELIST2_ITERATOR * | start_it, |
ELIST2_ITERATOR * | end_it | ||
) |
Definition at line 79 of file elst2.cpp.
{ //from list end const ERRCODE LIST_NOT_EMPTY = "Destination list must be empty before extracting a sublist"; #ifndef NDEBUG if (!this) NULL_OBJECT.error ("ELIST2::assign_to_sublist", ABORT, NULL); #endif if (!empty ()) LIST_NOT_EMPTY.error ("ELIST2.assign_to_sublist", ABORT, NULL); last = start_it->extract_sublist (end_it); }
bool ELIST2::empty | ( | ) | const [inline] |
void ELIST2::internal_clear | ( | void(*)(ELIST2_LINK *) | zapper | ) |
Definition at line 43 of file elst2.cpp.
{ //ptr to zapper functn ELIST2_LINK *ptr; ELIST2_LINK *next; #ifndef NDEBUG if (!this) NULL_OBJECT.error ("ELIST2::internal_clear", ABORT, NULL); #endif if (!empty ()) { ptr = last->next; //set to first last->next = NULL; //break circle last = NULL; //set list empty while (ptr) { next = ptr->next; zapper(ptr); ptr = next; } } }
void ELIST2::internal_deep_copy | ( | ELIST2_LINK *(*)(ELIST2_LINK *) | copier, |
const ELIST2 * | list | ||
) |
inT32 ELIST2::length | ( | ) | const |
Definition at line 103 of file elst2.cpp.
{ // count elements ELIST2_ITERATOR it(const_cast<ELIST2*>(this)); inT32 count = 0; #ifndef NDEBUG if (!this) NULL_OBJECT.error ("ELIST2::length", ABORT, NULL); #endif for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) count++; return count; }
void ELIST2::shallow_copy | ( | ELIST2 * | from_list | ) | [inline] |
bool ELIST2::singleton | ( | ) | const [inline] |
void ELIST2::sort | ( | int | comparatorconst void *, const void * | ) |
Definition at line 127 of file elst2.cpp.
{ ELIST2_ITERATOR it(this); inT32 count; ELIST2_LINK **base; //ptr array to sort ELIST2_LINK **current; inT32 i; #ifndef NDEBUG if (!this) NULL_OBJECT.error ("ELIST2::sort", ABORT, NULL); #endif /* Allocate an array of pointers, one per list element */ count = length (); base = (ELIST2_LINK **) malloc (count * sizeof (ELIST2_LINK *)); /* Extract all elements, putting the pointers in the array */ current = base; for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) { *current = it.extract (); current++; } /* Sort the pointer array */ qsort ((char *) base, count, sizeof (*base), comparator); /* Rebuild the list from the sorted pointers */ current = base; for (i = 0; i < count; i++) { it.add_to_end (*current); current++; } free(base); }
friend class ELIST2_ITERATOR [friend] |