some progress, but broken
This commit is contained in:
@@ -280,7 +280,7 @@ void *map_create_func(map_create_func_args_t args);
|
||||
}); \
|
||||
} while(0)
|
||||
|
||||
#define init_set(PTR, ...) do { \
|
||||
#define set_init(PTR, ...) do { \
|
||||
(*(PTR)) = map_create_func((map_create_func_args_t) { \
|
||||
.item_size=sizeof(*(*(PTR))), \
|
||||
.key_size=sizeof(*(*(PTR))), \
|
||||
@@ -291,8 +291,12 @@ void *map_create_func(map_create_func_args_t args);
|
||||
}); \
|
||||
} while(0)
|
||||
|
||||
int map_len(void *this);
|
||||
int map_cap(void *this);
|
||||
int map_len_func(void *this);
|
||||
#define map_len(THIS) map_len_func((void*) THIS)
|
||||
|
||||
int map_cap_func(void *this);
|
||||
#define map_cap(THIS) map_cap_func((void*) THIS)
|
||||
|
||||
uint32_t fnv_1a(const uint8_t *bytes, const unsigned int size);
|
||||
// Used for debugging the mapping array. Prints out nerdfonts icons to indicate
|
||||
// the state of each mapping slot.
|
||||
@@ -314,10 +318,13 @@ typedef struct index_pair {
|
||||
*/
|
||||
index_pair_t map_pair_hash(void *this, void *pair);
|
||||
|
||||
// TODO: NOT DONE
|
||||
#define map_add(THIS, PAIR) do { \
|
||||
map_assure_growable_by_1(THIS, __FILE__, __LINE__); \
|
||||
index_pair_t idx_pair = map_pair_hash((*(THIS)), pair); \
|
||||
// TODO: NOT DONE!!! FIRST try to get the existing in
|
||||
#define set_add(THIS, VALUE) do { \
|
||||
map_assure_growable_by_1((void**)THIS, __FILE__, __LINE__); \
|
||||
unsigned int len = map_len(*(THIS)); \
|
||||
(*(THIS))[len] = VALUE; \
|
||||
index_pair_t idx_pair = map_pair_hash((*(THIS)), &(*(THIS))[len]); \
|
||||
(*(THIS))[map_place((*(THIS)), idx_pair)] = VALUE; \
|
||||
} while (0)
|
||||
|
||||
// CLI /////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
int main() {
|
||||
with_borrow(allocator) {
|
||||
int *ints;
|
||||
init_set(&ints, allocator, .initial_capacity=20);
|
||||
set_init(&ints, allocator, .initial_capacity=20);
|
||||
map_print_mapping_state(ints, stdout);
|
||||
set_add(ints, 10);
|
||||
for ( int i = 0; i < 100; i++ ) {
|
||||
set_add(&ints, i);
|
||||
map_print_mapping_state(ints, stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ bool map_key_equals(void *this, const void *key1, const void *key2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int map_place(void *this, index_pair_t idx_pair) {
|
||||
unsigned int map_place(void *this, index_pair_t idx_pair) {
|
||||
map_header_t *header = PTR_FROM_FIELD_PTR(map_header_t, bytes, this);
|
||||
if (idx_pair.has_old_index) {
|
||||
header->mapping_arr[idx_pair.new_index] = header->mapping_arr[idx_pair.old_index];
|
||||
@@ -129,10 +129,11 @@ int map_place(void *this, index_pair_t idx_pair) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
header->mapping_arr[idx_pair.new_index] = header->n_items;
|
||||
}
|
||||
// TODO WRONG!!!
|
||||
|
||||
return idx_pair.new_index;
|
||||
return header->mapping_arr[idx_pair.new_index];
|
||||
}
|
||||
|
||||
index_pair_t map_pair_hash(void *this, void *pair) {
|
||||
@@ -249,7 +250,7 @@ uint32_t fnv_1a(const uint8_t *bytes, const unsigned int size) {
|
||||
return hash;
|
||||
}
|
||||
|
||||
int map_len(void *this) {
|
||||
int map_len_func(void *this) {
|
||||
if (this == NULL) {
|
||||
return 0;
|
||||
}
|
||||
@@ -257,7 +258,7 @@ int map_len(void *this) {
|
||||
return header->n_items;
|
||||
}
|
||||
|
||||
int map_cap(void *this) {
|
||||
int map_cap_func(void *this) {
|
||||
if (this == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user