diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2019-09-01 15:21:25 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2019-09-01 15:21:25 -0400 |
commit | cc7d494226f41d76208bd2a0613a26435247cc87 (patch) | |
tree | 77ba93bae293ea2e2299ab54bea5c0f58065bce0 /util | |
parent | 8640ec94e95156551ce90a8fe4d96eddc6e66f88 (diff) |
improved the way identifiers worked (now they use a single block array)
Diffstat (limited to 'util')
-rw-r--r-- | util/blockarr.c | 15 | ||||
-rw-r--r-- | util/err.c | 16 |
2 files changed, 16 insertions, 15 deletions
diff --git a/util/blockarr.c b/util/blockarr.c index c85df5a..03d44b2 100644 --- a/util/blockarr.c +++ b/util/blockarr.c @@ -21,13 +21,13 @@ typedef struct { Note: the block size must be a power of 2, to use right shifting instead of division (for optimization)! */ -void block_arr_create(BlockArr *arr, int lg_block_sz, size_t item_sz) { +static void block_arr_create(BlockArr *arr, int lg_block_sz, size_t item_sz) { arr_create(&arr->blocks, sizeof(ArrBlock)); arr->item_sz = item_sz; arr->lg_block_sz = lg_block_sz; } -void *block_arr_add(BlockArr *arr) { +static void *block_arr_add(BlockArr *arr) { ArrBlock *last_block; last_block = arr_last(&arr->blocks); @@ -46,12 +46,13 @@ void *block_arr_add(BlockArr *arr) { } } -/* Don't need this yet. */ -/* void *block_arr_get(BlockArr *arr, size_t index) { */ - -/* } */ +static inline void *block_arr_get(BlockArr *arr, size_t index) { + size_t block_index = index >> arr->lg_block_sz; + ArrBlock *block = (ArrBlock*)arr->blocks.data + block_index; + return (char*)block->data + arr->item_sz * index; +} -void block_arr_free(BlockArr *arr) { +static void block_arr_free(BlockArr *arr) { arr_foreach(&arr->blocks, ArrBlock, block) { free(block->data); } @@ -111,14 +111,14 @@ static void *err_malloc(size_t size) { return ret; } -static void *err_calloc(size_t n, size_t size) { - void *ret = calloc(n, size); - if (!ret) { - fprintf(stderr, "Error: Out of memory.\n"); - abort(); - } - return ret; -} +/* static void *err_calloc(size_t n, size_t size) { */ +/* void *ret = calloc(n, size); */ +/* if (!ret) { */ +/* fprintf(stderr, "Error: Out of memory.\n"); */ +/* abort(); */ +/* } */ +/* return ret; */ +/* } */ static void *err_realloc(void *data, size_t new_size) { void *ret = realloc(data, new_size); |