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);
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;
199 "This is: %p Current is: %p",
200 static_cast<void *
>(
this),
201 static_cast<void *
>(current));
231 for (ptr = current ? current : prev; offset-- > 0; ptr = ptr->next) {
258 while (current != list->last) {
277 constexpr ERRCODE DONT_EXCHANGE_DELETED(
"Can't exchange deleted elements of lists");
286 if (!(other_it->list))
293 if ((list->
empty()) || (other_it->list->
empty()) || (current == other_it->current)) {
299 if (!current || !other_it->current) {
300 DONT_EXCHANGE_DELETED.
error(
"ELIST_ITERATOR.exchange",
ABORT);
308 if ((next == other_it->current) || (other_it->next == current)) {
310 if ((next == other_it->current) && (other_it->next == current)) {
311 prev = next = current;
312 other_it->prev = other_it->next = other_it->current;
316 if (other_it->next == current) {
317 other_it->prev->next = current;
318 other_it->current->next = next;
319 current->next = other_it->current;
320 other_it->next = other_it->current;
323 prev->next = other_it->current;
324 current->next = other_it->next;
325 other_it->current->next = current;
327 other_it->prev = other_it->current;
331 prev->next = other_it->current;
332 current->next = other_it->next;
333 other_it->prev->next = current;
334 other_it->current->next = next;
340 if (list->last == current) {
341 list->last = other_it->current;
343 if (other_it->list->last == other_it->current) {
344 other_it->list->last = current;
347 if (current == cycle_pt) {
348 cycle_pt = other_it->cycle_pt;
350 if (other_it->current == other_it->cycle_pt) {
351 other_it->cycle_pt = cycle_pt;
356 old_current = current;
357 current = other_it->current;
358 other_it->current = old_current;
374 constexpr ERRCODE BAD_EXTRACTION_PTS(
"Can't extract sublist from points on different lists");
375 constexpr ERRCODE DONT_EXTRACT_DELETED(
"Can't extract a sublist marked by deleted points");
377 constexpr ERRCODE BAD_SUBLIST(
"Can't find sublist end point in original list");
387 if (list != other_it->list)
388 BAD_EXTRACTION_PTS.error(
"ELIST_ITERATOR.extract_sublist",
ABORT);
392 if (!current || !other_it->current)
393 DONT_EXTRACT_DELETED.error(
"ELIST_ITERATOR.extract_sublist",
ABORT);
396 ex_current_was_last = other_it->ex_current_was_last =
false;
397 ex_current_was_cycle_pt =
false;
398 other_it->ex_current_was_cycle_pt =
false;
403 BAD_SUBLIST.error(
"ELIST_ITERATOR.extract_sublist",
ABORT);
408 ex_current_was_last = other_it->ex_current_was_last =
true;
411 if (temp_it.current == cycle_pt) {
412 ex_current_was_cycle_pt =
true;
415 if (temp_it.current == other_it->cycle_pt) {
416 other_it->ex_current_was_cycle_pt =
true;
420 }
while (temp_it.prev != other_it->current);
423 other_it->current->next = current;
424 end_of_new_list = other_it->current;
427 if (prev == other_it->current) {
428 list->last =
nullptr;
429 prev = current = next =
nullptr;
430 other_it->prev = other_it->current = other_it->next =
nullptr;
432 prev->next = other_it->next;
433 current = other_it->current =
nullptr;
434 next = other_it->next;
435 other_it->prev = prev;
437 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(gnu_printf