fix construction of maps

This commit is contained in:
Felix Van der Jeugt 2023-10-30 23:38:10 +01:00
parent 35f48eb570
commit cdd56b8e25
No known key found for this signature in database
GPG Key ID: 58B209295023754D
2 changed files with 7 additions and 3 deletions

View File

@ -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) {

View File

@ -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 {