custom key and hasmap using a ranged key

Discussion in 'Java' started by Christian Bongiorno, Jun 15, 2004.

  1. 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
    Christian Bongiorno, Jun 15, 2004
    #1
    1. Advertising

  2. Christian Bongiorno

    Roedy Green Guest

    On 15 Jun 2004 14:16:05 -0700, (Christian
    Bongiorno) wrote or quoted :

    >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.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, Jun 15, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. christopher diggins
    Replies:
    0
    Views:
    407
    christopher diggins
    Aug 19, 2004
  2. Ranged Integers

    , Sep 3, 2007, in forum: C++
    Replies:
    9
    Views:
    356
    terminator
    Sep 3, 2007
  3. mttc
    Replies:
    8
    Views:
    2,716
    Daniel Pitts
    Dec 1, 2008
  4. M P
    Replies:
    1
    Views:
    455
  5. Victor Hooi
    Replies:
    1
    Views:
    102
    Victor Hooi
    Oct 29, 2013
Loading...

Share This Page