37 void (*zapper)(
void *)) {
70 constexpr
ERRCODE LIST_NOT_EMPTY(
"Destination list must be empty before extracting a sublist");
73 LIST_NOT_EMPTY.error(
"ELIST.assign_to_sublist",
ABORT,
nullptr);
76 last = start_it->extract_sublist(end_it);
89 const void *,
const void *)) {
95 std::vector<ELIST_LINK *> base;
106 qsort(&base[0], count,
sizeof(base[0]), comparator);
109 for (
auto current : base) {
128 if (last ==
nullptr || comparator(&last, &new_link) < 0) {
129 if (last ==
nullptr) {
130 new_link->next = new_link;
132 new_link->next = last->next;
133 last->next = new_link;
141 int compare = comparator(&link, &new_link);
144 }
else if (unique && compare == 0) {
181 started_cycling =
true;
183 current = current->next;
185 if (ex_current_was_cycle_pt) {
194 next = current->next;
198 NULL_NEXT.
error(
"ELIST_ITERATOR::forward",
ABORT,
"This is: %p Current is: %p",
this, current);
227 for (ptr = current ? current : prev; offset-- > 0; ptr = ptr->next) {
254 while (current != list->last) {
273 constexpr
ERRCODE DONT_EXCHANGE_DELETED(
"Can't exchange deleted elements of lists");
282 if (!(other_it->list))
289 if ((list->
empty()) || (other_it->list->
empty()) || (current == other_it->current)) {
295 if (!current || !other_it->current) {
296 DONT_EXCHANGE_DELETED.error(
"ELIST_ITERATOR.exchange",
ABORT,
nullptr);
304 if ((next == other_it->current) || (other_it->next == current)) {
306 if ((next == other_it->current) && (other_it->next == current)) {
307 prev = next = current;
308 other_it->prev = other_it->next = other_it->current;
312 if (other_it->next == current) {
313 other_it->prev->next = current;
314 other_it->current->next = next;
315 current->next = other_it->current;
316 other_it->next = other_it->current;
319 prev->next = other_it->current;
320 current->next = other_it->next;
321 other_it->current->next = current;
323 other_it->prev = other_it->current;
327 prev->next = other_it->current;
328 current->next = other_it->next;
329 other_it->prev->next = current;
330 other_it->current->next = next;
336 if (list->last == current) {
337 list->last = other_it->current;
339 if (other_it->list->last == other_it->current) {
340 other_it->list->last = current;
343 if (current == cycle_pt) {
344 cycle_pt = other_it->cycle_pt;
346 if (other_it->current == other_it->cycle_pt) {
347 other_it->cycle_pt = cycle_pt;
352 old_current = current;
353 current = other_it->current;
354 other_it->current = old_current;
370 constexpr
ERRCODE BAD_EXTRACTION_PTS(
"Can't extract sublist from points on different lists");
371 constexpr
ERRCODE DONT_EXTRACT_DELETED(
"Can't extract a sublist marked by deleted points");
373 constexpr
ERRCODE BAD_SUBLIST(
"Can't find sublist end point in original list");
383 if (list != other_it->list)
384 BAD_EXTRACTION_PTS.error(
"ELIST_ITERATOR.extract_sublist",
ABORT,
nullptr);
388 if (!current || !other_it->current)
389 DONT_EXTRACT_DELETED.error(
"ELIST_ITERATOR.extract_sublist",
ABORT,
nullptr);
392 ex_current_was_last = other_it->ex_current_was_last =
false;
393 ex_current_was_cycle_pt =
false;
394 other_it->ex_current_was_cycle_pt =
false;
399 BAD_SUBLIST.error(
"ELIST_ITERATOR.extract_sublist",
ABORT,
nullptr);
404 ex_current_was_last = other_it->ex_current_was_last =
true;
407 if (temp_it.current == cycle_pt) {
408 ex_current_was_cycle_pt =
true;
411 if (temp_it.current == other_it->cycle_pt) {
412 other_it->ex_current_was_cycle_pt =
true;
416 }
while (temp_it.prev != other_it->current);
419 other_it->current->next = current;
420 end_of_new_list = other_it->current;
423 if (prev == other_it->current) {
424 list->last =
nullptr;
425 prev = current = next =
nullptr;
426 other_it->prev = other_it->current = other_it->next =
nullptr;
428 prev->next = other_it->next;
429 current = other_it->current =
nullptr;
430 next = other_it->next;
431 other_it->prev = prev;
433 return end_of_new_list;
constexpr ERRCODE BAD_PARAMETER("List parameter error")
constexpr ERRCODE NO_LIST("Iterator not set to a list")
constexpr ERRCODE NULL_NEXT("Next element on the list is nullptr")
constexpr ERRCODE EMPTY_LIST("List is empty")
constexpr ERRCODE NULL_DATA("List would have returned a nullptr data pointer")
void sort(int comparator(const void *, const void *))
void assign_to_sublist(ELIST_ITERATOR *start_it, ELIST_ITERATOR *end_it)
ELIST_LINK * add_sorted_and_find(int comparator(const void *, const void *), bool unique, ELIST_LINK *new_link)
void internal_clear(void(*zapper)(void *))
ELIST_LINK * move_to_last()
void add_to_end(ELIST_LINK *new_link)
void exchange(ELIST_ITERATOR *other_it)
void add_before_then_move(ELIST_LINK *new_link)
ELIST_LINK * data_relative(int8_t offset)
void error(const char *caller, TessErrorLogCode action, const char *format,...) const __attribute__((format(printf