[Mono-list] Hashtable bucket growth
Jeffrey Stedfast
fejj@ximian.com
14 Jul 2001 18:50:09 -0400
Since the table is so easily created, I wonder if it wouldn't be best to
just generate it on the fly.
Then again, it's not that large so having a static table isn't gonna
bloat it too much I guess.
Jeff
On 14 Jul 2001 15:13:49 -0600, John Barnette wrote:
> Hey kids,
>
> This is what I'm currently using to generate the new available bucket count
> during a rehash. Any comments?
>
>
> ~ j.
>
> --- CUT CUT CUT ---
>
> // Max entries in a Hashtable == Int32.MaxValue == 2,147,483,647
> private static int[] PRIMES = {
> 2, 5, 11, 23, 47, 97, 197, 397, 797, 1597, 3203, 6421, 12853,
> 25717, 51437, 102877, 205759, 411527, 823117, 1646237, 3292489,
> 6584983, 13169977, 26339969, 52679969, 105359939, 210719881,
> 421439783, 842879579, 1685759167 };
> private static int NUMBER_OF_PRIMES = 30;
>
>
> private int GetNewBucketSize(int oldBucketSize) {
> int target = oldBucketSize * 2;
> int first = 0, last = NUMBER_OF_PRIMES - 1;
>
> while (first < last) {
> int mid = (first + last) / 2;
> if (target < PRIMES[mid]) last = mid;
> else if (target > PRIMES[mid]) first = mid + 1;
> else {
> // can't happen
> throw new Exception("Can't happen in prime search");
> }
> }
>
> return PRIMES[last];
> }
>
>
> _______________________________________________
> Mono-list maillist - Mono-list@ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list