Just another Perl shrine | |
PerlMonks |
hashing intervalsby baxy77bax (Deacon) |
on Jul 29, 2013 at 15:29 UTC ( [id://1046877]=perlquestion: print w/replies, xml ) | Need Help?? |
baxy77bax has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
well i know it is probably not the best title but... So what I have been trying to build is a data structure, a table from which i could retrieve the information very fast given a certain key is provided. A first thing that popped into my mind when I saw the problem was a hash table. But my data is very peculiar. Example:
so it is a table of intervals associated with some numbers. Intervals cannot overlap (Thank U G) but some intervals can remain empty like 18-18 or 21-22. the interval range is form 1 to 1000000000. associated values are from 1 to 5000000. the thing is when i am retrieving associated numbers I have to be able to make a query of the type:
"Q: What is the value associated with 50?" Is it clear what I am trying to get? Now, I could create a hash table for all possible values from 45 to 134 and associate each key to 23 and get the job done, but this seam like too memory wasteful. And since this looks like a trivial task I guess somebody already solved it efficiently and I can only be grateful if she/he is willing to share the knowledge :) thank you baxy
Back to
Seekers of Perl Wisdom
|
|