diff dict.rhope @ 87:3c4325e6298f

Add First@Dictionary (need to find mem man bug)
author Mike Pavone <pavone@retrodev.com>
date Fri, 30 Jul 2010 01:48:59 -0400
parents 27bb051d631c
children c25d75c2440b
line wrap: on
line diff
--- a/dict.rhope	Tue Jul 27 23:33:31 2010 -0400
+++ b/dict.rhope	Fri Jul 30 01:48:59 2010 -0400
@@ -86,10 +86,9 @@
 	}{
 		If[[bits]<[[dict]Bits >>]]
 		{
+			go <- Left >>[dict]
+		}{
 			go <- Right >>[dict]
-			
-		}{
-			go <- Left >>[dict]
 		}
 		out,not found <- [go]_Index[index,bits,bitindex]
 	}
@@ -116,14 +115,56 @@
 	}{
 		If[[bits]<[[dict]Bits >>]]
 		{
+			go <- Left >>[dict]
+			out <- [dict]Left <<[new]
+		}{
 			go <- Right >>[dict]
 			out <- [dict]Right <<[new]
-			
-		}{
-			go <- Left >>[dict]
-			out <- [dict]Left <<[new]
 		}
 		new <- [go]_Set[index,val,bits,bitindex]
 	}
 }
 
+_First Type ID@Empty Dictionary[dict:typeid,node,none]
+{
+	none <- dict
+}
+
+_First Type ID@Dictionary[dict:typeid,node]
+{
+	typeid,node <- [[dict]Left >>]_First Type ID {} {}
+	{
+		typeid <- [dict]Bits >>
+		node <- dict
+	}
+}
+
+_First@Empty Dictionary[dict,keylist:keyout,none]
+{
+	none <- dict
+}
+
+_First@Dictionary[dict,keylist:keyout]
+{
+	keyout <- [[dict]Left >>]_First[keylist] {}
+	{
+		If[[[dict]Bits >>] = [4294967295u32]]
+		{
+			keyout <- keylist
+		}{
+			keyout <- [[dict]Straight >>]_First[[keylist]Append[[dict]Bits >>]]
+		}
+	}
+}
+
+First@Dictionary[dict:out,none]
+{
+	typeid, node <- [dict]_First Type ID
+	l <- List[]
+	rawkey <- [[node]Left >>]_First[l] {}
+	{
+		rawkey <- [[node]Straight >>]_First[l]
+	}
+	out <- [Build[Blueprint From ID[typeid]]]From Dict Key[rawkey]
+}
+