diff dict.c @ 3:94c885692eb5

Partial set of fixes and enhancements from Linux box
author Mike Pavone <pavone@retrodev.com>
date Wed, 29 Apr 2009 03:21:23 -0400
parents 76568becd6d6
children
line wrap: on
line diff
--- a/dict.c	Wed Apr 29 02:58:03 2009 -0400
+++ b/dict.c	Wed Apr 29 03:21:23 2009 -0400
@@ -342,6 +342,7 @@
 	ternary_node * decision = NULL;
 	int decision_key_size;
 	BOOL next_flag = FALSE;
+	BOOL this_flag = FALSE;
 	nodes = current;
 	
 	if(dict->num_nodes <= 0)
@@ -359,12 +360,12 @@
 			if(old_key[i] == current->letter)
 				if(i == (old_key_len))
 				{
-					if(current->left >= 0)
+					/*if(current->left >= 0)
 					{
 						current = nodes + current->left;
 						break;
 					}
-					else if(current->next >= 0)
+					else */if(current->next >= 0)
 					{
 						APPEND_KEY_STORE(key, key_store, key_size, current->letter);
 						current = nodes + current->next;
@@ -386,6 +387,19 @@
 								APPEND_KEY_STORE(key, key_store, key_size, current->letter);
 								current = nodes + current->next;
 							}
+							else if(this_flag)
+							{
+								APPEND_KEY_STORE(key, key_store, key_size, current->letter);
+								APPEND_KEY_STORE(key, key_store, key_size, '\0');
+								release_ref(inputlist[0]);
+								release_ref(inputlist[1]);
+								inputlist[1] = NULL;
+								inputlist[0] = new_datum(BUILTIN_TYPE_STRING, 2, 0, worker_entry->instance->def->program);
+								inputlist[0]->union_type = 1;
+								inputlist[0]->c.generic.data = key;
+								inputlist[0]->c.generic.len = key_size;
+								return 0;
+							}
 							break;
 						}
 						else
@@ -405,6 +419,7 @@
 						decision = nodes + current->right;
 						decision_key_size = key_size;
 						next_flag = FALSE;
+						this_flag = FALSE;
 					}
 					APPEND_KEY_STORE(key, key_store, key_size, current->letter);
 					++i;
@@ -414,18 +429,27 @@
 				current = nodes + current->right;
 			else
 			{
-				if(current->next >= 0)
+				//Hmm, what do I do here if there's a payload at this location?
+				if(current->next >= 0 || current->payload)
 				{
 					//APPEND_KEY_STORE(key, key_store, key_size, current->letter);
 					decision = current;//nodes + current->next;
 					decision_key_size = key_size;
-					next_flag = TRUE;
+					if(current->payload)
+					{
+						next_flag = FALSE;
+						this_flag = TRUE;
+					} else {
+						next_flag = TRUE;
+						this_flag = FALSE;
+					}
 				}
 				else if(current->right >= 0)
 				{
 					decision = nodes + current->right;
 					decision_key_size = key_size;
 					next_flag = FALSE;
+					this_flag = FALSE;
 				}
 				current = nodes + current->left;
 			}