"Edward M. Perry" <eperry@learjet.com> writes: > Here is the problem: given a key ($key), and a hash (%h), I want the value > of the closest hash key. I came up with this which is only moderately fun. > Really it works pretty well, assuming keys are numeric and the hash is > small. Mapping to %temp is weak. > > An array seems unreasonable because in reality the keys (or indicies) are > large and the array would be very sparse. >[hashing example snipped] It sounds like you want (gasp!) a data structure that isn't an array or a hash. A binary tree would be a good choice. If linear-time is acceptable, or if the keys arrive in reasonably "random" order, then it's definitely good enough; otherwise you may want to rotate it. How many items have you got? -- Ariel Scolnicov |"GCAAGAATTGAACTGTAG" |ariels@compugen.co.il Compugen Ltd. |Tel: +972-2-6795059 (Jerusalem) \ NEW IMPROVED URL! 72 Pinhas Rosen St. |Tel: +972-3-7658520 (Main office)`-------------------- Tel-Aviv 69512, ISRAEL |Fax: +972-3-7658555 http://3w.compugen.co.il/~ariels ==== Want to unsubscribe from Fun With Perl? Well, if you insist... ==== Send email to <fwp-request@technofile.org> with message _body_ ==== unsubscribe