pools of 128 items instead of 1024 items.
[platform/upstream/glib.git] / gprimes.c
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /* 
21  * MT safe
22  */
23
24 #include "glib.h"
25
26 static const guint g_primes[] =
27 {
28   11,
29   19,
30   37,
31   73,
32   109,
33   163,
34   251,
35   367,
36   557,
37   823,
38   1237,
39   1861,
40   2777,
41   4177,
42   6247,
43   9371,
44   14057,
45   21089,
46   31627,
47   47431,
48   71143,
49   106721,
50   160073,
51   240101,
52   360163,
53   540217,
54   810343,
55   1215497,
56   1823231,
57   2734867,
58   4102283,
59   6153409,
60   9230113,
61   13845163,
62 };
63
64 static const guint g_nprimes = sizeof (g_primes) / sizeof (g_primes[0]);
65
66 guint
67 g_spaced_primes_closest (guint num)
68 {
69   gint i;
70
71   for (i = 0; i < g_nprimes; i++)
72     if (g_primes[i] > num)
73       return g_primes[i];
74
75   return g_primes[g_nprimes - 1];
76 }