From 10e8e2017c8193b784f30a2aeb625f6eb0d3e965 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Wed, 8 Sep 2021 09:05:16 +0200 Subject: Added init_with_capacity(). --- include/stc/cpque.h | 6 +++++- include/stc/cstack.h | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'include') 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]); -- cgit v1.2.3