42 void (*zapper) (
void *)) {
102 "Destination list must be empty before extracting a sublist";
105 LIST_NOT_EMPTY.
error (
"CLIST.assign_to_sublist",
ABORT, NULL);
107 last = start_it->extract_sublist (end_it);
136 const void *,
const void *)) {
145 base = (
void **) malloc (count *
sizeof (
void *));
155 qsort ((
char *) base, count,
sizeof (*base), comparator);
159 for (i = 0; i <
count; i++) {
174 bool unique,
void* new_data) {
176 if (last == NULL || comparator(&last->data, &new_data) < 0) {
178 new_element->data = new_data;
180 new_element->next = new_element;
182 new_element->next = last->next;
183 last->next = new_element;
187 }
else if (!unique || last->data != new_data) {
191 void* data = it.
data();
192 if (data == new_data && unique)
194 if (comparator(&data, &new_data) > 0)
220 void* minu = m_it.
data();
223 subtra = s_it.
data();
225 comparator(&subtra, &minu) < 0) {
227 subtra = s_it.
data();
230 if (subtra == NULL || comparator(&subtra, &minu) != 0)
259 started_cycling =
TRUE;
261 current = current->next;
263 if (ex_current_was_cycle_pt)
267 next = current->next;
274 "This is: %p Current is: %p",
this, current);
276 return current->data;
305 for (ptr = current ? current : prev; offset-- > 0; ptr = ptr->next);
330 while (current != list->last)
336 return current->data;
352 const ERRCODE DONT_EXCHANGE_DELETED =
353 "Can't exchange deleted elements of lists";
362 if (!(other_it->list))
369 if ((list->
empty ()) ||
370 (other_it->list->
empty ()) || (current == other_it->current))
375 if (!current || !other_it->current)
376 DONT_EXCHANGE_DELETED.
error (
"CLIST_ITERATOR.exchange",
ABORT, NULL);
383 if ((next == other_it->current) ||
384 (other_it->next == current)) {
386 if ((next == other_it->current) &&
387 (other_it->next == current)) {
388 prev = next = current;
389 other_it->prev = other_it->next = other_it->current;
394 if (other_it->next == current) {
395 other_it->prev->next = current;
396 other_it->current->next = next;
397 current->next = other_it->current;
398 other_it->next = other_it->current;
402 prev->next = other_it->current;
403 current->next = other_it->next;
404 other_it->current->next = current;
406 other_it->prev = other_it->current;
411 prev->next = other_it->current;
412 current->next = other_it->next;
413 other_it->prev->next = current;
414 other_it->current->next = next;
420 if (list->last == current)
421 list->last = other_it->current;
422 if (other_it->list->last == other_it->current)
423 other_it->list->last = current;
425 if (current == cycle_pt)
426 cycle_pt = other_it->cycle_pt;
427 if (other_it->current == other_it->cycle_pt)
428 other_it->cycle_pt = cycle_pt;
432 old_current = current;
433 current = other_it->current;
434 other_it->current = old_current;
453 const ERRCODE BAD_SUBLIST =
"Can't find sublist end point in original list";
455 const ERRCODE BAD_EXTRACTION_PTS =
456 "Can't extract sublist from points on different lists";
457 const ERRCODE DONT_EXTRACT_DELETED =
458 "Can't extract a sublist marked by deleted points";
465 if (list != other_it->list)
466 BAD_EXTRACTION_PTS.
error (
"CLIST_ITERATOR.extract_sublist",
ABORT, NULL);
470 if (!current || !other_it->current)
471 DONT_EXTRACT_DELETED.
error (
"CLIST_ITERATOR.extract_sublist",
ABORT,
475 ex_current_was_last = other_it->ex_current_was_last =
FALSE;
476 ex_current_was_cycle_pt =
FALSE;
477 other_it->ex_current_was_cycle_pt =
FALSE;
482 BAD_SUBLIST.
error (
"CLIST_ITERATOR.extract_sublist",
ABORT, NULL);
486 ex_current_was_last = other_it->ex_current_was_last =
TRUE;
489 if (temp_it.current == cycle_pt)
490 ex_current_was_cycle_pt =
TRUE;
492 if (temp_it.current == other_it->cycle_pt)
493 other_it->ex_current_was_cycle_pt =
TRUE;
497 while (temp_it.prev != other_it->current);
500 other_it->current->next = current;
501 end_of_new_list = other_it->current;
504 if (prev == other_it->current) {
506 prev = current = next = NULL;
507 other_it->prev = other_it->current = other_it->next = NULL;
510 prev->next = other_it->next;
511 current = other_it->current = NULL;
512 next = other_it->next;
513 other_it->prev = prev;
515 return end_of_new_list;
void exchange(CLIST_ITERATOR *other_it)
void assign_to_sublist(CLIST_ITERATOR *start_it, CLIST_ITERATOR *end_it)
const ERRCODE BAD_PARAMETER
void set_subtract(int comparator(const void *, const void *), bool unique, CLIST *minuend, CLIST *subtrahend)
void * data_relative(inT8 offset)
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
void sort(int comparator(const void *, const void *))
void add_before_then_move(void *new_data)
void add_to_end(void *new_data)
void internal_deep_clear(void(*zapper)(void *))
bool add_sorted(int comparator(const void *, const void *), bool unique, void *new_data)