From: bdemsky Date: Tue, 20 Jun 2017 21:19:01 +0000 (-0700) Subject: Make vectors work well inline X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=2e26de133c138661c9981d4b93364e5dfd83c1d6;p=satune.git Make vectors work well inline --- diff --git a/src/Collections/vector.h b/src/Collections/vector.h index f3b45f8..fa1764e 100644 --- a/src/Collections/vector.h +++ b/src/Collections/vector.h @@ -19,7 +19,10 @@ void deleteVector ## name(Vector ## name *vector); \ void clearVector ## name(Vector ## name *vector); \ void deleteVectorArray ## name(Vector ## name *vector); \ - type * exposeArray ## name(Vector ## name * vector); + type * exposeArray ## name(Vector ## name * vector); \ + void allocInlineVector ## name(Vector ## name * vector, uint capacity); \ + void allocInlineDefVector ## name(Vector ## name * vector); \ + void allocInlineVectorArray ## name(Vector ## name * vector, uint capacity, type * array); #define VectorImpl(name, type, defcap) \ Vector ## name * allocDefVector ## name() { \ @@ -65,5 +68,17 @@ } \ void deleteVectorArray ## name(Vector ## name *vector) { \ ourfree(vector->array); \ + } \ + void allocInlineVector ## name(Vector ## name * vector, uint capacity) { \ + vector->size = 0; \ + vector->capacity = capacity; \ + vector->array = (type *) ourcalloc(1, sizeof(type) * capacity); \ + } \ + void allocInlineDefVector ## name(Vector ## name * vector) { \ + allocInlineVector ## name(vector, defcap); \ + } \ + void allocInlineVectorArray ## name(Vector ## name * vector, uint capacity, type * array) { \ + allocInlineVector ##name(vector, capacity); \ + memcpy(vector->array, array, capacity * sizeof(type)); \ } #endif