summaryrefslogtreecommitdiff
path: root/src/hashtable.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hashtable.c')
-rw-r--r--src/hashtable.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/hashtable.c b/src/hashtable.c
index 3a83861..2ec766d 100644
--- a/src/hashtable.c
+++ b/src/hashtable.c
@@ -49,18 +49,28 @@ unsigned int hashtable_add_pair(hashtable_t* hashtable, pair_t pair) {
unsigned int hash = get_hash(pair.key);
for (int i = 0; i < hashtable->capacity; i++) {
pair_t p = hashtable->pairs[hash % hashtable->capacity];
- if (p.key == NULL || p.key == pair.key) {
+ if (p.key == NULL || strcmp(p.key, pair.key) == 0) {
hashtable->pairs[hash % hashtable->capacity] = pair;
return hash;
}
}
return 0;
}
+unsigned int hashtable_update_pair_recurse(hashtable_t* origin, pair_t pair) {
+ pair_t p = hashtable_get_pair(origin, pair.key);
+ if (p.key != NULL) {
+ return hashtable_add_pair(origin, pair);
+ }
+ if (origin->parent != NULL) {
+ return hashtable_update_pair_recurse(origin->parent, pair);
+ }
+ return 0;
+}
pair_t hashtable_get_pair(hashtable_t* hashtable, char* key) {
unsigned int hash = get_hash(key);
for (int i = 0; i < hashtable->capacity; i++) {
pair_t p = hashtable->pairs[hash % hashtable->capacity];
- if (p.key == key) {
+ if (p.key != NULL && strcmp(p.key, key) == 0) {
return p;
}
else if (p.key == NULL) {