cc-hash.c (fhash): The FILE name may be null.
[u/mdw/catacomb] / primeiter.h
1 /* -*-c-*-
2 *
3 * Iterate over small primes efficiently
4 *
5 * (c) 2007 Straylight/Edgeware
6 */
7
8 /*----- Licensing notice --------------------------------------------------*
9 *
10 * This file is part of Catacomb.
11 *
12 * Catacomb is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
16 *
17 * Catacomb is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
21 *
22 * You should have received a copy of the GNU Library General Public
23 * License along with Catacomb; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 * MA 02111-1307, USA.
26 */
27
28 #ifndef CATACOMB_PRIMEITER_H
29 #define CATACOMB_PRIMEITER_H
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 /*----- Header files ------------------------------------------------------*/
36
37 #ifndef CATACOMB_GRAND_H
38 # include "grand.h"
39 #endif
40
41 #ifndef CATACOMB_MP_H
42 # include "mp.h"
43 #endif
44
45 /*----- Data structures ---------------------------------------------------*/
46
47 typedef struct primeiter {
48 mpw w;
49 mp pp;
50 mp *p;
51 grand *r;
52 unsigned mode;
53 int i;
54 } primeiter;
55
56 enum {
57 PIMODE_PTAB,
58 PIMODE_STALL,
59 PIMODE_WHEEL
60 };
61
62 /*----- Functions provided ------------------------------------------------*/
63
64 /* --- @primeiter_create@ --- *
65 *
66 * Arguments: @primeiter *pi@ = pointer to an iterator structure
67 * @mp *start@ = where to start
68 *
69 * Returns: ---
70 *
71 * Use: Initializes a prime iterator. The first output will be the
72 * smallest prime not less than @start@.
73 */
74
75 extern void primeiter_create(primeiter */*pi*/, mp */*start*/);
76
77 /* --- @primeiter_destroy@ --- *
78 *
79 * Arguments: @primeiter *pi@ = pointer to iterator structure
80 *
81 * Returns: ---
82 *
83 * Use: Frees up an iterator structure when it's no longer wanted.
84 */
85
86 void primeiter_destroy(primeiter */*pi*/);
87
88 /* --- @primeiter_next@ --- *
89 *
90 * Arguments: @primeiter *pi@ = pointer to an iterator structure
91 * @mp *d@ = fake destination
92 *
93 * Returns: The next prime number from the iterator.
94 *
95 * Use: Returns a new prime number.
96 */
97
98 mp *primeiter_next(primeiter */*pi*/, mp */*d*/);
99
100 /*----- That's all, folks -------------------------------------------------*/
101
102 #ifdef __cplusplus
103 }
104 #endif
105
106 #endif