fix construction of maps
This commit is contained in:
parent
35f48eb570
commit
cdd56b8e25
@ -47,9 +47,9 @@ SortedMap * put_map(SortedMap *this, char *key, void *value) {
|
|||||||
leaf->content.value = value;
|
leaf->content.value = value;
|
||||||
intern = malloc(sizeof(SortedMap));
|
intern = malloc(sizeof(SortedMap));
|
||||||
intern->type = INTERN;
|
intern->type = INTERN;
|
||||||
intern->key = this->key;
|
intern->key = cmp <= 0 ? key : this->key;
|
||||||
intern->content.children.l = cmp < 0 ? leaf : this;
|
intern->content.children.l = cmp <= 0 ? leaf : this;
|
||||||
intern->content.children.r = cmp < 0 ? this : leaf;
|
intern->content.children.r = cmp <= 0 ? this : leaf;
|
||||||
return intern;
|
return intern;
|
||||||
case INTERN:
|
case INTERN:
|
||||||
if (cmp <= 0) {
|
if (cmp <= 0) {
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
#ifndef SORTED_MAP
|
#ifndef SORTED_MAP
|
||||||
#define 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 };
|
enum nodetype { EMPTY, LEAF, INTERN };
|
||||||
|
|
||||||
typedef struct node {
|
typedef struct node {
|
||||||
|
Loading…
Reference in New Issue
Block a user