a little bit of this. a little bit of that (hashmap stuff)

This commit is contained in:
2026-02-26 20:14:44 +01:00
parent fbb340d465
commit 0f7f092ad3
2 changed files with 27 additions and 20 deletions
+2 -1
View File
@@ -9,7 +9,8 @@
#include <string.h>
typedef union any_align { char c; int i; long l; long long ll; float f; double d; void *p; long double ld; } any_align_t;
#define MAX_ALIGN ((size_t) sizeof(any_align_t))
#define ALIGN_OF(TYPE) ((size_t)(&((struct{char c; TYPE t;}*) 0)->t))
#define MAX_ALIGN (ALIGN_OF(any_align_t))
#define KB (1024)
#define MB (KB * KB)
#define GB (KB * KB * KB)
+15 -9
View File
@@ -1,20 +1,22 @@
#include "cig.h"
static inline int mapping_cap(int capacity) {
return capacity * 2;
}
void *hashmap_create_func(
hashmap_create_func_args_t args
) {
size_t size_of_index_arr = sizeof(int) * args.initial_capacity * 2;
size_t INC = sizeof(any_align_t);
size_t size_of_index_arr = sizeof(int) * mapping_cap(args.initial_capacity);
size_t INC = ALIGN_OF(int);
size_t SIZE = args.itemsize * args.initial_capacity;
size_t size_of_items_arr = (SIZE + INC - 1) / INC;
size_t bytes = sizeof(hashmap_header_t) + size_of_items_arr + size_of_index_arr;
size_t bytes =
sizeof(hashmap_header_t) + size_of_items_arr + size_of_index_arr;
hashmap_header_t *header = allocator_alloc_func(
args.allocator,
bytes,
args.file,
args.line
);
hashmap_header_t *header =
allocator_alloc_func(args.allocator, bytes, args.file, args.line);
header->n_items = 0;
header->capacity = args.initial_capacity;
@@ -26,3 +28,7 @@ void *hashmap_create_func(
return header->bytes;
}
int *hashmap_get_mapping_arr(hashmap_header_t *this) {
// TODO
}