|
-
Jun 12th, 2005, 02:26 PM
#1
Thread Starter
Dazed Member
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.
-
Jun 13th, 2005, 04:27 AM
#2
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.
-
Jun 13th, 2005, 01:12 PM
#3
Thread Starter
Dazed Member
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.
-
Jun 13th, 2005, 02:25 PM
#4
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.
-
Jun 13th, 2005, 09:31 PM
#5
Thread Starter
Dazed Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|