38 void (*zapper)(
void *)) {
71 constexpr ERRCODE LIST_NOT_EMPTY(
"Destination list must be empty before extracting a sublist");
74 LIST_NOT_EMPTY.
error(
"ELIST2.assign_to_sublist",
ABORT);
77 last = start_it->extract_sublist(end_it);
90 const void *,
const void *)) {
95 std::vector<ELIST2_LINK *> base;
106 qsort(&base[0],
count,
sizeof(base[0]), comparator);
109 for (
auto current : base) {
122 if (last ==
nullptr || comparator(&last, &new_link) < 0) {
123 if (last ==
nullptr) {
124 new_link->next = new_link;
125 new_link->prev = new_link;
127 new_link->next = last->next;
128 new_link->prev = last;
129 last->next = new_link;
130 new_link->next->prev = new_link;
138 if (comparator(&link, &new_link) > 0) {
174 started_cycling =
true;
176 current = current->next;
178 if (ex_current_was_cycle_pt) {
189 next = current->next;
194 "This is: %p Current is: %p",
195 static_cast<void *
>(
this),
196 static_cast<void *
>(current));
222 started_cycling =
true;
224 current = current->prev;
226 if (ex_current_was_cycle_pt) {
237 "This is: %p Current is: %p",
238 static_cast<void *
>(
this),
239 static_cast<void *
>(current));
243 prev = current->prev;
266 for (ptr = current ? current : next; offset++ < 0; ptr = ptr->prev) {
270 for (ptr = current ? current : prev; offset-- > 0; ptr = ptr->next) {
295 constexpr ERRCODE DONT_EXCHANGE_DELETED(
"Can't exchange deleted elements of lists");
304 if (!(other_it->list))
311 if ((list->
empty()) || (other_it->list->
empty()) || (current == other_it->current)) {
317 if (!current || !other_it->current) {
318 DONT_EXCHANGE_DELETED.
error(
"ELIST2_ITERATOR.exchange",
ABORT);
326 if ((next == other_it->current) || (other_it->next == current)) {
328 if ((next == other_it->current) && (other_it->next == current)) {
329 prev = next = current;
330 other_it->prev = other_it->next = other_it->current;
334 if (other_it->next == current) {
335 other_it->prev->next = current;
336 other_it->current->next = next;
337 other_it->current->prev = current;
338 current->next = other_it->current;
339 current->prev = other_it->prev;
340 next->prev = other_it->current;
342 other_it->next = other_it->current;
345 prev->next = other_it->current;
346 current->next = other_it->next;
347 current->prev = other_it->current;
348 other_it->current->next = current;
349 other_it->current->prev = prev;
350 other_it->next->prev = current;
353 other_it->prev = other_it->current;
357 prev->next = other_it->current;
358 current->next = other_it->next;
359 current->prev = other_it->prev;
360 next->prev = other_it->current;
361 other_it->prev->next = current;
362 other_it->current->next = next;
363 other_it->current->prev = prev;
364 other_it->next->prev = current;
370 if (list->last == current) {
371 list->last = other_it->current;
373 if (other_it->list->last == other_it->current) {
374 other_it->list->last = current;
377 if (current == cycle_pt) {
378 cycle_pt = other_it->cycle_pt;
380 if (other_it->current == other_it->cycle_pt) {
381 other_it->cycle_pt = cycle_pt;
386 old_current = current;
387 current = other_it->current;
388 other_it->current = old_current;
404 constexpr ERRCODE BAD_EXTRACTION_PTS(
"Can't extract sublist from points on different lists");
405 constexpr ERRCODE DONT_EXTRACT_DELETED(
"Can't extract a sublist marked by deleted points");
407 constexpr ERRCODE BAD_SUBLIST(
"Can't find sublist end point in original list");
417 if (list != other_it->list)
418 BAD_EXTRACTION_PTS.error(
"ELIST2_ITERATOR.extract_sublist",
ABORT);
422 if (!current || !other_it->current)
423 DONT_EXTRACT_DELETED.error(
"ELIST2_ITERATOR.extract_sublist",
ABORT);
426 ex_current_was_last = other_it->ex_current_was_last =
false;
427 ex_current_was_cycle_pt =
false;
428 other_it->ex_current_was_cycle_pt =
false;
433 BAD_SUBLIST.error(
"ELIST2_ITERATOR.extract_sublist",
ABORT);
438 ex_current_was_last = other_it->ex_current_was_last =
true;
441 if (temp_it.current == cycle_pt) {
442 ex_current_was_cycle_pt =
true;
445 if (temp_it.current == other_it->cycle_pt) {
446 other_it->ex_current_was_cycle_pt =
true;
452 while (temp_it.prev != other_it->current);
455 other_it->current->next = current;
457 current->prev = other_it->current;
458 end_of_new_list = other_it->current;
461 if (prev == other_it->current) {
462 list->last =
nullptr;
463 prev = current = next =
nullptr;
464 other_it->prev = other_it->current = other_it->next =
nullptr;
466 prev->next = other_it->next;
467 other_it->next->prev = prev;
469 current = other_it->current =
nullptr;
470 next = other_it->next;
471 other_it->prev = prev;
473 return end_of_new_list;
constexpr ERRCODE BAD_PARAMETER("List parameter error")
constexpr ERRCODE NULL_PREV("Previous element on the list is nullptr")
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(ELIST2_ITERATOR *start_it, ELIST2_ITERATOR *end_it)
void internal_clear(void(*zapper)(void *))
void add_sorted(int comparator(const void *, const void *), ELIST2_LINK *new_link)
void exchange(ELIST2_ITERATOR *other_it)
void add_before_then_move(ELIST2_LINK *new_link)
void add_to_end(ELIST2_LINK *new_link)
ELIST2_LINK * data_relative(int8_t offset)
void error(const char *caller, TessErrorLogCode action, const char *format,...) const __attribute__((format(gnu_printf