add json parsing of lists and maps
This commit is contained in:
parent
7471093f67
commit
025c8125fa
16 changed files with 210 additions and 20 deletions
27
sortedmap.c
27
sortedmap.c
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue