add debugging function
want to visualize the mapping array of maps to see that they work as intended
This commit is contained in:
@@ -294,6 +294,9 @@ void *map_create_func(map_create_func_args_t args);
|
|||||||
int map_len(void *this);
|
int map_len(void *this);
|
||||||
int map_cap(void *this);
|
int map_cap(void *this);
|
||||||
uint32_t fnv_1a(const uint8_t *bytes, const unsigned int size);
|
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.
|
||||||
|
void map_print_mapping_state(void *this, FILE *file);
|
||||||
|
|
||||||
// CLI /////////////////////////////////////////////////////////////////////////
|
// CLI /////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,39 @@
|
|||||||
#include "cig.h"
|
#include "cig.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#define FLAG_FREE (-1)
|
#define FLAG_FREE (-1)
|
||||||
#define FLAG_TOMBSTONE (-2)
|
#define FLAG_TOMBSTONE (-2)
|
||||||
|
|
||||||
|
|
||||||
// TODO: when setting a key to a gravestone, then while the mapping
|
// TODO: when setting a key to a gravestone, then while the mapping
|
||||||
// item to the right is FLAG_FREE, you can set this one to FLAG_FREE,
|
// item to the right is FLAG_FREE, you can set this one to FLAG_FREE,
|
||||||
// go one index less, and if that is also a FLAG_GRAVESTONE, you can
|
// go one index less, and if that is also a FLAG_GRAVESTONE, you can
|
||||||
// continue the process.
|
// continue the process.
|
||||||
|
|
||||||
|
#define ESC "\033["
|
||||||
|
#define RED ESC "31m"
|
||||||
|
#define DEFAULT ESC "0m"
|
||||||
|
#define COLORED(COLOR, TEXT) COLOR TEXT DEFAULT
|
||||||
|
|
||||||
|
void map_print_mapping_state(void *this, FILE *file) {
|
||||||
|
map_header_t *header = PTR_FROM_FIELD_PTR(map_header_t, bytes, this);
|
||||||
|
for ( int i = 0; i < header->mapping_capacity; i++ ) {
|
||||||
|
int mapping = header->mapping_arr[i];
|
||||||
|
|
||||||
|
if (mapping == FLAG_TOMBSTONE) {
|
||||||
|
fprintf(file, "");
|
||||||
|
} else if (mapping == FLAG_FREE) {
|
||||||
|
fprintf(file, "");
|
||||||
|
} else if (mapping < 0) {
|
||||||
|
fprintf(file, COLORED(RED, ""));
|
||||||
|
} else {
|
||||||
|
fprintf(file, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fprintf(file, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
static inline unsigned int mapping_cap(unsigned int capacity) {
|
static inline unsigned int mapping_cap(unsigned int capacity) {
|
||||||
return capacity * 2;
|
return capacity * 2;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user