Results 1 to 5 of 5

Thread: Calculating when a Hashtable rehashing operation will occur

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Calculating when a Hashtable rehashing operation will occur

    After reading somthing out of the sun docs i am a bit confused. According to the documentation on Hashtable no rehash operations will ever occur if the initial capacity is greater than the maximum number of entries the Hashtable will contain divided by its load factor.

    This to me makes absolutely no nense. If the maximum capacity of a Hashtable is say 20 and it's load factor is defaulted at 0.75. Then 20 * 0.75 yields 15. So any initial capacity over 15 or an initial capacity under 15 plus an amount that pushes the capacity over 15 would cause a resizing.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Calculating when a Hashtable rehashing operation will occur

    No. Don't confuse capacity and element count.

    The Hashtable you describe will be resized if ever the element count rises above 15.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: Calculating when a Hashtable rehashing operation will occur

    Posted by CornedBee

    No. Don't confuse capacity and element count.

    The Hashtable you describe will be resized if ever the element count rises above 15.
    Yes exactly. That's how i saw it(Second statement). But the first statement i wrote makes no sense(at least to me) and it's from Sun's docs.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Calculating when a Hashtable rehashing operation will occur

    Ah, I see. Well, nothing weird about it: if the intial capacity of the HashMap is large enough to hold all entries that might eventually be stored, then there will never be a need to resize the HashMap.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: Calculating when a Hashtable rehashing operation will occur

    Yeah i missunderstood the semantics of initial capacity.

    The HashMap docs offered a better explanation, well actualy two, as opposed to the one offered by the Hashtables documentation.
    HashMap Docs

    When the number of entries in the hash table exceeds the product of the load factor and the current capacity, the capacity is roughly doubled by calling the rehash method.

    If the initial capacity is greater than the maximum number of entries divided by the load factor, no rehash operations will ever occur.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width