From 9b91c0690b1d9122351524129677c7faef363ce0 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 31 Oct 2016 19:45:05 -0700 Subject: [PATCH] . --- util.c | 12 ++++++------ util.h | 11 +++-------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/util.c b/util.c index dce901d..e5776c0 100644 --- a/util.c +++ b/util.c @@ -18,19 +18,19 @@ #include "util.h" -void array_init(Array* arr, size_t init_size) { - arr->ptr = (Entry *)malloc(init_size * sizeof(Entry)); +void array_init(Array* arr, size_t size) { + arr->ptr = calloc(size, sizeof(void*)); arr->used = 0; - arr->size = init_size; + arr->size = size; } -Entry* array_new(Array* arr) { +void array_push(Array* arr, void* data) { if (arr->used == arr->size) { arr->size *= 2; - arr->ptr = (Entry *)realloc(arr->ptr, arr->size * sizeof(Entry)); + arr->ptr = realloc(arr->ptr, arr->size * sizeof(void*)); } - return &arr->ptr[arr->used++]; + arr->ptr[arr->used++] = data; } void array_free(Array* arr) { diff --git a/util.h b/util.h index da81ffe..88516e2 100644 --- a/util.h +++ b/util.h @@ -22,18 +22,13 @@ #include typedef struct { - char* header; - char* text; -} Entry; - -typedef struct { - Entry* ptr; + void** ptr; size_t used; size_t size; } Array; -void array_init(Array* arr, size_t init_size); -Entry* array_new(Array* arr); +void array_init(Array* arr, size_t size); +void array_push(Array* arr, void* data); void array_free(Array* arr); #endif