From 51980ebb0b5d220c0e2c7bffe853d4d3e2628a56 Mon Sep 17 00:00:00 2001 From: Timerix Date: Thu, 24 Jul 2025 17:45:22 +0300 Subject: [PATCH] renamed some collection functions --- include/tlibc/collections/HashMap.h | 4 +++- include/tlibc/collections/List.h | 8 ++++---- src/collections/HashMap.c | 3 ++- src/collections/List.c | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/tlibc/collections/HashMap.h b/include/tlibc/collections/HashMap.h index 850df38..1c00071 100755 --- a/include/tlibc/collections/HashMap.h +++ b/include/tlibc/collections/HashMap.h @@ -26,7 +26,9 @@ typedef struct HashMap_ { u16 height_n; } HashMap_; -void HashMap_create(HashMap_* ptr, u32 value_t_size, FreeFunction NULLABLE(value_destructor)); +//TODO: standartize constructor function names across tlibc +#define HashMap_create(PTR, T, VALUE_DESTRUCTOR) HashMap_create_size(PTR, sizeof(T), VALUE_DESTRUCTOR) +void HashMap_create_size(HashMap_* ptr, u32 value_t_size, FreeFunction NULLABLE(value_destructor)); void HashMap_destroy(HashMap_* ptr); void* NULLABLE(HashMap_tryGetPtr)(HashMap_* ptr, str key); bool HashMap_tryPush(HashMap_* ptr, str key, void* value_ptr); diff --git a/include/tlibc/collections/List.h b/include/tlibc/collections/List.h index 84f7fca..fff8134 100755 --- a/include/tlibc/collections/List.h +++ b/include/tlibc/collections/List.h @@ -9,7 +9,7 @@ typedef struct List_ { u32 allocated_size; } List_; -#define List_construct(DATA_PTR, T, OCCUPIED_COUNT, ALLOCATED_COUNT) \ +#define List_construct(T, DATA_PTR, OCCUPIED_COUNT, ALLOCATED_COUNT) \ List_construct_size(DATA_PTR, (OCCUPIED_COUNT) * sizeof(T), (ALLOCATED_COUNT) * sizeof(T)) static inline List_ List_construct_size(void* data_ptr, u32 occupied_size, u32 allocated_size) { @@ -19,12 +19,12 @@ static inline List_ List_construct_size(void* data_ptr, u32 occupied_size, u32 a #define List_alloc(T, INITIAL_COUNT) List_alloc_size((INITIAL_COUNT) * sizeof(T)) List_ List_alloc_size(u32 initial_size); -void* List_expand(List_* ptr, u32 expansion_size); -#define List_push(L, T, VALUE) *(T*)(List_expand(L, sizeof(T))) = VALUE +void* List_expand_size(List_* ptr, u32 expansion_size); +#define List_push(L, T, VALUE) *(T*)(List_expand_size(L, sizeof(T))) = VALUE #define List_pushMany(L, T, VALUES_PTR, COUNT) List_push_size(L, VALUES_PTR, (COUNT) * sizeof(T)) void List_push_size(List_* ptr, void* values, u32 size); #define List_removeAt(L, T, I, COUNT) List_removeAt_size(L, (I)*sizeof(T), (COUNT) * sizeof(T)) bool List_removeAt_size(List_* ptr, u32 i, u32 remove_size); -#define List_len(L, T) ((L)->size / sizeof(T)) \ No newline at end of file +#define List_len(L, T) ((L)->size / sizeof(T)) diff --git a/src/collections/HashMap.c b/src/collections/HashMap.c index 2839f69..2d8f9fb 100755 --- a/src/collections/HashMap.c +++ b/src/collections/HashMap.c @@ -12,7 +12,8 @@ static const Array(u32) __HashMap_heights = ARRAY(u32, { 8388617, 16777213, 33554467, 67108859, 134217757, 268435493 }); -void HashMap_create(HashMap_* ptr, u32 value_t_size, FreeFunction NULLABLE(value_destructor)){ + +void HashMap_create_size(HashMap_* ptr, u32 value_t_size, FreeFunction NULLABLE(value_destructor)){ ptr->value_t_size = value_t_size; ptr->value_destructor = value_destructor; ptr->height_n = 0; diff --git a/src/collections/List.c b/src/collections/List.c index e6a92c0..18dffaa 100755 --- a/src/collections/List.c +++ b/src/collections/List.c @@ -7,7 +7,7 @@ List_ List_alloc_size(u32 initial_size){ return List_construct_size(malloc(allocated_size), 0, allocated_size); } -void* List_expand(List_* ptr, u32 expansion_size){ +void* List_expand_size(List_* ptr, u32 expansion_size){ u32 occupied_size = ptr->size; u32 expanded_alloc_size = ptr->allocated_size; if(expanded_alloc_size == 0) @@ -23,7 +23,7 @@ void* List_expand(List_* ptr, u32 expansion_size){ } void List_push_size(List_* ptr, void* values, u32 size){ - void* empty_cell_ptr = List_expand(ptr, size); + void* empty_cell_ptr = List_expand_size(ptr, size); memcpy(empty_cell_ptr, values, size); }