add json parsing of lists and maps

This commit is contained in:
Felix Van der Jeugt 2022-11-08 23:31:00 +01:00
parent 7471093f67
commit 025c8125fa
No known key found for this signature in database
GPG key ID: 58B209295023754D
16 changed files with 210 additions and 20 deletions

View file

@ -98,7 +98,7 @@ void * fold_map(SortedMap *this, void * init, void * (*f)(void * acc, char *key,
case LEAF:
return f(init, this->key, this->content.value);
case INTERN:
return fold_map(fold_map(init, this->content.children.l, f), this->content.children.r, f);
return fold_map(this->content.children.r, fold_map(this->content.children.l, init, f), f);
default:
return NULL;
}
@ -118,6 +118,31 @@ void free_mapvalues(SortedMap *this) {
}
}
void free_mapkeys(SortedMap *this) {
switch (this->type) {
case EMPTY:
break;
case LEAF:
free(this->key);
break;
case INTERN:
free_mapkeys(this->content.children.l);
free_mapkeys(this->content.children.r);
break;
}
}
void * free_mappair(void *acc, char *key, void *value) {
free(key);
free(value);
return NULL;
}
void * free_mapitem(void *acc, char *key, void *value) {
free(value);
return NULL;
}
void free_map(SortedMap *this) {
switch (this->type) {
case EMPTY: