30 lines
808 B
C
30 lines
808 B
C
#ifndef SORTED_MAP
|
|
#define SORTED_MAP
|
|
/* A map datastructure which maps strings to void*.
|
|
* A binary search tree putting string equal to or smaller than the current node left.
|
|
*/
|
|
|
|
enum nodetype { EMPTY, LEAF, INTERN };
|
|
|
|
typedef struct node {
|
|
enum nodetype type;
|
|
char * key;
|
|
union {
|
|
struct children {
|
|
struct node * l;
|
|
struct node * r;
|
|
} children;
|
|
void * value;
|
|
} content;
|
|
} SortedMap;
|
|
|
|
SortedMap * map();
|
|
void * get_map(SortedMap *this, char *key);
|
|
SortedMap * put_map(SortedMap *this, char *key, void *value);
|
|
void print_map(SortedMap *this);
|
|
void * fold_map(SortedMap *this, void * init, void * (*f)(void * acc, char *key, void *value));
|
|
void * free_mappair(void *acc, char *key, void *value);
|
|
void * free_mapitem(void *acc, char *key, void *value);
|
|
void free_map(SortedMap *this);
|
|
#endif
|