From d256e06f518d701413dfb9bff6d00504f8c88109 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Tue, 9 Apr 2024 21:21:12 +0630 Subject: Mid-work through documenting darr.h --- lib/darr.h | 19 +++++++++++++++++-- todo.org | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/darr.h b/lib/darr.h index 02938da..aa37d27 100644 --- a/lib/darr.h +++ b/lib/darr.h @@ -18,14 +18,29 @@ #include "./base.h" +/** + * A dynamically sized buffer of bytes which may be used for a + * variety of purposes. + * @prop data: Buffer of bytes (may be reallocated) + * @prop used: Number of bytes currently used + * @prop available: Number of bytes currently allocated + */ typedef struct { byte *data; size_t used, available; } darr_t; -#define DARR_DEFAULT_SIZE 8 -#define DARR_REALLOC_MULT 1.5 +/* Some useful constants for dynamic array work. */ +#define DARR_DEFAULT_SIZE 8 +#define DARR_REALLOC_MULT 1.5 + +/** Get the INDth item in a darr, where the buffer of bytes is + * considerd an array of type TYPE. + * Unsafe operation as safety checks are not done (in particular if + * the dynamic array has IND items or is big enough to store an + * element of TYPE) so it is presumed the caller will. + */ #define DARR_AT(TYPE, DARR_DATA, IND) ((TYPE *)(DARR_DATA))[(IND)] void darr_init(darr_t *, size_t); diff --git a/todo.org b/todo.org index bf15bb2..82beb04 100644 --- a/todo.org +++ b/todo.org @@ -6,7 +6,7 @@ ** TODO Comment coverage [0%] *** WIP Lib [25%] **** DONE lib/base.h -**** TODO lib/darr.h +**** WIP lib/darr.h **** TODO lib/heap.h **** TODO lib/inst.h *** TODO ASM [0%] -- cgit v1.2.3-13-gbd6f