81 "Destination list must be empty before extracting a sublist";
91 last = start_it->extract_sublist (end_it);
127 const void *,
const void *)) {
151 qsort ((
char *) base, count,
sizeof (*base), comparator);
155 for (i = 0; i <
count; i++) {
173 int comparator(
const void*,
const void*),
176 if (last ==
NULL || comparator(&last, &new_link) < 0) {
178 new_link->next = new_link;
180 new_link->next = last->next;
181 last->next = new_link;
189 int compare = comparator(&link, &new_link);
192 }
else if (unique && compare == 0) {
229 started_cycling =
TRUE;
231 current = current->next;
233 if (ex_current_was_cycle_pt)
237 next = current->next;
244 "This is: %p Current is: %p",
this, current);
277 for (ptr = current ? current : prev; offset-- > 0; ptr = ptr->next);
304 while (current != list->last)
323 const ERRCODE DONT_EXCHANGE_DELETED =
324 "Can't exchange deleted elements of lists";
335 if (!(other_it->list))
342 if ((list->
empty ()) ||
343 (other_it->list->
empty ()) || (current == other_it->current))
348 if (!current || !other_it->current)
349 DONT_EXCHANGE_DELETED.
error (
"ELIST_ITERATOR.exchange",
ABORT,
NULL);
356 if ((next == other_it->current) ||
357 (other_it->next == current)) {
359 if ((next == other_it->current) &&
360 (other_it->next == current)) {
361 prev = next = current;
362 other_it->prev = other_it->next = other_it->current;
367 if (other_it->next == current) {
368 other_it->prev->next = current;
369 other_it->current->next = next;
370 current->next = other_it->current;
371 other_it->next = other_it->current;
375 prev->next = other_it->current;
376 current->next = other_it->next;
377 other_it->current->next = current;
379 other_it->prev = other_it->current;
384 prev->next = other_it->current;
385 current->next = other_it->next;
386 other_it->prev->next = current;
387 other_it->current->next = next;
393 if (list->last == current)
394 list->last = other_it->current;
395 if (other_it->list->last == other_it->current)
396 other_it->list->last = current;
398 if (current == cycle_pt)
399 cycle_pt = other_it->cycle_pt;
400 if (other_it->current == other_it->cycle_pt)
401 other_it->cycle_pt = cycle_pt;
405 old_current = current;
406 current = other_it->current;
407 other_it->current = old_current;
424 const ERRCODE BAD_EXTRACTION_PTS =
425 "Can't extract sublist from points on different lists";
426 const ERRCODE DONT_EXTRACT_DELETED =
427 "Can't extract a sublist marked by deleted points";
429 const ERRCODE BAD_SUBLIST =
"Can't find sublist end point in original list";
442 if (list != other_it->list)
443 BAD_EXTRACTION_PTS.
error (
"ELIST_ITERATOR.extract_sublist",
ABORT,
NULL);
447 if (!current || !other_it->current)
448 DONT_EXTRACT_DELETED.
error (
"ELIST_ITERATOR.extract_sublist",
ABORT,
452 ex_current_was_last = other_it->ex_current_was_last =
FALSE;
453 ex_current_was_cycle_pt =
FALSE;
454 other_it->ex_current_was_cycle_pt =
FALSE;
459 BAD_SUBLIST.
error (
"ELIST_ITERATOR.extract_sublist",
ABORT,
NULL);
463 ex_current_was_last = other_it->ex_current_was_last =
TRUE;
466 if (temp_it.current == cycle_pt)
467 ex_current_was_cycle_pt =
TRUE;
469 if (temp_it.current == other_it->cycle_pt)
470 other_it->ex_current_was_cycle_pt =
TRUE;
474 while (temp_it.prev != other_it->current);
477 other_it->current->next = current;
478 end_of_new_list = other_it->current;
481 if (prev == other_it->current) {
483 prev = current = next =
NULL;
484 other_it->prev = other_it->current = other_it->next =
NULL;
487 prev->next = other_it->next;
488 current = other_it->current =
NULL;
489 next = other_it->next;
490 other_it->prev = prev;
492 return end_of_new_list;
void add_to_end(ELIST_LINK *new_link)
void sort(int comparator(const void *, const void *))
ELIST_LINK * data_relative(inT8 offset)
const ERRCODE BAD_PARAMETER
void exchange(ELIST_ITERATOR *other_it)
void add_before_then_move(ELIST_LINK *new_link)
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
ELIST_LINK * add_sorted_and_find(int comparator(const void *, const void *), bool unique, ELIST_LINK *new_link)
ELIST_LINK * move_to_last()
const ERRCODE NULL_OBJECT
void internal_clear(void(*zapper)(ELIST_LINK *))
void assign_to_sublist(ELIST_ITERATOR *start_it, ELIST_ITERATOR *end_it)