37 void (*zapper)(
void *)) {
39 auto ptr = last->next;
43 auto next = ptr->next;
62 auto ptr = last->next;
66 auto next = ptr->next;
89 constexpr ERRCODE LIST_NOT_EMPTY(
"Destination list must be empty before extracting a sublist");
92 LIST_NOT_EMPTY.
error(
"CLIST.assign_to_sublist",
ABORT);
95 last = start_it->extract_sublist(end_it);
106 const void *,
const void *)) {
111 std::vector<void *> base;
122 qsort(&base[0],
count,
sizeof(base[0]), comparator);
125 for (
auto current : base) {
138bool CLIST::add_sorted(
int comparator(
const void *,
const void *),
bool unique,
void *new_data) {
140 if (last ==
nullptr || comparator(&last->data, &new_data) < 0) {
142 new_element->data = new_data;
143 if (last ==
nullptr) {
144 new_element->next = new_element;
146 new_element->next = last->next;
147 last->next = new_element;
151 }
else if (!unique || last->data != new_data) {
155 void *data = it.
data();
156 if (data == new_data && unique) {
159 if (comparator(&data, &new_data) > 0) {
186 void *minu = m_it.
data();
187 void *subtra =
nullptr;
189 subtra = s_it.
data();
190 while (!s_it.
at_last() && comparator(&subtra, &minu) < 0) {
192 subtra = s_it.
data();
195 if (subtra ==
nullptr || comparator(&subtra, &minu) != 0) {
221 started_cycling =
true;
223 current = current->next;
225 if (ex_current_was_cycle_pt) {
231 next = current->next;
232 return current->data;
259 for (ptr = current ? current : prev; offset-- > 0; ptr = ptr->next) {
276 while (current != list->last) {
280 if (current ==
nullptr) {
283 return current->data;
299 constexpr ERRCODE DONT_EXCHANGE_DELETED(
"Can't exchange deleted elements of lists");
304 if ((list->
empty()) || (other_it->list->
empty()) || (current == other_it->current)) {
310 if (!current || !other_it->current) {
311 DONT_EXCHANGE_DELETED.
error(
"CLIST_ITERATOR.exchange",
ABORT);
319 if ((next == other_it->current) || (other_it->next == current)) {
321 if ((next == other_it->current) && (other_it->next == current)) {
322 prev = next = current;
323 other_it->prev = other_it->next = other_it->current;
327 if (other_it->next == current) {
328 other_it->prev->next = current;
329 other_it->current->next = next;
330 current->next = other_it->current;
331 other_it->next = other_it->current;
334 prev->next = other_it->current;
335 current->next = other_it->next;
336 other_it->current->next = current;
338 other_it->prev = other_it->current;
342 prev->next = other_it->current;
343 current->next = other_it->next;
344 other_it->prev->next = current;
345 other_it->current->next = next;
351 if (list->last == current) {
352 list->last = other_it->current;
354 if (other_it->list->last == other_it->current) {
355 other_it->list->last = current;
358 if (current == cycle_pt) {
359 cycle_pt = other_it->cycle_pt;
361 if (other_it->current == other_it->cycle_pt) {
362 other_it->cycle_pt = cycle_pt;
367 auto old_current = current;
368 current = other_it->current;
369 other_it->current = old_current;
386 constexpr ERRCODE BAD_SUBLIST(
"Can't find sublist end point in original list");
388 constexpr ERRCODE BAD_EXTRACTION_PTS(
"Can't extract sublist from points on different lists");
389 constexpr ERRCODE DONT_EXTRACT_DELETED(
"Can't extract a sublist marked by deleted points");
391 if (list != other_it->list)
392 BAD_EXTRACTION_PTS.error(
"CLIST_ITERATOR.extract_sublist",
ABORT);
396 if (!current || !other_it->current)
397 DONT_EXTRACT_DELETED.error(
"CLIST_ITERATOR.extract_sublist",
ABORT);
400 ex_current_was_last = other_it->ex_current_was_last =
false;
401 ex_current_was_cycle_pt =
false;
402 other_it->ex_current_was_cycle_pt =
false;
407 BAD_SUBLIST.error(
"CLIST_ITERATOR.extract_sublist",
ABORT);
412 ex_current_was_last = other_it->ex_current_was_last =
true;
415 if (temp_it.current == cycle_pt) {
416 ex_current_was_cycle_pt =
true;
419 if (temp_it.current == other_it->cycle_pt) {
420 other_it->ex_current_was_cycle_pt =
true;
424 }
while (temp_it.prev != other_it->current);
427 other_it->current->next = current;
428 auto end_of_new_list = other_it->current;
431 if (prev == other_it->current) {
432 list->last =
nullptr;
433 prev = current = next =
nullptr;
434 other_it->prev = other_it->current = other_it->next =
nullptr;
436 prev->next = other_it->next;
437 current = other_it->current =
nullptr;
438 next = other_it->next;
439 other_it->prev = prev;
441 return end_of_new_list;
constexpr ERRCODE BAD_PARAMETER("List parameter error")
constexpr ERRCODE NO_LIST("Iterator not set to a list")
constexpr ERRCODE EMPTY_LIST("List is empty")
void sort(int comparator(const void *, const void *))
void assign_to_sublist(CLIST_ITERATOR *start_it, CLIST_ITERATOR *end_it)
void internal_deep_clear(void(*zapper)(void *))
void set_subtract(int comparator(const void *, const void *), bool unique, CLIST *minuend, CLIST *subtrahend)
bool add_sorted(int comparator(const void *, const void *), bool unique, void *new_data)
void exchange(CLIST_ITERATOR *other_it)
void add_to_end(void *new_data)
void add_before_then_move(void *new_data)
void * data_relative(int8_t offset)
void error(const char *caller, TessErrorLogCode action, const char *format,...) const __attribute__((format(gnu_printf