42 void (*zapper) (
void *)) {
101 "Destination list must be empty before extracting a sublist";
104 LIST_NOT_EMPTY.
error (
"CLIST.assign_to_sublist",
ABORT,
nullptr);
106 last = start_it->extract_sublist (end_it);
133 const void *,
const void *)) {
142 base = (
void **) malloc (
count *
sizeof (
void *));
152 qsort(base,
count,
sizeof(*base), comparator);
156 for (i = 0; i <
count; i++) {
171 bool unique,
void* new_data) {
173 if (last ==
nullptr || comparator(&last->data, &new_data) < 0) {
175 new_element->data = new_data;
176 if (last ==
nullptr) {
177 new_element->next = new_element;
179 new_element->next = last->next;
180 last->next = new_element;
184 }
else if (!unique || last->data != new_data) {
188 void* data = it.
data();
189 if (data == new_data && unique)
191 if (comparator(&data, &new_data) > 0)
217 void* minu = m_it.
data();
218 void* subtra =
nullptr;
220 subtra = s_it.
data();
222 comparator(&subtra, &minu) < 0) {
224 subtra = s_it.
data();
227 if (subtra ==
nullptr || comparator(&subtra, &minu) != 0)
256 started_cycling =
TRUE;
258 current = current->next;
260 if (ex_current_was_cycle_pt)
270 "This is: %p Current is: %p",
this, current);
273 next = current->next;
274 return current->data;
302 for (ptr = current ? current : prev; offset-- > 0; ptr = ptr->next);
326 while (current != list->last)
329 if (current ==
nullptr)
332 return current->data;
347 const ERRCODE DONT_EXCHANGE_DELETED =
348 "Can't exchange deleted elements of lists";
357 if (!(other_it->list))
364 if ((list->
empty ()) ||
365 (other_it->list->
empty ()) || (current == other_it->current))
370 if (!current || !other_it->current)
371 DONT_EXCHANGE_DELETED.
error (
"CLIST_ITERATOR.exchange",
ABORT,
nullptr);
378 if ((next == other_it->current) ||
379 (other_it->next == current)) {
381 if ((next == other_it->current) &&
382 (other_it->next == current)) {
383 prev = next = current;
384 other_it->prev = other_it->next = other_it->current;
389 if (other_it->next == current) {
390 other_it->prev->next = current;
391 other_it->current->next = next;
392 current->next = other_it->current;
393 other_it->next = other_it->current;
397 prev->next = other_it->current;
398 current->next = other_it->next;
399 other_it->current->next = current;
401 other_it->prev = other_it->current;
406 prev->next = other_it->current;
407 current->next = other_it->next;
408 other_it->prev->next = current;
409 other_it->current->next = next;
415 if (list->last == current)
416 list->last = other_it->current;
417 if (other_it->list->last == other_it->current)
418 other_it->list->last = current;
420 if (current == cycle_pt)
421 cycle_pt = other_it->cycle_pt;
422 if (other_it->current == other_it->cycle_pt)
423 other_it->cycle_pt = cycle_pt;
427 old_current = current;
428 current = other_it->current;
429 other_it->current = old_current;
447 const ERRCODE BAD_SUBLIST =
"Can't find sublist end point in original list";
449 const ERRCODE BAD_EXTRACTION_PTS =
450 "Can't extract sublist from points on different lists";
451 const ERRCODE DONT_EXTRACT_DELETED =
452 "Can't extract a sublist marked by deleted points";
459 if (list != other_it->list)
460 BAD_EXTRACTION_PTS.
error (
"CLIST_ITERATOR.extract_sublist",
ABORT,
nullptr);
464 if (!current || !other_it->current)
465 DONT_EXTRACT_DELETED.
error (
"CLIST_ITERATOR.extract_sublist",
ABORT,
469 ex_current_was_last = other_it->ex_current_was_last =
false;
470 ex_current_was_cycle_pt =
false;
471 other_it->ex_current_was_cycle_pt =
false;
476 BAD_SUBLIST.
error (
"CLIST_ITERATOR.extract_sublist",
ABORT,
nullptr);
480 ex_current_was_last = other_it->ex_current_was_last =
true;
483 if (temp_it.current == cycle_pt)
484 ex_current_was_cycle_pt =
true;
486 if (temp_it.current == other_it->cycle_pt)
487 other_it->ex_current_was_cycle_pt =
true;
491 while (temp_it.prev != other_it->current);
494 other_it->current->next = current;
495 end_of_new_list = other_it->current;
498 if (prev == other_it->current) {
499 list->last =
nullptr;
500 prev = current = next =
nullptr;
501 other_it->prev = other_it->current = other_it->next =
nullptr;
504 prev->next = other_it->next;
505 current = other_it->current =
nullptr;
506 next = other_it->next;
507 other_it->prev = prev;
509 return end_of_new_list;
bool add_sorted(int comparator(const void *, const void *), bool unique, void *new_data)
void assign_to_sublist(CLIST_ITERATOR *start_it, CLIST_ITERATOR *end_it)
void add_before_then_move(void *new_data)
void internal_deep_clear(void(*zapper)(void *))
void * data_relative(int8_t offset)
void sort(int comparator(const void *, const void *))
void exchange(CLIST_ITERATOR *other_it)
const ERRCODE BAD_PARAMETER
void set_subtract(int comparator(const void *, const void *), bool unique, CLIST *minuend, CLIST *subtrahend)
void add_to_end(void *new_data)
void error(const char *caller, TessErrorLogCode action, const char *format,...) const