Mercurial > projects > chipmunkd
view trunk/chipmunkd/prime.d @ 4:7ebbd4d05553
initial commit
author | Extrawurst |
---|---|
date | Thu, 02 Dec 2010 02:11:26 +0100 |
parents | |
children |
line wrap: on
line source
// written in the D programming language module chipmunkd.prime; // Used for resizing hash tables. // Values approximately double. // http://planetmath.org/encyclopedia/GoodHashTablePrimes.html enum int primes[] = [ 5, 13, 23, 47, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593, 49157, 98317, 196613, 393241, 786433, 1572869, 3145739, 6291469, 12582917, 25165843, 50331653, 100663319, 201326611, 402653189, 805306457, 1610612741, 0, ]; static int next_prime(int n) { int i = 0; while(n > primes[i]){ i++; assert(primes[i]!=0, "Tried to resize a hash table to a size greater than 1610612741 O_o"); // realistically this should never happen } return primes[i]; }