77 "Destination list must be empty before extracting a sublist";
80 LIST_NOT_EMPTY.
error (
"ELIST2.assign_to_sublist",
ABORT, NULL);
82 last = start_it->extract_sublist (end_it);
113 const void *,
const void *)) {
132 qsort ((
char *) base, count,
sizeof (*base), comparator);
136 for (i = 0; i <
count; i++) {
151 if (last == NULL || comparator(&last, &new_link) < 0) {
153 new_link->next = new_link;
154 new_link->prev = new_link;
156 new_link->next = last->next;
157 new_link->prev = last;
158 last->next = new_link;
159 new_link->next->prev = new_link;
167 if (comparator(&link, &new_link) > 0)
200 started_cycling =
TRUE;
202 current = current->next;
205 if (ex_current_was_cycle_pt)
209 next = current->next;
216 "This is: %p Current is: %p",
this, current);
240 started_cycling =
TRUE;
242 current = current->prev;
244 if (ex_current_was_cycle_pt)
248 prev = current->prev;
255 "This is: %p Current is: %p",
this, current);
280 for (ptr = current ? current : next; offset++ < 0; ptr = ptr->prev);
282 for (ptr = current ? current : prev; offset-- > 0; ptr = ptr->next);
305 const ERRCODE DONT_EXCHANGE_DELETED =
306 "Can't exchange deleted elements of lists";
315 if (!(other_it->list))
322 if ((list->
empty ()) ||
323 (other_it->list->
empty ()) || (current == other_it->current))
328 if (!current || !other_it->current)
329 DONT_EXCHANGE_DELETED.
error (
"ELIST2_ITERATOR.exchange",
ABORT, NULL);
336 if ((next == other_it->current) ||
337 (other_it->next == current)) {
339 if ((next == other_it->current) &&
340 (other_it->next == current)) {
341 prev = next = current;
342 other_it->prev = other_it->next = other_it->current;
347 if (other_it->next == current) {
348 other_it->prev->next = current;
349 other_it->current->next = next;
350 other_it->current->prev = current;
351 current->next = other_it->current;
352 current->prev = other_it->prev;
353 next->prev = other_it->current;
355 other_it->next = other_it->current;
359 prev->next = other_it->current;
360 current->next = other_it->next;
361 current->prev = other_it->current;
362 other_it->current->next = current;
363 other_it->current->prev = prev;
364 other_it->next->prev = current;
367 other_it->prev = other_it->current;
372 prev->next = other_it->current;
373 current->next = other_it->next;
374 current->prev = other_it->prev;
375 next->prev = other_it->current;
376 other_it->prev->next = current;
377 other_it->current->next = next;
378 other_it->current->prev = prev;
379 other_it->next->prev = current;
385 if (list->last == current)
386 list->last = other_it->current;
387 if (other_it->list->last == other_it->current)
388 other_it->list->last = current;
390 if (current == cycle_pt)
391 cycle_pt = other_it->cycle_pt;
392 if (other_it->current == other_it->cycle_pt)
393 other_it->cycle_pt = cycle_pt;
397 old_current = current;
398 current = other_it->current;
399 other_it->current = old_current;
416 const ERRCODE BAD_EXTRACTION_PTS =
417 "Can't extract sublist from points on different lists";
418 const ERRCODE DONT_EXTRACT_DELETED =
419 "Can't extract a sublist marked by deleted points";
421 const ERRCODE BAD_SUBLIST =
"Can't find sublist end point in original list";
432 if (list != other_it->list)
433 BAD_EXTRACTION_PTS.
error (
"ELIST2_ITERATOR.extract_sublist",
ABORT, NULL);
437 if (!current || !other_it->current)
438 DONT_EXTRACT_DELETED.
error (
"ELIST2_ITERATOR.extract_sublist",
ABORT,
442 ex_current_was_last = other_it->ex_current_was_last =
FALSE;
443 ex_current_was_cycle_pt =
FALSE;
444 other_it->ex_current_was_cycle_pt =
FALSE;
449 BAD_SUBLIST.
error (
"ELIST2_ITERATOR.extract_sublist",
ABORT, NULL);
453 ex_current_was_last = other_it->ex_current_was_last =
TRUE;
456 if (temp_it.current == cycle_pt)
457 ex_current_was_cycle_pt =
TRUE;
459 if (temp_it.current == other_it->cycle_pt)
460 other_it->ex_current_was_cycle_pt =
TRUE;
465 while (temp_it.prev != other_it->current);
468 other_it->current->next = current;
470 current->prev = other_it->current;
471 end_of_new_list = other_it->current;
474 if (prev == other_it->current) {
476 prev = current = next = NULL;
477 other_it->prev = other_it->current = other_it->next = NULL;
480 prev->next = other_it->next;
481 other_it->next->prev = prev;
483 current = other_it->current = NULL;
484 next = other_it->next;
485 other_it->prev = prev;
487 return end_of_new_list;
void internal_clear(void(*zapper)(ELIST2_LINK *))
void add_sorted(int comparator(const void *, const void *), ELIST2_LINK *new_link)
void sort(int comparator(const void *, const void *))
void add_before_then_move(ELIST2_LINK *new_link)
const ERRCODE BAD_PARAMETER
void assign_to_sublist(ELIST2_ITERATOR *start_it, ELIST2_ITERATOR *end_it)
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
void exchange(ELIST2_ITERATOR *other_it)
ELIST2_LINK * data_relative(inT8 offset)
void add_to_end(ELIST2_LINK *new_link)