diff options
| author | Tyge Løvset <[email protected]> | 2021-09-26 18:01:47 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-09-26 18:01:47 +0200 |
| commit | 050675e6a9e62d9a7abf420b6da19a600487181f (patch) | |
| tree | 7c57d787316a77067d51c16f1fcb51f199c7dc08 /include/stc/cpque.h | |
| parent | fdadea4fbdff996e968d920d4fae9f8b73efa74d (diff) | |
| download | STC-modified-050675e6a9e62d9a7abf420b6da19a600487181f.tar.gz STC-modified-050675e6a9e62d9a7abf420b6da19a600487181f.zip | |
Added some extensions to cstack and cpque. cstack can now be used as a vector-lite.
Diffstat (limited to 'include/stc/cpque.h')
| -rw-r--r-- | include/stc/cpque.h | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/include/stc/cpque.h b/include/stc/cpque.h index 7a81d486..642f04cb 100644 --- a/include/stc/cpque.h +++ b/include/stc/cpque.h @@ -51,6 +51,11 @@ STC_INLINE Self cx_memb(_with_capacity)(size_t cap) { return out;
}
+STC_INLINE void cx_memb(_reserve)(Self* self, size_t n) {
+ if (n >= self->size)
+ self->data = (cx_value_t *)c_realloc(self->data, (self->capacity = n)*sizeof(cx_rawvalue_t));
+}
+
STC_INLINE void cx_memb(_clear)(Self* self) {
size_t i = self->size; self->size = 0;
while (i--) i_valdel(&self->data[i]);
@@ -85,17 +90,9 @@ STC_INLINE void cx_memb(_emplace)(Self* self, cx_rawvalue_t raw) STC_INLINE i_val cx_memb(_value_clone)(cx_value_t val)
{ return i_valfrom(i_valto(&val)); }
-STC_INLINE int cx_memb(_value_compare)(const cx_value_t* x, const cx_value_t* y) {
- cx_rawvalue_t rx = i_valto(x), ry = i_valto(y);
- return i_cmp(&rx, &ry);
-}
-
STC_INLINE void
cx_memb(_push_back)(Self* self, cx_value_t value) {
- if (self->size == self->capacity) {
- self->capacity = self->size*3/2 + 4;
- self->data = (cx_value_t *)c_realloc(self->data, self->capacity*sizeof value);
- }
+ if (self->size == self->capacity) cx_memb(_reserve)(self, self->size*3/2 + 4);
self->data[ self->size++ ] = value;
}
|
