shithub: neatroff

Download patch

ref: c8b2386ccc90cad553c4fd36a7235e95b78f6a7b
parent: 50a514828490db6eb2531f25d75779c2cd6e3046
author: Ali Gholami Rudi <[email protected]>
date: Thu Apr 13 11:56:55 EDT 2017

dict: overriding values

--- a/dict.c
+++ b/dict.c
@@ -76,12 +76,12 @@
 /* return the index of key in d */
 int dict_idx(struct dict *d, char *key)
 {
-	int *r = iset_get(d->map, DHASH(d, key));
-	while (r && *r >= 0) {
+	int h = DHASH(d, key);
+	int *b = iset_get(d->map, h);
+	int *r = b + iset_len(d->map, h);
+	while (b && --r >= b)
 		if (!strcmp(d->key[*r], key))
 			return *r;
-		r++;
-	}
 	return -1;
 }