diff --git a/sortedmap.c b/sortedmap.c index 415e317..448b809 100644 --- a/sortedmap.c +++ b/sortedmap.c @@ -47,9 +47,9 @@ SortedMap * put_map(SortedMap *this, char *key, void *value) { leaf->content.value = value; intern = malloc(sizeof(SortedMap)); intern->type = INTERN; - intern->key = this->key; - intern->content.children.l = cmp < 0 ? leaf : this; - intern->content.children.r = cmp < 0 ? this : leaf; + intern->key = cmp <= 0 ? key : this->key; + intern->content.children.l = cmp <= 0 ? leaf : this; + intern->content.children.r = cmp <= 0 ? this : leaf; return intern; case INTERN: if (cmp <= 0) { diff --git a/sortedmap.h b/sortedmap.h index 9bab76e..7482f5e 100644 --- a/sortedmap.h +++ b/sortedmap.h @@ -1,5 +1,9 @@ #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 {