Commit Diff


commit - f9ce7ebaa6ef436f492408aa23d1ae1b6778e4c4
commit + bebd7c2cb6957b68f5a5f2a124e95766dda2018c
blob - a81cec5087f86f647bb1e17a9e7f827c4868330e
blob + 9d2b286e385f476e21d96b592915d680646b7313
--- minip_n.h
+++ minip_n.h
@@ -93,10 +93,13 @@ typedef bool action(void *, void *, const char *, size
 
 /* an entry in the memoization hash table */
 struct memento {
-	const char *position;	/* NULL: unused entry */
-	const char *symbol;	/* NULL: dummy entry -- may be reused */
-	const char *result;
+	const void *mem_key;	/* NULL: unused entry */
+	const void *mem_key2;	/* NULL: dummy entry -- may be reused */
+	const void *mem_value;
 };
+#define mem_position mem_key
+#define mem_symbol mem_key2
+#define mem_result mem_value
 
 struct cache {
 	struct memento *table;
@@ -240,12 +243,12 @@ memo_(struct stream inp, struct cache *cache, void *en
 	/* NB: count steps, since the table could be filled with dummies */
 	for (i=0, h=h0, s=1; i < cache->capacity; i++, h+=s, s*=5) {
 		mem = cache->table + (h % cache->capacity);
-		if (mem->position == NULL)	/* not in table */
+		if (mem->mem_key == NULL)	/* not in table */
 			break;
-		if (mem->symbol == NULL)	/* dummy entry */
+		if (mem->mem_key2 == NULL)	/* dummy entry */
 			continue;
-		if (mem->position == inp.p && mem->symbol == sym)
-			return mem->result;	/* match */
+		if (mem->mem_position == inp.p && mem->mem_symbol == sym)
+			return mem->mem_result;	/* match */
 	}
 
 	/* else run the argument sequence */
@@ -274,8 +277,8 @@ memo_(struct stream inp, struct cache *cache, void *en
 
 		/* relocate items */
 		for (i=0; i < cache->capacity; i++) {
-			const char *pi = cache->table[i].position;
-			const char *si = cache->table[i].symbol;
+			const char *pi = cache->table[i].mem_position;
+			const char *si = cache->table[i].mem_symbol;
 
 			if (pi == NULL || si == NULL)	/* unused or dummy */
 				continue;
@@ -291,7 +294,7 @@ memo_(struct stream inp, struct cache *cache, void *en
 			for (s=1; ; h+=s, s*=5) {
 				h %= newcap;
 				mem = newp + h;
-				if (mem->position == NULL)	/* unused */
+				if (mem->mem_key == NULL)	/* unused */
 					break;
 			}
 #ifdef PROFGROW
@@ -321,17 +324,17 @@ memo_(struct stream inp, struct cache *cache, void *en
 	/* NB: loop will terminate because dummies count as free here */
 	for (h=h0, s=1; ; h+=s, s*=5) {
 		mem = cache->table + (h % cache->capacity);
-		if (mem->position == NULL)	/* unused entry */
+		if (mem->mem_key == NULL)	/* unused entry */
 			break;
-		if (mem->symbol == NULL)	/* dummy entry */
+		if (mem->mem_key2 == NULL)	/* dummy entry */
 			break;			/* reuse! */
 	}
 
 	/* save the result */
-	assert(mem->position == NULL || mem->symbol == NULL);
-	mem->position = inp.p;
-	mem->symbol = sym;
-	mem->result = res;
+	assert(mem->mem_key == NULL || mem->mem_key2 == NULL);
+	mem->mem_position = inp.p;
+	mem->mem_symbol = sym;
+	mem->mem_result = res;
 	cache->nused++;
 
 	return res;