diff options
| author | Tyge Løvset <[email protected]> | 2021-09-08 09:05:16 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-09-08 09:05:16 +0200 |
| commit | 10e8e2017c8193b784f30a2aeb625f6eb0d3e965 (patch) | |
| tree | 2ba2d17b36bd12c38afd675bdb8db9565cc4631f /include | |
| parent | f16e08017abfc44864b37a42c42951f0fd885f5f (diff) | |
| download | STC-modified-10e8e2017c8193b784f30a2aeb625f6eb0d3e965.tar.gz STC-modified-10e8e2017c8193b784f30a2aeb625f6eb0d3e965.zip | |
Added init_with_capacity().
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/cpque.h | 6 | ||||
| -rw-r--r-- | include/stc/cstack.h | 5 |
2 files changed, 10 insertions, 1 deletions
diff --git a/include/stc/cpque.h b/include/stc/cpque.h index 3f3bc515..d7590a85 100644 --- a/include/stc/cpque.h +++ b/include/stc/cpque.h @@ -45,6 +45,11 @@ STC_API Self cx_memb(_clone)(Self q); STC_INLINE Self cx_memb(_init)(void)
{ return (Self){0, 0, 0}; }
+STC_INLINE Self cx_memb(_init_with_capacity)(size_t cap) {
+ Self out = {(cx_value_t *) c_malloc(cap*sizeof(cx_value_t)), 0, cap};
+ return out;
+}
+
STC_INLINE void cx_memb(_clear)(Self* self) {
size_t i = self->size; self->size = 0;
while (i--) i_valdel(&self->data[i]);
@@ -116,7 +121,6 @@ STC_INLINE Self cx_memb(_clone)(Self q) { return out;
}
-
STC_DEF void
cx_memb(_erase_at)(Self* self, size_t idx) {
size_t n = cx_memb(_size)(*self) - 1;
diff --git a/include/stc/cstack.h b/include/stc/cstack.h index f68a01d7..448b6c2f 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -39,6 +39,11 @@ typedef i_valraw cx_rawvalue_t; STC_INLINE Self cx_memb(_init)(void)
{ return (Self){0, 0, 0}; }
+STC_INLINE Self cx_memb(_init_with_capacity)(size_t cap) {
+ Self out = {(cx_value_t *) c_malloc(cap*sizeof(cx_value_t)), 0, cap};
+ return out;
+}
+
STC_INLINE void cx_memb(_clear)(Self* self) {
size_t i = self->size; self->size = 0;
while (i--) i_valdel(&self->data[i]);
|
