in reply to Better way to search array for elements in other array?
What if you take one list of strings and convert it to a HoHoHo...?
The top level key would be the first letter of each string. At each level, you have either the string to eq against, or a hash of choices for the next letter.
EG: my $tree = {f => {o => 'foo', i => {r => 'fire', n => 'fine', }, }, b => 'bar', }
You would know instantly that 'monk' isn't in the second list because !exists($tree->{m}).
You would know 'balloon' doesn't exist pretty quick because exists($tree->{b}) and ref($tree->{b}) ne 'HASH' and $tree->{b} ne 'balloon'.
If the second list is something constant without too much duplication early in the string, such as a dictionary, then it should work really well.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Better way to search array for elements in other array?
by Limbic~Region (Chancellor) on Jan 24, 2011 at 21:49 UTC | |
by SuicideJunkie (Vicar) on Jan 25, 2011 at 16:16 UTC | |
|
Re^2: Better way to search array for elements in other array?
by eff_i_g (Curate) on Jan 24, 2011 at 21:12 UTC |