some progress or whatever (still WIP)

This commit is contained in:
2026-03-31 22:00:09 +02:00
parent 253e095e4d
commit da4de1c560
2 changed files with 24 additions and 5 deletions
+4
View File
@@ -15,6 +15,10 @@ typedef union any_align { char c; int i; long l; long long ll; float f; double d
#define MB (KB * KB) #define MB (KB * KB)
#define GB (KB * KB * KB) #define GB (KB * KB * KB)
#define PTR_FROM_FIELD_PTR(STRUCT, FIELD, PTR) ((STRUCT *) (((char *) PTR) - offsetof(STRUCT, FIELD))) #define PTR_FROM_FIELD_PTR(STRUCT, FIELD, PTR) ((STRUCT *) (((char *) PTR) - offsetof(STRUCT, FIELD)))
#define TODO(...) do { \
fprintf(stderr, "%s:%d: TODO: %s", __FILE__, (int)__LINE__, #__VA_ARGS__);\
exit(1); \
} while (0)
// Contains all operations an allocator can do. Similar interface to sdtlibs // Contains all operations an allocator can do. Similar interface to sdtlibs
// malloc, realloc and free. // malloc, realloc and free.
+20 -5
View File
@@ -74,17 +74,32 @@ void *map_grow_func(void *this, const char *file, int line) {
header->itemsize header->itemsize
); );
header = allocator_resize_func(allocator, header, new_size.bytes, file, line); header = allocator_resize_func(allocator, header, new_size.bytes, file, line);
// TODO!!! Overwrite the mapping arr with -1, then iterate through the
// items arr and find the hashes of the values to populate the mappings TODO(
// arr. Overwrite the mapping arr with -1, then iterate through the items
assert(false && "TODO"); arr and find the hashes of the values to populate the mappings
TODO );
} }
header->n_items = new_size; header->n_items = new_size;
return header->bytes; return header->bytes;
} }
void map_shrink_func(void *this, const char *file, int line) {
if (map_len(this) <= 0) {
fprintf(
stderr,
"%s:%d: tried to shrink map of size 0.\n",
file,
line
);
exit(1);
}
map_header_t *header = PTR_FROM_FIELD_PTR(map_header_t, bytes, this);
header->n_items--;
TODO(Hash the key at the removed item to find it in the mapping array, and set it to the gravestone value.);
}
int map_len(void *this) { int map_len(void *this) {
if (this == NULL) { if (this == NULL) {
return 0; return 0;