Re: Map partial key match method
Posted: Mon May 25, 2020 11:39 pm
you're correct a Trie <> Tree, although it's still a form of Tree. This will make more sense than I can https://en.wikipedia.org/wiki/Trie
If you're set's small you could get away with something like this though it's not efficient but it might also work in spider basic.
If you're set's small you could get away with something like this though it's not efficient but it might also work in spider basic.
Code: Select all
Procedure EnumMap(Map mp(),List ls.s(),key.s,len,mode=#PB_Unicode)
Protected word.s
ForEach mp()
word = PeekS(mp(),-1,mode)
If Left(word,len) = key
AddElement(ls())
ls() = word
EndIf
Next
SortList(ls(),#PB_Sort_Ascending)
EndProcedure
NewMap txt.i()
NewList out.s()
AddMapElement(txt(),"ab") : txt()=@"ab"
AddMapElement(txt(),"abc") : txt()=@"abc"
AddMapElement(txt(),"abcd") : txt()=@"abcd"
AddMapElement(txt(),"cdef") : txt()=@"cdef"
EnumMap(txt(),out(),"ab",2)
ForEach out()
Debug out()
Next
ClearList(out())
EnumMap(txt(),out(),"cd",2)
ForEach out()
Debug out()
Next
ClearList(out())