summaryrefslogtreecommitdiffhomepage
path: root/include/stc/clist.h
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-10-29 14:39:12 +0200
committerTyge Løvset <[email protected]>2021-10-29 14:39:12 +0200
commita0899da505475f4f98e67027d13ffc8da155c201 (patch)
treed27788c588543163190807c063ce7b6ccc37e22a /include/stc/clist.h
parent583a0ac357dba6b8c35db7450e8286469516a3b9 (diff)
downloadSTC-modified-a0899da505475f4f98e67027d13ffc8da155c201.tar.gz
STC-modified-a0899da505475f4f98e67027d13ffc8da155c201.zip
renamed cx_..._t to _cx_..._t, and Self to _cx_self
Diffstat (limited to 'include/stc/clist.h')
-rw-r--r--include/stc/clist.h222
1 files changed, 111 insertions, 111 deletions
diff --git a/include/stc/clist.h b/include/stc/clist.h
index aa1ef3e8..85f14378 100644
--- a/include/stc/clist.h
+++ b/include/stc/clist.h
@@ -64,13 +64,13 @@
SELF##_value_t value; \
}
-#define clist_node_(vp) c_container_of(vp, cx_node_t, value)
+#define clist_node_(vp) c_container_of(vp, _cx_node_t, value)
_c_clist_types(clist_VOID, int);
_c_clist_complete_types(clist_VOID, dummy);
-#define _c_clist_insert_after(self, Self, node, val) \
- cx_node_t *entry = c_new (cx_node_t); \
+#define _c_clist_insert_after(self, _cx_self, node, val) \
+ _cx_node_t *entry = c_new (_cx_node_t); \
if (node) entry->next = node->next, node->next = entry; \
else entry->next = entry; \
entry->value = val
@@ -84,132 +84,132 @@ _c_clist_complete_types(clist_VOID, dummy);
#include "template.h"
#if !defined i_fwd
- cx_deftypes(_c_clist_types, Self, i_val);
+ _cx_deftypes(_c_clist_types, _cx_self, i_val);
#endif
-cx_deftypes(_c_clist_complete_types, Self, dummy);
-typedef i_valraw cx_rawvalue_t;
+_cx_deftypes(_c_clist_complete_types, _cx_self, dummy);
+typedef i_valraw _cx_rawvalue_t;
STC_API size_t _clist_count(const clist_VOID* self);
-
-STC_API Self cx_memb(_clone)(Self cx);
-STC_API void cx_memb(_del)(Self* self);
-STC_API cx_value_t* cx_memb(_push_back)(Self* self, i_val value);
-STC_API cx_value_t* cx_memb(_push_front)(Self* self, i_val value);
-STC_API cx_iter_t cx_memb(_insert)(Self* self, cx_iter_t it, i_val value);
-STC_API cx_iter_t cx_memb(_erase_at)(Self* self, cx_iter_t it);
-STC_API cx_iter_t cx_memb(_erase_range)(Self* self, cx_iter_t it1, cx_iter_t it2);
-STC_API size_t cx_memb(_remove)(Self* self, i_valraw val);
-STC_API cx_iter_t cx_memb(_splice)(Self* self, cx_iter_t it, Self* other);
-STC_API Self cx_memb(_split_off)(Self* self, cx_iter_t it1, cx_iter_t it2);
-STC_API void cx_memb(_sort)(Self* self);
-STC_API cx_iter_t cx_memb(_find_in)(cx_iter_t it1, cx_iter_t it2, i_valraw val);
-STC_API cx_node_t* cx_memb(_erase_after_)(Self* self, cx_node_t* node);
-
-STC_INLINE Self cx_memb(_init)(void) { return c_make(Self){NULL}; }
-STC_INLINE bool cx_memb(_empty)(Self cx) { return cx.last == NULL; }
-STC_INLINE size_t cx_memb(_count)(Self cx)
+
+STC_API _cx_self _cx_memb(_clone)(_cx_self cx);
+STC_API void _cx_memb(_del)(_cx_self* self);
+STC_API _cx_value_t* _cx_memb(_push_back)(_cx_self* self, i_val value);
+STC_API _cx_value_t* _cx_memb(_push_front)(_cx_self* self, i_val value);
+STC_API _cx_iter_t _cx_memb(_insert)(_cx_self* self, _cx_iter_t it, i_val value);
+STC_API _cx_iter_t _cx_memb(_erase_at)(_cx_self* self, _cx_iter_t it);
+STC_API _cx_iter_t _cx_memb(_erase_range)(_cx_self* self, _cx_iter_t it1, _cx_iter_t it2);
+STC_API size_t _cx_memb(_remove)(_cx_self* self, i_valraw val);
+STC_API _cx_iter_t _cx_memb(_splice)(_cx_self* self, _cx_iter_t it, _cx_self* other);
+STC_API _cx_self _cx_memb(_split_off)(_cx_self* self, _cx_iter_t it1, _cx_iter_t it2);
+STC_API void _cx_memb(_sort)(_cx_self* self);
+STC_API _cx_iter_t _cx_memb(_find_in)(_cx_iter_t it1, _cx_iter_t it2, i_valraw val);
+STC_API _cx_node_t* _cx_memb(_erase_after_)(_cx_self* self, _cx_node_t* node);
+
+STC_INLINE _cx_self _cx_memb(_init)(void) { return c_make(_cx_self){NULL}; }
+STC_INLINE bool _cx_memb(_empty)(_cx_self cx) { return cx.last == NULL; }
+STC_INLINE size_t _cx_memb(_count)(_cx_self cx)
{ return _clist_count((const clist_VOID*) &cx); }
-STC_INLINE void cx_memb(_clear)(Self* self) { cx_memb(_del)(self); }
-STC_INLINE i_val cx_memb(_value_fromraw)(i_valraw raw) { return i_valfrom(raw); }
-STC_INLINE i_valraw cx_memb(_value_toraw)(cx_value_t* pval) { return i_valto(pval); }
-STC_INLINE i_val cx_memb(_value_clone)(i_val val)
+STC_INLINE void _cx_memb(_clear)(_cx_self* self) { _cx_memb(_del)(self); }
+STC_INLINE i_val _cx_memb(_value_fromraw)(i_valraw raw) { return i_valfrom(raw); }
+STC_INLINE i_valraw _cx_memb(_value_toraw)(_cx_value_t* pval) { return i_valto(pval); }
+STC_INLINE i_val _cx_memb(_value_clone)(i_val val)
{ return i_valfrom(i_valto(&val)); }
-STC_INLINE void cx_memb(_pop_front)(Self* self)
- { cx_memb(_erase_after_)(self, self->last); }
-STC_INLINE cx_value_t* cx_memb(_emplace_back)(Self* self, i_valraw raw)
- { return cx_memb(_push_back)(self, i_valfrom(raw)); }
-STC_INLINE cx_value_t* cx_memb(_emplace_front)(Self* self, i_valraw raw)
- { return cx_memb(_push_front)(self, i_valfrom(raw)); }
-STC_INLINE cx_iter_t cx_memb(_emplace)(Self* self, cx_iter_t it, i_valraw raw)
- { return cx_memb(_insert)(self, it, i_valfrom(raw)); }
-STC_INLINE cx_value_t* cx_memb(_front)(const Self* self) { return &self->last->next->value; }
-STC_INLINE cx_value_t* cx_memb(_back)(const Self* self) { return &self->last->value; }
+STC_INLINE void _cx_memb(_pop_front)(_cx_self* self)
+ { _cx_memb(_erase_after_)(self, self->last); }
+STC_INLINE _cx_value_t* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw)
+ { return _cx_memb(_push_back)(self, i_valfrom(raw)); }
+STC_INLINE _cx_value_t* _cx_memb(_emplace_front)(_cx_self* self, i_valraw raw)
+ { return _cx_memb(_push_front)(self, i_valfrom(raw)); }
+STC_INLINE _cx_iter_t _cx_memb(_emplace)(_cx_self* self, _cx_iter_t it, i_valraw raw)
+ { return _cx_memb(_insert)(self, it, i_valfrom(raw)); }
+STC_INLINE _cx_value_t* _cx_memb(_front)(const _cx_self* self) { return &self->last->next->value; }
+STC_INLINE _cx_value_t* _cx_memb(_back)(const _cx_self* self) { return &self->last->value; }
STC_INLINE void
-cx_memb(_copy)(Self *self, Self other) {
+_cx_memb(_copy)(_cx_self *self, _cx_self other) {
if (self->last == other.last) return;
- cx_memb(_del)(self); *self = cx_memb(_clone)(other);
+ _cx_memb(_del)(self); *self = _cx_memb(_clone)(other);
}
-STC_INLINE cx_iter_t
-cx_memb(_iter)(const Self* self, cx_node_t* prev) {
- return c_make(cx_iter_t){&prev->next->value, &self->last, prev};
+STC_INLINE _cx_iter_t
+_cx_memb(_iterator)(const _cx_self* self, _cx_node_t* prev) {
+ return c_make(_cx_iter_t){&prev->next->value, &self->last, prev};
}
-STC_INLINE cx_iter_t
-cx_memb(_begin)(const Self* self) {
- cx_value_t* head = self->last ? &self->last->next->value : NULL;
- return c_make(cx_iter_t){head, &self->last, self->last};
+STC_INLINE _cx_iter_t
+_cx_memb(_begin)(const _cx_self* self) {
+ _cx_value_t* head = self->last ? &self->last->next->value : NULL;
+ return c_make(_cx_iter_t){head, &self->last, self->last};
}
-STC_INLINE cx_iter_t
-cx_memb(_end)(const Self* self) {
- return c_make(cx_iter_t){NULL};
+STC_INLINE _cx_iter_t
+_cx_memb(_end)(const _cx_self* self) {
+ return c_make(_cx_iter_t){NULL};
}
STC_INLINE void
-cx_memb(_next)(cx_iter_t* it) {
- cx_node_t* node = it->prev = clist_node_(it->ref);
+_cx_memb(_next)(_cx_iter_t* it) {
+ _cx_node_t* node = it->prev = clist_node_(it->ref);
it->ref = (node == *it->_last ? NULL : &node->next->value);
}
-STC_INLINE cx_iter_t
-cx_memb(_advance)(cx_iter_t it, size_t n) {
- while (n-- && it.ref) cx_memb(_next)(&it);
+STC_INLINE _cx_iter_t
+_cx_memb(_advance)(_cx_iter_t it, size_t n) {
+ while (n-- && it.ref) _cx_memb(_next)(&it);
return it;
}
-STC_INLINE cx_iter_t
-cx_memb(_splice_range)(Self* self, cx_iter_t it,
- Self* other, cx_iter_t it1, cx_iter_t it2) {
- Self tmp = cx_memb(_split_off)(other, it1, it2);
- return cx_memb(_splice)(self, it, &tmp);
+STC_INLINE _cx_iter_t
+_cx_memb(_splice_range)(_cx_self* self, _cx_iter_t it,
+ _cx_self* other, _cx_iter_t it1, _cx_iter_t it2) {
+ _cx_self tmp = _cx_memb(_split_off)(other, it1, it2);
+ return _cx_memb(_splice)(self, it, &tmp);
}
-STC_INLINE cx_iter_t
-cx_memb(_find)(const Self* self, i_valraw val) {
- return cx_memb(_find_in)(cx_memb(_begin)(self), cx_memb(_end)(self), val);
+STC_INLINE _cx_iter_t
+_cx_memb(_find)(const _cx_self* self, i_valraw val) {
+ return _cx_memb(_find_in)(_cx_memb(_begin)(self), _cx_memb(_end)(self), val);
}
-STC_INLINE cx_value_t*
-cx_memb(_get)(const Self* self, i_valraw val) {
- return cx_memb(_find_in)(cx_memb(_begin)(self), cx_memb(_end)(self), val).ref;
+STC_INLINE _cx_value_t*
+_cx_memb(_get)(const _cx_self* self, i_valraw val) {
+ return _cx_memb(_find_in)(_cx_memb(_begin)(self), _cx_memb(_end)(self), val).ref;
}
// -------------------------- IMPLEMENTATION -------------------------
#if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION) || defined(i_imp)
-STC_DEF Self
-cx_memb(_clone)(Self cx) {
- Self out = cx_memb(_init)();
- c_foreach (it, Self, cx) cx_memb(_emplace_back)(&out, i_valto(it.ref));
+STC_DEF _cx_self
+_cx_memb(_clone)(_cx_self cx) {
+ _cx_self out = _cx_memb(_init)();
+ c_foreach (it, _cx_self, cx) _cx_memb(_emplace_back)(&out, i_valto(it.ref));
return out;
}
STC_DEF void
-cx_memb(_del)(Self* self) {
- while (self->last) cx_memb(_erase_after_)(self, self->last);
+_cx_memb(_del)(_cx_self* self) {
+ while (self->last) _cx_memb(_erase_after_)(self, self->last);
}
-STC_DEF cx_value_t*
-cx_memb(_push_back)(Self* self, i_val value) {
- _c_clist_insert_after(self, Self, self->last, value);
+STC_DEF _cx_value_t*
+_cx_memb(_push_back)(_cx_self* self, i_val value) {
+ _c_clist_insert_after(self, _cx_self, self->last, value);
self->last = entry;
return &entry->value;
}
-STC_DEF cx_value_t*
-cx_memb(_push_front)(Self* self, i_val value) {
- _c_clist_insert_after(self, Self, self->last, value);
+STC_DEF _cx_value_t*
+_cx_memb(_push_front)(_cx_self* self, i_val value) {
+ _c_clist_insert_after(self, _cx_self, self->last, value);
if (!self->last) self->last = entry;
return &entry->value;
}
-STC_DEF cx_iter_t
-cx_memb(_insert)(Self* self, cx_iter_t it, i_val value) {
- cx_node_t* node = it.ref ? it.prev : self->last;
- _c_clist_insert_after(self, Self, node, value);
+STC_DEF _cx_iter_t
+_cx_memb(_insert)(_cx_self* self, _cx_iter_t it, i_val value) {
+ _cx_node_t* node = it.ref ? it.prev : self->last;
+ _c_clist_insert_after(self, _cx_self, node, value);
if (!self->last || !it.ref) {
it.prev = self->last ? self->last : entry;
self->last = entry;
@@ -218,35 +218,35 @@ cx_memb(_insert)(Self* self, cx_iter_t it, i_val value) {
return it;
}
-STC_DEF cx_iter_t
-cx_memb(_erase_at)(Self* self, cx_iter_t it) {
- cx_node_t *node = clist_node_(it.ref);
+STC_DEF _cx_iter_t
+_cx_memb(_erase_at)(_cx_self* self, _cx_iter_t it) {
+ _cx_node_t *node = clist_node_(it.ref);
it.ref = (node == self->last) ? NULL : &node->next->value;
- cx_memb(_erase_after_)(self, it.prev);
+ _cx_memb(_erase_after_)(self, it.prev);
return it;
}
-STC_DEF cx_iter_t
-cx_memb(_erase_range)(Self* self, cx_iter_t it1, cx_iter_t it2) {
- cx_node_t *node = it1.ref ? it1.prev : NULL,
+STC_DEF _cx_iter_t
+_cx_memb(_erase_range)(_cx_self* self, _cx_iter_t it1, _cx_iter_t it2) {
+ _cx_node_t *node = it1.ref ? it1.prev : NULL,
*done = it2.ref ? clist_node_(it2.ref) : NULL;
while (node && node->next != done)
- node = cx_memb(_erase_after_)(self, node);
+ node = _cx_memb(_erase_after_)(self, node);
return it2;
}
-STC_DEF cx_iter_t
-cx_memb(_find_in)(cx_iter_t it1, cx_iter_t it2, i_valraw val) {
- c_foreach (it, Self, it1, it2) {
+STC_DEF _cx_iter_t
+_cx_memb(_find_in)(_cx_iter_t it1, _cx_iter_t it2, i_valraw val) {
+ c_foreach (it, _cx_self, it1, it2) {
i_valraw r = i_valto(it.ref);
if (i_cmp(&r, &val) == 0) return it;
}
it2.ref = NULL; return it2;
}
-STC_DEF cx_node_t*
-cx_memb(_erase_after_)(Self* self, cx_node_t* node) {
- cx_node_t* del = node->next, *next = del->next;
+STC_DEF _cx_node_t*
+_cx_memb(_erase_after_)(_cx_self* self, _cx_node_t* node) {
+ _cx_node_t* del = node->next, *next = del->next;
node->next = next;
if (del == next) self->last = node = NULL;
else if (self->last == del) self->last = node, node = NULL;
@@ -255,26 +255,26 @@ cx_memb(_erase_after_)(Self* self, cx_node_t* node) {
}
STC_DEF size_t
-cx_memb(_remove)(Self* self, i_valraw val) {
+_cx_memb(_remove)(_cx_self* self, i_valraw val) {
size_t n = 0;
- cx_node_t* prev = self->last, *node;
+ _cx_node_t* prev = self->last, *node;
while (prev) {
node = prev->next;
i_valraw r = i_valto(&node->value);
if (i_cmp(&r, &val) == 0)
- prev = cx_memb(_erase_after_)(self, prev), ++n;
+ prev = _cx_memb(_erase_after_)(self, prev), ++n;
else
prev = (node == self->last ? NULL : node);
}
return n;
}
-STC_DEF cx_iter_t
-cx_memb(_splice)(Self* self, cx_iter_t it, Self* other) {
+STC_DEF _cx_iter_t
+_cx_memb(_splice)(_cx_self* self, _cx_iter_t it, _cx_self* other) {
if (!self->last)
self->last = other->last;
else if (other->last) {
- cx_node_t *p = it.ref ? it.prev : self->last, *next = p->next;
+ _cx_node_t *p = it.ref ? it.prev : self->last, *next = p->next;
it.prev = other->last;
p->next = it.prev->next;
it.prev->next = next;
@@ -283,11 +283,11 @@ cx_memb(_splice)(Self* self, cx_iter_t it, Self* other) {
other->last = NULL; return it;
}
-STC_DEF Self
-cx_memb(_split_off)(Self* self, cx_iter_t it1, cx_iter_t it2) {
- Self cx = {NULL};
+STC_DEF _cx_self
+_cx_memb(_split_off)(_cx_self* self, _cx_iter_t it1, _cx_iter_t it2) {
+ _cx_self cx = {NULL};
if (it1.ref == it2.ref) return cx;
- cx_node_t *p1 = it1.prev,
+ _cx_node_t *p1 = it1.prev,
*p2 = it2.ref ? it2.prev : self->last;
p1->next = p2->next, p2->next = clist_node_(it1.ref);
if (self->last == p2) self->last = (p1 == p2) ? NULL : p1;
@@ -296,9 +296,9 @@ cx_memb(_split_off)(Self* self, cx_iter_t it1, cx_iter_t it2) {
}
STC_DEF int
-cx_memb(_sort_cmp_)(const clist_VOID_node_t* x, const clist_VOID_node_t* y) {
- i_valraw a = i_valto(&((const cx_node_t *) x)->value);
- i_valraw b = i_valto(&((const cx_node_t *) y)->value);
+_cx_memb(_sort_cmp_)(const clist_VOID_node_t* x, const clist_VOID_node_t* y) {
+ i_valraw a = i_valto(&((const _cx_node_t *) x)->value);
+ i_valraw b = i_valto(&((const _cx_node_t *) y)->value);
return i_cmp(&a, &b);
}
@@ -306,9 +306,9 @@ STC_API clist_VOID_node_t*
_clist_mergesort(clist_VOID_node_t *list, int (*cmp)(const clist_VOID_node_t*, const clist_VOID_node_t*));
STC_DEF void
-cx_memb(_sort)(Self* self) {
+_cx_memb(_sort)(_cx_self* self) {
if (self->last)
- self->last = (cx_node_t *) _clist_mergesort((clist_VOID_node_t *) self->last->next, cx_memb(_sort_cmp_));
+ self->last = (_cx_node_t *) _clist_mergesort((clist_VOID_node_t *) self->last->next, _cx_memb(_sort_cmp_));
}
#endif // TEMPLATE IMPLEMENTATION