comparison string.rhope @ 157:37b999dbd12e

Small change to make String Cat trees a little more balanced
author Mike Pavone <pavone@retrodev.com>
date Thu, 23 Dec 2010 15:48:19 -0500
parents ed70399a07aa
children 0e06f29aa83d
comparison
equal deleted inserted replaced
156:ed70399a07aa 157:37b999dbd12e
826 } 826 }
827 out <- String Slice[[string]Source >>, sliceoffset, slength, sbytelen] 827 out <- String Slice[[string]Source >>, sliceoffset, slength, sbytelen]
828 } 828 }
829 } 829 }
830 830
831 Depth@String[string:out]
832 {
833 out <- 0
834 }
835
836 Depth@String Slice[string:out]
837 {
838 out <- 0
839 }
840
841 Depth@String Cat[string:out]
842 {
843 out <- Depth >>[string]
844 }
845
831 Blueprint String Cat 846 Blueprint String Cat
832 { 847 {
833 Left 848 Left
834 Right 849 Right
835 Length 850 Length
836 ByteLen 851 ByteLen
852 Depth
837 } 853 }
838 854
839 String Cat[left,right:out] 855 String Cat[left,right:out]
840 { 856 {
841 out <- [[[[Build[String Cat()] 857 out <- [[[[[Build[String Cat()]
842 ]Left <<[left] 858 ]Left <<[left]
843 ]Right <<[right] 859 ]Right <<[right]
844 ]Length <<[ [[left]Length]+[[right]Length] ] 860 ]Length <<[ [[left]Length]+[[right]Length] ]
845 ]ByteLen <<[ [[left]Byte Length]+[[right]Byte Length] ] 861 ]ByteLen <<[ [[left]Byte Length]+[[right]Byte Length] ]
862 ]Depth <<[ [1]+[Min[[left]Depth, [right]Depth]] ]
846 } 863 }
847 864
848 Append@String Cat[left,right:out] 865 Append@String Cat[left,right:out]
849 { 866 {
850 out <- String Cat[left,right] 867 ll <- [left]Left >>
868 lr <- [left]Right >>
869 If[[[ll]Depth] > [[lr]Depth]]
870 {
871 out <- String Cat[ll, String Cat[lr,right]]
872 }{
873 out <- String Cat[left,right]
874 }
851 } 875 }
852 876
853 Byte@String Cat[string,index:out,invalid] 877 Byte@String Cat[string,index:out,invalid]
854 { 878 {
855 leftlen <- [[string]Left >>]Byte Length 879 leftlen <- [[string]Left >>]Byte Length