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);
111 const void *,
const void *)) {
130 qsort ((
char *) base,
count,
sizeof (*base), comparator);
134 for (i = 0; i <
count; i++) {
149 if (last == NULL || comparator(&last, &new_link) < 0) {
151 new_link->next = new_link;
152 new_link->prev = new_link;
154 new_link->next = last->next;
155 new_link->prev = last;
156 last->next = new_link;
157 new_link->next->prev = new_link;
165 if (comparator(&link, &new_link) > 0)
198 started_cycling =
TRUE;
200 current = current->next;
203 if (ex_current_was_cycle_pt)
207 next = current->next;
214 "This is: %p Current is: %p",
this, current);
237 started_cycling =
TRUE;
239 current = current->prev;
241 if (ex_current_was_cycle_pt)
245 prev = current->prev;
252 "This is: %p Current is: %p",
this, current);
276 for (ptr = current ? current : next; offset++ < 0; ptr = ptr->prev);
278 for (ptr = current ? current : prev; offset-- > 0; ptr = ptr->next);
300 const ERRCODE DONT_EXCHANGE_DELETED =
301 "Can't exchange deleted elements of lists";
310 if (!(other_it->list))
317 if ((list->
empty ()) ||
318 (other_it->list->
empty ()) || (current == other_it->current))
323 if (!current || !other_it->current)
324 DONT_EXCHANGE_DELETED.
error (
"ELIST2_ITERATOR.exchange",
ABORT, NULL);
331 if ((next == other_it->current) ||
332 (other_it->next == current)) {
334 if ((next == other_it->current) &&
335 (other_it->next == current)) {
336 prev = next = current;
337 other_it->prev = other_it->next = other_it->current;
342 if (other_it->next == current) {
343 other_it->prev->next = current;
344 other_it->current->next = next;
345 other_it->current->prev = current;
346 current->next = other_it->current;
347 current->prev = other_it->prev;
348 next->prev = other_it->current;
350 other_it->next = other_it->current;
354 prev->next = other_it->current;
355 current->next = other_it->next;
356 current->prev = other_it->current;
357 other_it->current->next = current;
358 other_it->current->prev = prev;
359 other_it->next->prev = current;
362 other_it->prev = other_it->current;
367 prev->next = other_it->current;
368 current->next = other_it->next;
369 current->prev = other_it->prev;
370 next->prev = other_it->current;
371 other_it->prev->next = current;
372 other_it->current->next = next;
373 other_it->current->prev = prev;
374 other_it->next->prev = current;
380 if (list->last == current)
381 list->last = other_it->current;
382 if (other_it->list->last == other_it->current)
383 other_it->list->last = current;
385 if (current == cycle_pt)
386 cycle_pt = other_it->cycle_pt;
387 if (other_it->current == other_it->cycle_pt)
388 other_it->cycle_pt = cycle_pt;
392 old_current = current;
393 current = other_it->current;
394 other_it->current = old_current;
410 const ERRCODE BAD_EXTRACTION_PTS =
411 "Can't extract sublist from points on different lists";
412 const ERRCODE DONT_EXTRACT_DELETED =
413 "Can't extract a sublist marked by deleted points";
415 const ERRCODE BAD_SUBLIST =
"Can't find sublist end point in original list";
426 if (list != other_it->list)
427 BAD_EXTRACTION_PTS.
error (
"ELIST2_ITERATOR.extract_sublist",
ABORT, NULL);
431 if (!current || !other_it->current)
432 DONT_EXTRACT_DELETED.
error (
"ELIST2_ITERATOR.extract_sublist",
ABORT,
436 ex_current_was_last = other_it->ex_current_was_last =
FALSE;
437 ex_current_was_cycle_pt =
FALSE;
438 other_it->ex_current_was_cycle_pt =
FALSE;
443 BAD_SUBLIST.
error (
"ELIST2_ITERATOR.extract_sublist",
ABORT, NULL);
447 ex_current_was_last = other_it->ex_current_was_last =
TRUE;
450 if (temp_it.current == cycle_pt)
451 ex_current_was_cycle_pt =
TRUE;
453 if (temp_it.current == other_it->cycle_pt)
454 other_it->ex_current_was_cycle_pt =
TRUE;
459 while (temp_it.prev != other_it->current);
462 other_it->current->next = current;
464 current->prev = other_it->current;
465 end_of_new_list = other_it->current;
468 if (prev == other_it->current) {
470 prev = current = next = NULL;
471 other_it->prev = other_it->current = other_it->next = NULL;
474 prev->next = other_it->next;
475 other_it->next->prev = prev;
477 current = other_it->current = NULL;
478 next = other_it->next;
479 other_it->prev = prev;
481 return end_of_new_list;
const ERRCODE BAD_PARAMETER
void add_before_then_move(ELIST2_LINK *new_link)
void internal_clear(void(*zapper)(ELIST2_LINK *))
void add_to_end(ELIST2_LINK *new_link)
void assign_to_sublist(ELIST2_ITERATOR *start_it, ELIST2_ITERATOR *end_it)
void exchange(ELIST2_ITERATOR *other_it)
void sort(int comparator(const void *, const void *))
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
void add_sorted(int comparator(const void *, const void *), ELIST2_LINK *new_link)
ELIST2_LINK * data_relative(inT8 offset)