in reply to Fuzzy hash key lookups

Hashes are not sorted, so your premises of "assume that the hash is lexically sorted" makes as much sense as "assume that the array is Wednesday". At best what you can archieve is to have some sort of datastructure that keeps the keys sorted, and you have a tied hash interface to that datastructure.

A sorted search tree might be the solution you are looking for, but that depends on what you mean by "fuzzy". Do you want to do a "nearest" query, nearest measured over the way you have sorted your data? In that case, a tree will work. Or do you mean that if you search with "abadabafupla", a result of "abadabaxupla" is wanted because there's only on letter that's different? In that case you need a completely different datastructure.

Of course, any datastructure whose search queries take a scalar and give a scalar as return can be hidden being a tied hash.

Abigail

Replies are listed 'Best First'.
Re: Re: Fuzzy hash key lookups
by c0bra (Acolyte) on Aug 01, 2002 at 15:29 UTC
    Well a B-Tree is sorted, isn't it?

    And by fuzzy I mean lookups by regexes like in Tie::Hash::Regex. If the lookup matches multiple keys, they're all returned.

    If you search for just "abadabafupla" it should return the data for "abadabafupla" and only "abadabafupla".

      A B-Tree isn't a hash, is it?

      Your second line confuses me. If you want to do the same as in Tie::Hash::Regex, why don't you use Tie::Hash::Regex?

      Oh, you want to do it without searching all the keys, and you think that sorting will help? How would you sort if the regex could contain a leading dot?

      Abigail