summaryrefslogtreecommitdiff
path: root/util/blockarr.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/blockarr.c')
-rw-r--r--util/blockarr.c15
1 files changed, 8 insertions, 7 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);
}