custom key and hasmap using a ranged key

  • Thread starter Christian Bongiorno
  • Start date
C

Christian Bongiorno

So, what I would like to do is have a mapping between a range of keys
and a value

so, min < key < max = true;

I am not sure that hasmap can do this cleanly. I believe the problem
lies in hashCode(). What do I return for hashcodes??

Perhaps HashXXX is not the way. Perhaps I need a sorted list and then
sort by
objA.max - objB.min??

Thoughs?

Christian
 
R

Roedy Green

So, what I would like to do is have a mapping between a range of keys
and a value

so, min < key < max = true;

I am not sure that hasmap can do this cleanly. I believe the problem
lies in hashCode(). What do I return for hashcodes??

hashCodes have nothing to do with ordering. They are for lookup by
precise key.

See http://mindprod.com/projects/caserange.html

where I discuss algorithms for adding case ranges to Java. Much of
that applies to your problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top