d03ab969 |
1 | /* -*-c-*- |
2 | * |
3 | * $Id: mpscan.h,v 1.1 1999/09/03 08:41:12 mdw Exp $ |
4 | * |
5 | * Sequential bit scan of multiprecision integers |
6 | * |
7 | * (c) 1999 Straylight/Edgeware |
8 | */ |
9 | |
10 | /*----- Licensing notice --------------------------------------------------* |
11 | * |
12 | * This file is part of Catacomb. |
13 | * |
14 | * Catacomb is free software; you can redistribute it and/or modify |
15 | * it under the terms of the GNU Library General Public License as |
16 | * published by the Free Software Foundation; either version 2 of the |
17 | * License, or (at your option) any later version. |
18 | * |
19 | * Catacomb is distributed in the hope that it will be useful, |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | * GNU Library General Public License for more details. |
23 | * |
24 | * You should have received a copy of the GNU Library General Public |
25 | * License along with Catacomb; if not, write to the Free |
26 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
27 | * MA 02111-1307, USA. |
28 | */ |
29 | |
30 | /*----- Revision history --------------------------------------------------* |
31 | * |
32 | * $Log: mpscan.h,v $ |
33 | * Revision 1.1 1999/09/03 08:41:12 mdw |
34 | * Initial import. |
35 | * |
36 | */ |
37 | |
38 | #ifndef MPSCAN_H |
39 | #define MPSCAN_H |
40 | |
41 | #ifdef __cplusplus |
42 | extern "C" { |
43 | #endif |
44 | |
45 | /*----- Header files ------------------------------------------------------*/ |
46 | |
47 | #ifndef MPTYPES_H |
48 | # include "mptypes.h" |
49 | #endif |
50 | |
51 | /*----- Data structures ---------------------------------------------------*/ |
52 | |
53 | typedef struct mpscan { |
54 | const mpw *v; /* Vector of words to scan */ |
55 | mpw w; /* Current word to scan */ |
56 | int bits; /* Number of bits left in @w@ */ |
57 | size_t len; /* Length of the vector in words */ |
58 | } mpscan; |
59 | |
60 | /*----- Functions provided ------------------------------------------------*/ |
61 | |
62 | /* --- @mpscan_initx@ --- * |
63 | * |
64 | * Arguments: @mpscan *m@ = pointer to bitscanner structure |
65 | * @const mpw *v@ = vector of words to scan |
66 | * @size_t len@ = length of vector in words |
67 | * |
68 | * Returns: --- |
69 | * |
70 | * Use: Initializes a bitscanner from a low-level vector-and-length |
71 | * representation of an integer. Initially no bit is ready; you |
72 | * must call @mpscan_step@ before anything useful will come |
73 | * out. |
74 | */ |
75 | |
76 | #define MPSCAN_INITX(m_, v_, len_) do { \ |
77 | mpscan *_m = (m_); \ |
78 | _m->v = (v_); \ |
79 | _m->len = (len_); \ |
80 | _m->bits = 0; \ |
81 | } while (0) |
82 | |
83 | extern void mpscan_initx(mpscan */*m*/, const mpw */*v*/, size_t /*len*/); |
84 | |
85 | /* --- @mpscan_step@ --- * |
86 | * |
87 | * Arguments: @mpscan *m@ = pointer to bitscanner |
88 | * |
89 | * Returns: Nonzero if there is another bit to read. |
90 | * |
91 | * Use: Steps on to the next bit in the integer. The macro version |
92 | * evaluates its argument multiple times. |
93 | */ |
94 | |
95 | #define MPSCAN_STEP(m) \ |
96 | ((m)->bits ? ((m)->w >>= 1, \ |
97 | (m)->bits--, 1) : \ |
98 | (m)->len ? ((m)->len--, \ |
99 | (m)->w = *(m)->v++, \ |
100 | (m)->bits = MP_WBITS - 1, 1) : \ |
101 | 0) |
102 | |
103 | extern int mpscan_step(mpscan */*m*/); |
104 | |
105 | /* --- @mpscan_bit@ --- * |
106 | * |
107 | * Arguments: @const mpscan *m@ = pointer to bitscanner |
108 | * |
109 | * Returns: The value of the current bit. |
110 | * |
111 | * Use: Reads the value of the current bit looked at by a |
112 | * bitscanner. |
113 | */ |
114 | |
115 | #define MPSCAN_BIT(m) ((m)->w & 1) |
116 | |
117 | extern int mpscan_bit(const mpscan */*m*/); |
118 | |
119 | /*----- That's all, folks -------------------------------------------------*/ |
120 | |
121 | #ifdef __cplusplus |
122 | } |
123 | #endif |
124 | |
125 | #endif |