summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-09-10 21:34:52 +0200
committerTyge Løvset <[email protected]>2022-09-10 21:34:52 +0200
commitd6a4bdb81312d5e3b1894d261932002b57f4c830 (patch)
tree3d512063d89d933397abf337d24bd7198ce8ded9 /include
parentab073505ad044e95cf83cc89effe992707a02c4d (diff)
downloadSTC-modified-d6a4bdb81312d5e3b1894d261932002b57f4c830.tar.gz
STC-modified-d6a4bdb81312d5e3b1894d261932002b57f4c830.zip
Internal renamings to discourage use of private struct fields.
Diffstat (limited to 'include')
-rw-r--r--include/stc/cpque.h32
-rw-r--r--include/stc/cstack.h56
-rw-r--r--include/stc/forward.h6
3 files changed, 47 insertions, 47 deletions
diff --git a/include/stc/cpque.h b/include/stc/cpque.h
index bfc09106..183390c4 100644
--- a/include/stc/cpque.h
+++ b/include/stc/cpque.h
@@ -46,13 +46,13 @@ STC_INLINE _cx_self _cx_memb(_init)(void)
{ return c_make(_cx_self){NULL}; }
STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, const size_t cap) {
- if (cap != self->size && cap <= self->capacity) return true;
+ if (cap != self->_len && cap <= self->_cap) return true;
_cx_value *d = (_cx_value *)c_realloc(self->data, cap*sizeof *d);
- return d ? (self->data = d, self->capacity = cap, true) : false;
+ return d ? (self->data = d, self->_cap = cap, true) : false;
}
STC_INLINE void _cx_memb(_shrink_to_fit)(_cx_self* self)
- { _cx_memb(_reserve)(self, self->size); }
+ { _cx_memb(_reserve)(self, self->_len); }
STC_INLINE _cx_self _cx_memb(_with_capacity)(const size_t cap) {
_cx_self out = {NULL}; _cx_memb(_reserve)(&out, cap);
@@ -61,12 +61,12 @@ STC_INLINE _cx_self _cx_memb(_with_capacity)(const size_t cap) {
STC_INLINE _cx_self _cx_memb(_with_size)(const size_t size, i_key null) {
_cx_self out = {NULL}; _cx_memb(_reserve)(&out, size);
- while (out.size < size) out.data[out.size++] = null;
+ while (out._len < size) out.data[out._len++] = null;
return out;
}
STC_INLINE void _cx_memb(_clear)(_cx_self* self) {
- size_t i = self->size; self->size = 0;
+ size_t i = self->_len; self->_len = 0;
while (i--) { i_keydrop((self->data + i)); }
}
@@ -74,13 +74,13 @@ STC_INLINE void _cx_memb(_drop)(_cx_self* self)
{ _cx_memb(_clear)(self); c_free(self->data); }
STC_INLINE size_t _cx_memb(_size)(const _cx_self* q)
- { return q->size; }
+ { return q->_len; }
STC_INLINE bool _cx_memb(_empty)(const _cx_self* q)
- { return !q->size; }
+ { return !q->_len; }
STC_INLINE size_t _cx_memb(_capacity)(const _cx_self* q)
- { return q->capacity; }
+ { return q->_cap; }
STC_INLINE const _cx_value* _cx_memb(_top)(const _cx_self* self)
{ return &self->data[0]; }
@@ -119,7 +119,7 @@ _cx_memb(_sift_down_)(_cx_value* arr, const size_t idx, const size_t n) {
STC_DEF void
_cx_memb(_make_heap)(_cx_self* self) {
- size_t n = self->size;
+ size_t n = self->_len;
_cx_value *arr = self->data - 1;
for (size_t k = n/2; k != 0; --k)
_cx_memb(_sift_down_)(arr, k, n);
@@ -127,9 +127,9 @@ _cx_memb(_make_heap)(_cx_self* self) {
#if !defined _i_no_clone
STC_DEF _cx_self _cx_memb(_clone)(_cx_self q) {
- _cx_self out = _cx_memb(_with_capacity)(q.size);
- for (; out.size < out.capacity; ++q.data)
- out.data[out.size++] = i_keyclone((*q.data));
+ _cx_self out = _cx_memb(_with_capacity)(q._len);
+ for (; out._len < out._cap; ++q.data)
+ out.data[out._len++] = i_keyclone((*q.data));
return out;
}
#endif
@@ -137,17 +137,17 @@ STC_DEF _cx_self _cx_memb(_clone)(_cx_self q) {
STC_DEF void
_cx_memb(_erase_at)(_cx_self* self, const size_t idx) {
i_keydrop((self->data + idx));
- const size_t n = --self->size;
+ const size_t n = --self->_len;
self->data[idx] = self->data[n];
_cx_memb(_sift_down_)(self->data - 1, idx + 1, n);
}
STC_DEF void
_cx_memb(_push)(_cx_self* self, _cx_value value) {
- if (self->size == self->capacity)
- _cx_memb(_reserve)(self, self->size*3/2 + 4);
+ if (self->_len == self->_cap)
+ _cx_memb(_reserve)(self, self->_len*3/2 + 4);
_cx_value *arr = self->data - 1; /* base 1 */
- size_t c = ++self->size;
+ size_t c = ++self->_len;
for (; c > 1 && (i_less((&arr[c/2]), (&value))); c /= 2)
arr[c] = arr[c/2];
arr[c] = value;
diff --git a/include/stc/cstack.h b/include/stc/cstack.h
index 921e6618..98d21e13 100644
--- a/include/stc/cstack.h
+++ b/include/stc/cstack.h
@@ -44,19 +44,19 @@
typedef i_keyraw _cx_raw;
STC_INLINE _cx_self _cx_memb(_init)(void) {
- _cx_self s; s.size = 0;
+ _cx_self s; s._len = 0;
#ifndef i_cap
- s.capacity = 0; s.data = NULL;
+ s._cap = 0; s.data = NULL;
#endif
return s;
}
#ifdef i_cap
STC_INLINE void _cx_memb(_inits)(_cx_self* self)
- { self->size = 0; }
+ { self->_len = 0; }
#else
STC_INLINE void _cx_memb(_inits)(_cx_self* self)
- { self->size = 0; self->capacity = 0; self->data = NULL; }
+ { self->_len = 0; self->_cap = 0; self->data = NULL; }
STC_INLINE _cx_self _cx_memb(_with_capacity)(size_t cap) {
_cx_self out = {(_cx_value *) c_malloc(cap*sizeof(i_key)), 0, cap};
@@ -71,9 +71,9 @@ STC_INLINE _cx_self _cx_memb(_with_size)(size_t size, i_key null) {
#endif
STC_INLINE void _cx_memb(_clear)(_cx_self* self) {
- _cx_value *p = self->data + self->size;
+ _cx_value *p = self->data + self->_len;
while (p-- != self->data) { i_keydrop(p); }
- self->size = 0;
+ self->_len = 0;
}
STC_INLINE void _cx_memb(_drop)(_cx_self* self) {
@@ -84,63 +84,63 @@ STC_INLINE void _cx_memb(_drop)(_cx_self* self) {
}
STC_INLINE size_t _cx_memb(_size)(const _cx_self* self)
- { return self->size; }
+ { return self->_len; }
STC_INLINE bool _cx_memb(_empty)(const _cx_self* self)
- { return !self->size; }
+ { return !self->_len; }
STC_INLINE size_t _cx_memb(_capacity)(const _cx_self* self) {
#ifndef i_cap
- return self->capacity;
+ return self->_cap;
#else
return i_cap;
#endif
}
STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, size_t n) {
- if (n < self->size) return true;
+ if (n < self->_len) return true;
#ifndef i_cap
_cx_value *t = (_cx_value *)c_realloc(self->data, n*sizeof *t);
- if (t) { self->capacity = n, self->data = t; return true; }
+ if (t) { self->_cap = n, self->data = t; return true; }
#endif
return false;
}
STC_INLINE _cx_value*
_cx_memb(_append_uninit)(_cx_self *self, size_t n) {
- size_t len = self->size;
+ size_t len = self->_len;
if (!_cx_memb(_reserve)(self, len + n)) return NULL;
- self->size += n;
+ self->_len += n;
return self->data + len;
}
STC_INLINE void _cx_memb(_shrink_to_fit)(_cx_self* self)
- { _cx_memb(_reserve)(self, self->size); }
+ { _cx_memb(_reserve)(self, self->_len); }
STC_INLINE const _cx_value* _cx_memb(_top)(const _cx_self* self)
- { return &self->data[self->size - 1]; }
+ { return &self->data[self->_len - 1]; }
STC_INLINE _cx_value* _cx_memb(_back)(const _cx_self* self)
- { return (_cx_value*) &self->data[self->size - 1]; }
+ { return (_cx_value*) &self->data[self->_len - 1]; }
STC_INLINE _cx_value* _cx_memb(_front)(const _cx_self* self)
{ return (_cx_value*) &self->data[0]; }
STC_INLINE _cx_value* _cx_memb(_push)(_cx_self* self, _cx_value val) {
- if (self->size == _cx_memb(_capacity)(self))
- if (!_cx_memb(_reserve)(self, self->size*3/2 + 4))
+ if (self->_len == _cx_memb(_capacity)(self))
+ if (!_cx_memb(_reserve)(self, self->_len*3/2 + 4))
return NULL;
- _cx_value* vp = self->data + self->size++;
+ _cx_value* vp = self->data + self->_len++;
*vp = val; return vp;
}
STC_INLINE void _cx_memb(_pop)(_cx_self* self)
- { _cx_value* p = &self->data[--self->size]; i_keydrop(p); }
+ { _cx_value* p = &self->data[--self->_len]; i_keydrop(p); }
STC_INLINE const _cx_value* _cx_memb(_at)(const _cx_self* self, size_t idx)
- { assert(idx < self->size); return self->data + idx; }
+ { assert(idx < self->_len); return self->data + idx; }
STC_INLINE _cx_value* _cx_memb(_at_mut)(_cx_self* self, size_t idx)
- { assert(idx < self->size); return self->data + idx; }
+ { assert(idx < self->_len); return self->data + idx; }
#if !defined _i_no_emplace
STC_INLINE _cx_value* _cx_memb(_emplace)(_cx_self* self, _cx_raw raw)
@@ -149,9 +149,9 @@ STC_INLINE _cx_value* _cx_memb(_emplace)(_cx_self* self, _cx_raw raw)
#if !defined _i_no_clone
STC_INLINE _cx_self _cx_memb(_clone)(_cx_self v) {
- _cx_self out = {(_cx_value *)c_malloc(v.size*sizeof(_cx_value)), v.size, v.size};
- if (!out.data) out.capacity = 0;
- else for (size_t i = 0; i < v.size; ++v.data)
+ _cx_self out = {(_cx_value *)c_malloc(v._len*sizeof(_cx_value)), v._len, v._len};
+ if (!out.data) out._cap = 0;
+ else for (size_t i = 0; i < v._len; ++v.data)
out.data[i++] = i_keyclone((*v.data));
return out;
}
@@ -170,12 +170,12 @@ STC_INLINE i_keyraw _cx_memb(_value_toraw)(const _cx_value* val)
#endif // !_i_no_clone
STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) {
- return c_make(_cx_iter){self->size ? (_cx_value*)self->data : NULL,
- (_cx_value*)self->data + self->size};
+ return c_make(_cx_iter){self->_len ? (_cx_value*)self->data : NULL,
+ (_cx_value*)self->data + self->_len};
}
STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self)
- { return c_make(_cx_iter){NULL, (_cx_value*)self->data + self->size}; }
+ { return c_make(_cx_iter){NULL, (_cx_value*)self->data + self->_len}; }
STC_INLINE void _cx_memb(_next)(_cx_iter* it)
{ if (++it->ref == it->end) it->ref = NULL; }
diff --git a/include/stc/forward.h b/include/stc/forward.h
index 264d6939..167d1539 100644
--- a/include/stc/forward.h
+++ b/include/stc/forward.h
@@ -189,7 +189,7 @@ typedef union {
typedef struct { SELF##_value *ref, *end; } SELF##_iter; \
typedef struct SELF { \
SELF##_value* data; \
- size_t size, capacity; \
+ size_t _len, _cap; \
} SELF
#define _c_cstack_fixed(SELF, VAL, CAP) \
@@ -197,14 +197,14 @@ typedef union {
typedef struct { SELF##_value *ref, *end; } SELF##_iter; \
typedef struct SELF { \
SELF##_value data[CAP]; \
- size_t size; \
+ size_t _len; \
} SELF
#define _c_cpque_types(SELF, VAL) \
typedef VAL SELF##_value; \
typedef struct SELF { \
SELF##_value* data; \
- size_t size, capacity; \
+ size_t _len, _cap; \
} SELF
#define _c_cvec_types(SELF, VAL) \