garbage collection

This commit is contained in:
biglyderv 2025-03-26 01:20:38 -04:00
parent c02e8aa59a
commit e6165f3af8
Signed by: biglyderv
GPG key ID: 0E2EB0B4CD7397B5
6 changed files with 44 additions and 21 deletions

View file

@ -12,6 +12,20 @@
#define MAX_BUF_LENGTH 1024
#define MAX_COMBO_LENGTH 1024
void init_tables(hashmap *elements, hashmap *inv, int do_inv) {
load_elements(elements, "../elem_data/" combo_file, 0) ||
load_elements(elements, combo_file, 0) ||
load_elements(elements, "bin/" combo_file, 0);
if (!do_inv)
return;
load_elements(elements, "../elem_data/" inv_base_file, 1) ||
load_elements(inv, inv_base_file, 1) ||
load_elements(inv, "bin/" inv_base_file, 1);
}
int main(int argc, char *argv[]) {
hashmap *elements = hashmap_create();
hashmap *inv = hashmap_create();
@ -20,10 +34,7 @@ int main(int argc, char *argv[]) {
char *command_re = calloc(MAX_BUF_LENGTH, sizeof(char));
char **sort_tmp = calloc(MAX_COMBO_LENGTH, sizeof(char **));
load_elements(elements, combo_file, 0) ||
load_elements(elements, "bin/" combo_file, 0);
load_elements(inv, inv_base_file, 1) ||
load_elements(inv, "bin/" inv_base_file, 1);
init_tables(elements, inv, 1);
load_elements(inv, inv_file, 1);
@ -56,10 +67,8 @@ int main(int argc, char *argv[]) {
uintptr_t result;
hashmap_get(elements, command_re, strlen(command_re), &result);
// todo: better
if (result == 0) {
load_elements(elements, combo_file, 0) ||
load_elements(elements, "bin/" combo_file, 0);
init_tables(elements, inv, 0);
hashmap_get(elements, command_re, strlen(command_re), &result);
}
@ -71,7 +80,7 @@ int main(int argc, char *argv[]) {
char *res_str = (char *)result;
hashmap_set(inv, res_str, strlen(res_str), (uintptr_t)1);
hashmap_set(inv, res_str, strlen(res_str), (uintptr_t)1, 0);
printf("You made %s!\n", res_str);
FILE *fptr;