我有一个哈希值。这个哈希有一个字典。我需要在其中找到所有具有相同根的匹配项。例如,我有:
#<Trie:0x00000001bf9a40 @root={
"m"=>{"a"=>{"x"=>{
:end=>true,
"i"=>{"m"=>{
:end=>true,
"i"=>{"m"=>{"l"=>{"i"=>{"a"=>{"n"=>{:end=>true}}}}}}
}},
"w"=>{"e"=>{"l"=>{"l"=>{:end=>true}}}}
}}}
}>
和单词"max"
, "maxim"
, "maximilian"
, "maxwell"
. 如何按根获取此哈希中的所有单词?例如
t = Trie.new
t.add( .....# now we added words
t.find('max')
#result all words which begins from 'max'
t.find('maxim')
#result all words which begins from 'maxim' => maxim, maximilian