Ordering of hashtable keys

Discussion in 'Java' started by Boris Punk, Jul 17, 2010.

  1. Boris Punk

    Boris Punk Guest

    Hi

    Could someone tell me what determines the order of the keys in a hashtable?
    Boris Punk, Jul 17, 2010
    #1
    1. Advertising

  2. In article <1uc0o.87059$2>,
    "Boris Punk" <> wrote:

    > Hi
    >
    > Could someone tell me what determines the order of the keys in a hashtable?


    If the JavaDoc doesn't state an order then it's a mix of JVM version,
    initial table size, insertion order, and _lots_ of bit hashing. After
    all, a hashing algorithm works best when it eliminates bucket mapping
    patterns.

    Use something like LinkedHashMap or TreeMap if order matters.
    --
    I won't see Google Groups replies because I must filter them as spam
    Kevin McMurtrie, Jul 17, 2010
    #2
    1. Advertising

  3. Boris Punk

    Lew Guest

    Boris Punk wrote:
    >> Could someone tell me what determines the order of the keys in a hashtable?


    Kevin McMurtrie wrote:
    > If the JavaDoc doesn't state an order then it's a mix of JVM version,
    > initial table size, insertion order, and _lots_ of bit hashing. After
    > all, a hashing algorithm works best when it eliminates bucket mapping
    > patterns.
    >
    > Use something like LinkedHashMap or TreeMap if order matters.


    And don't use 'java.util.Hashtable' even when order doesn't matter. It's been
    out of date since '98.

    --
    Lew
    Lew, Jul 17, 2010
    #3
  4. Boris Punk

    markspace Guest

    Boris Punk wrote:
    > Hi
    >
    > Could someone tell me what determines the order of the keys in a hashtable?



    Hash tables work by distributing their keys randomly, and therefore
    presumably evenly, in an array. The hash code and the hashing algorithm
    that uses the hash code are basically random number generators that
    produce indexes into this array.

    So the order of the keys is random, and as Patricia pointed out will
    change at runtime if the array needs to be re-hashed.
    markspace, Jul 17, 2010
    #4
  5. Boris Punk

    Boris Punk Guest

    thanks
    Boris Punk, Jul 18, 2010
    #5
  6. Boris Punk

    Boris Punk Guest

    Something I've noticed without digging into the code-that key strings that
    are almost the same apart from 1 character are next to each other-figure
    that one out!
    Boris Punk, Jul 19, 2010
    #6
  7. Boris Punk

    Lew Guest

    Boris Punk wrote:
    > Something I've noticed without digging into the code-that key strings that
    > are almost the same apart from 1 character are next to each other-figure
    > that one out!


    I don't fully understand that. What do you mean by "key strings" and "next to
    each other"?

    Does it matter where the one-character difference is in the strings?

    Can't figure out a problem so incompletely specified.

    --
    Lew
    Lew, Jul 19, 2010
    #7
    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. Harald Kirsch
    Replies:
    10
    Views:
    709
    Roedy Green
    Aug 16, 2003
  2. Alexander Mueller

    Hashtable/Two keys

    Alexander Mueller, Mar 19, 2005, in forum: Java
    Replies:
    29
    Views:
    7,324
    Chris Uppal
    Mar 22, 2005
  3. Replies:
    8
    Views:
    4,530
    Bjorn Abelli
    May 8, 2006
  4. Frank Cisco

    Hashtable ordering

    Frank Cisco, Aug 25, 2009, in forum: Java
    Replies:
    94
    Views:
    3,230
    Dave Searles
    Sep 1, 2009
  5. nbigaouette

    Z-Ordering (Morton ordering) question

    nbigaouette, Nov 5, 2009, in forum: C Programming
    Replies:
    2
    Views:
    2,128
Loading...

Share This Page