Mercurial > repos > rhope
diff dict.rhope @ 90:c25d75c2440b
Implemented Next@Dictionary and Print@Dictionary
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 31 Jul 2010 15:08:15 -0400 |
parents | 3c4325e6298f |
children | e73a93fb5de1 |
line wrap: on
line diff
--- a/dict.rhope Sat Jul 31 00:19:15 2010 -0400 +++ b/dict.rhope Sat Jul 31 15:08:15 2010 -0400 @@ -32,14 +32,14 @@ ]Left <<[Dictionary[]] ]Right <<[Dictionary[]] ]Straight <<[val] - ]Bits <<[4294967295u32] //Maximum 32-bit unsigned int value + ]Bits <<[0u32] } _Set New[index,val,bits,bitindex:out] { nbitindex <- [bitindex]+[1] [index]Dict Bits[nbitindex] - { straight <- _Set New[index,val,~,nbitindex] } + { straight <- _Set New[index,val,[~]+[1u32],nbitindex] } { straight <- _Terminal Node[val] } out <- [[[[Build[Dictionary()]]Left <<[Dictionary[]]]Right <<[Dictionary[]]]Straight <<[straight]]Bits <<[bits] } @@ -51,7 +51,7 @@ Set@Empty Dictionary[dict,index,val:out] { - out <- _Set New[index,val, Dict Type ID[index], -1] + out <- _Set New[index,val, [Dict Type ID[index]]+[1u32], -1] } First@Empty Dictionary[dict:first,not found] @@ -67,20 +67,21 @@ Index@Dictionary[dict,index:out,not found] { - out,not found <- [dict]_Index[index,Dict Type ID[index], -1] + out,not found <- [dict]_Index[index,[Dict Type ID[index]]+[1u32], -1] } _Index@Dictionary[dict,index,bits,bitindex:out,not found] { If[[bits]=[[dict]Bits >>]] { - If[[bits]=[4294967295u32]] + If[[bits]=[0u32]] { out <- Straight >>[dict] }{ nbitindex <- [bitindex]+[1] - nbits <- [index]Dict Bits[nbitindex] {} - { nbits <- 4294967295u32 } + [index]Dict Bits[nbitindex] + { nbits <- [~]+[1u32] } + { nbits <- 0u32 } out,not found <- [[dict]Straight >>]_Index[index,nbits,nbitindex] } }{ @@ -96,20 +97,21 @@ Set@Dictionary[dict,index,val:out] { - out <- [dict]_Set[index,val,Dict Type ID[index], -1] + out <- [dict]_Set[index,val,[Dict Type ID[index]]+[1u32], -1] } _Set@Dictionary[dict,index,val,bits,bitindex:out] { If[[bits]=[[dict]Bits >>]] { - If[[bits]=[4294967295u32]] + If[[bits]=[0u32]] { out <- [dict]Straight <<[val] }{ nbitindex <- [bitindex]+[1] - nbits <- [index]Dict Bits[nbitindex] {} - { nbits <- 4294967295u32 } + [index]Dict Bits[nbitindex] + { nbits <- [~]+[1u32] } + { nbits <- 0u32 } out <- [dict]Straight <<[[[dict]Straight >>]_Set[index,val,nbits,nbitindex]] } }{ @@ -134,8 +136,8 @@ { typeid,node <- [[dict]Left >>]_First Type ID {} {} { - typeid <- [dict]Bits >> - node <- dict + typeid <- [[dict]Bits >>]-[1u32] + node <- Straight >>[dict] } } @@ -148,11 +150,11 @@ { keyout <- [[dict]Left >>]_First[keylist] {} { - If[[[dict]Bits >>] = [4294967295u32]] + If[[[dict]Bits >>] = [0u32]] { keyout <- keylist }{ - keyout <- [[dict]Straight >>]_First[[keylist]Append[[dict]Bits >>]] + keyout <- [[dict]Straight >>]_First[[keylist]Append[[[dict]Bits >>]-[1u32]]] } } } @@ -160,11 +162,102 @@ First@Dictionary[dict:out,none] { typeid, node <- [dict]_First Type ID - l <- List[] - rawkey <- [[node]Left >>]_First[l] {} - { - rawkey <- [[node]Straight >>]_First[l] - } + rawkey <- [node]_First[List[]] + out <- [Build[Blueprint From ID[typeid]]]From Dict Key[rawkey] +} + +Next@Dictionary[dict,cur:out,none] +{ + [cur]Dict Type ID + { rawkey,typeid,none <- [dict]_Next Type ID[[~]+[1u32], cur] } + out <- [Build[Blueprint From ID[typeid]]]From Dict Key[rawkey] } +_Next@Empty Dictionary[dict:out,none] +{ + none <- dict +} + +_Next Type ID@Empty Dictionary[dict:out,typeid,none] +{ + none <- dict +} + +_Next Type ID@Dictionary[dict,curtypeid,key:out,typeid,none] +{ + If[[[dict]Bits >>]=[curtypeid]] + { + out <- [[dict]Straight >>]_Next[key,0,List[]] + { typeid <- [curtypeid]-[1u32] } + { + typeid,,none <- [[dict]Right >>]_First Type ID {} + { + l <- List[] + out <- [~]_First[l] {} + } + } + }{ + If[[curtypeid]<[[dict]Bits >>]] + { + out,typeid <- [[dict]Left >>]_Next Type ID[curtypeid,key] {} {} + { + typeid <- [curtypeid]-[1u32] + out <- [[dict]Straight >>]_First[List[]] + } + }{ + out,typeid,none <- [[dict]Right >>]_Next Type ID[curtypeid,key] + } + } +} + +_Next@Dictionary[dict,key,keyidx,newkey:out,none] +{ + [key]Dict Bits[keyidx] + { bits <- [~]+[1u32] } + { bits <- 0u32 } + + If[[[dict]Bits >>]=[bits]] + { + ,goright <- If[bits] + { + out,goright <- [[dict]Straight >>]_Next[key,[keyidx]+[1], [newkey]Append[[bits]-[1u32]]] + } + Val[goright] + { + out,none <- [[dict]Right >>]_First[newkey] + } + }{ + If[[bits]<[[dict]Bits >>]] + { + out <- [[dict]Left >>]_Next[key, keyidx, newkey] {} + { out <- [[dict]Straight >>]_First[[newkey]Append[[[dict]Bits >>]-[1u32]]] } + }{ + out,none <- [[dict]Right >>]_Next[key, keyidx, newkey] + } + } +} + +_Print Dict[dict,key] +{ + val <- String[[dict]Index[key]] + Print[ [[["\t"]Append[String[key]]]Append[": "]]Append[val] ] + { + [dict]Next[key] + { + _Print Dict[dict, ~] + } + } +} + +Print@Dictionary[dict:out] +{ + Print["Dictionary"] + { _Print Dict[dict, [dict]First] } +} + +Print@Empty Dictionary[dict:out] +{ + Print["Dictionary\n\t{Empty}"] +} +