comparison trunk/chipmunkd/prime.d @ 4:7ebbd4d05553

initial commit
author Extrawurst
date Thu, 02 Dec 2010 02:11:26 +0100
parents
children
comparison
equal deleted inserted replaced
3:81145a61c2fe 4:7ebbd4d05553
1
2 // written in the D programming language
3
4 module chipmunkd.prime;
5
6 // Used for resizing hash tables.
7 // Values approximately double.
8 // http://planetmath.org/encyclopedia/GoodHashTablePrimes.html
9 enum int primes[] = [
10 5,
11 13,
12 23,
13 47,
14 97,
15 193,
16 389,
17 769,
18 1543,
19 3079,
20 6151,
21 12289,
22 24593,
23 49157,
24 98317,
25 196613,
26 393241,
27 786433,
28 1572869,
29 3145739,
30 6291469,
31 12582917,
32 25165843,
33 50331653,
34 100663319,
35 201326611,
36 402653189,
37 805306457,
38 1610612741,
39 0,
40 ];
41
42 static int
43 next_prime(int n)
44 {
45 int i = 0;
46 while(n > primes[i]){
47 i++;
48 assert(primes[i]!=0, "Tried to resize a hash table to a size greater than 1610612741 O_o"); // realistically this should never happen
49 }
50
51 return primes[i];
52 }