The stupid question is the question not asked | |
PerlMonks |
Re: Bidirectional lookup algorithm?by QM (Parson) |
on Jan 08, 2015 at 13:31 UTC ( [id://1112641]=note: print w/replies, xml ) | Need Help?? |
It's too bad there's no easy mechanism for creating a hash value pointing to a hash key, instead of another hash value.
Does it buy anything to create a hash with keys of some known hash function, and values as indexes pointing into an array? There's one more lookup, but into an array, which should be much cheaper than another hash lookup.
Without a real hash function, this gives:
...which is only slightly smaller than your original 2-hash result. Mind you, I'm on a 32-bit perl, so that could be the difference. (Caveats: I've not used a real hash function. I've not accounted for hash collisions.) -QM
In Section
Seekers of Perl Wisdom
|
|