Mercurial > repos > rhope
diff dict.rhope @ 83:27bb051d631c
Initial implementation of Dictionary
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 27 Jul 2010 23:33:31 -0400 |
parents | |
children | 3c4325e6298f |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dict.rhope Tue Jul 27 23:33:31 2010 -0400 @@ -0,0 +1,129 @@ + +Blueprint Empty Dictionary +{ +} + +Blueprint Dictionary +{ + Left + Right + Straight + Bits(UInt32,Naked) +} + +Dictionary[:out] +{ + out <- Build[Empty Dictionary()] +} + +_Index@Empty Dictionary[dict,index,bits,bitindex:out,not found] +{ + not found <- dict +} + +Index@Empty Dictionary[dict,index:out,not found] +{ + not found <- dict +} + +_Terminal Node[val:out] +{ + out <- [[[[Build[Dictionary()] + ]Left <<[Dictionary[]] + ]Right <<[Dictionary[]] + ]Straight <<[val] + ]Bits <<[4294967295u32] //Maximum 32-bit unsigned int value +} + +_Set New[index,val,bits,bitindex:out] +{ + nbitindex <- [bitindex]+[1] + [index]Dict Bits[nbitindex] + { straight <- _Set New[index,val,~,nbitindex] } + { straight <- _Terminal Node[val] } + out <- [[[[Build[Dictionary()]]Left <<[Dictionary[]]]Right <<[Dictionary[]]]Straight <<[straight]]Bits <<[bits] +} + +_Set@Empty Dictionary[dict,index,val,bits,bitindex:out] +{ + out <- _Set New[index,val,bits,bitindex] +} + +Set@Empty Dictionary[dict,index,val:out] +{ + out <- _Set New[index,val, Dict Type ID[index], -1] +} + +First@Empty Dictionary[dict:first,not found] +{ + not found <- dict +} + +Next@Empty Dictionary[dict,index:next,not found] +{ + not found <- dict +} + + +Index@Dictionary[dict,index:out,not found] +{ + out,not found <- [dict]_Index[index,Dict Type ID[index], -1] +} + +_Index@Dictionary[dict,index,bits,bitindex:out,not found] +{ + If[[bits]=[[dict]Bits >>]] + { + If[[bits]=[4294967295u32]] + { + out <- Straight >>[dict] + }{ + nbitindex <- [bitindex]+[1] + nbits <- [index]Dict Bits[nbitindex] {} + { nbits <- 4294967295u32 } + out,not found <- [[dict]Straight >>]_Index[index,nbits,nbitindex] + } + }{ + If[[bits]<[[dict]Bits >>]] + { + go <- Right >>[dict] + + }{ + go <- Left >>[dict] + } + out,not found <- [go]_Index[index,bits,bitindex] + } +} + +Set@Dictionary[dict,index,val:out] +{ + out <- [dict]_Set[index,val,Dict Type ID[index], -1] +} + +_Set@Dictionary[dict,index,val,bits,bitindex:out] +{ + If[[bits]=[[dict]Bits >>]] + { + If[[bits]=[4294967295u32]] + { + out <- [dict]Straight <<[val] + }{ + nbitindex <- [bitindex]+[1] + nbits <- [index]Dict Bits[nbitindex] {} + { nbits <- 4294967295u32 } + out <- [dict]Straight <<[[[dict]Straight >>]_Set[index,val,nbits,nbitindex]] + } + }{ + If[[bits]<[[dict]Bits >>]] + { + go <- Right >>[dict] + out <- [dict]Right <<[new] + + }{ + go <- Left >>[dict] + out <- [dict]Left <<[new] + } + new <- [go]_Set[index,val,bits,bitindex] + } +} +