Using a prime number to size a hashtable is a way of getting a good distribution across buckets in the table if one is using division (modulo) by the table size to identify the bucket to use for some key. You can get a refresher in Knuth v3, p. 515-516. Another, faster approach that you will also see a lot of these days (the java hashtables use this one as of a few releases back), is to set hashtable sizes to one-less-than-some-power-of two. You then assign keys to buckets by doing a bitwise and of the key and that size. This saves the time involved in doing division (still very expensive, even on modern processors) and also removes the need to find a new prime number every time the table grows. On Aug 14, 2008, at 11:37 AM, Phil Pennock wrote: On 2008-08-14 at 15:08 +0200, Richard Hartmann wrote:On Mon, Aug 11, 2008 at 17:29, Dan Nelson <dnelson@xxxxxxxxxxxxxxx> wrote:Raise suggested-size to 1601 (a prime number larger than your currentlist size with some room to grow).Using a prime hints at an interesting reason. What is it? |