2 |
7u83 |
1 |
/*
|
|
|
2 |
Crown Copyright (c) 1997
|
|
|
3 |
|
|
|
4 |
This TenDRA(r) Computer Program is subject to Copyright
|
|
|
5 |
owned by the United Kingdom Secretary of State for Defence
|
|
|
6 |
acting through the Defence Evaluation and Research Agency
|
|
|
7 |
(DERA). It is made available to Recipients with a
|
|
|
8 |
royalty-free licence for its use, reproduction, transfer
|
|
|
9 |
to other parties and amendment for any purpose not excluding
|
|
|
10 |
product development provided that any such use et cetera
|
|
|
11 |
shall be deemed to be acceptance of the following conditions:-
|
|
|
12 |
|
|
|
13 |
(1) Its Recipients shall ensure that this Notice is
|
|
|
14 |
reproduced upon any copies or amended versions of it;
|
|
|
15 |
|
|
|
16 |
(2) Any amended version of it shall be clearly marked to
|
|
|
17 |
show both the nature of and the organisation responsible
|
|
|
18 |
for the relevant amendment or amendments;
|
|
|
19 |
|
|
|
20 |
(3) Its onward transfer from a recipient to another
|
|
|
21 |
party shall be deemed to be that party's acceptance of
|
|
|
22 |
these conditions;
|
|
|
23 |
|
|
|
24 |
(4) DERA gives no warranty or assurance as to its
|
|
|
25 |
quality or suitability for any purpose and DERA accepts
|
|
|
26 |
no liability whatsoever in relation to any use to which
|
|
|
27 |
it may be put.
|
|
|
28 |
*/
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
/**** bitvec.h --- Bit vector manipulation.
|
|
|
32 |
*
|
|
|
33 |
** Author: Steve Folkes <smf@hermes.mod.uk>
|
|
|
34 |
*
|
|
|
35 |
**** Commentary:
|
|
|
36 |
*
|
|
|
37 |
***=== INTRODUCTION =========================================================
|
|
|
38 |
*
|
|
|
39 |
* This file specifies the interface to a single size bit vector manipulation
|
|
|
40 |
* facility. It is necessary to call the ``bitvec_set_size'' function to set
|
|
|
41 |
* the size of these bit vectors, before any are actually created.
|
|
|
42 |
*
|
|
|
43 |
***=== TYPES ================================================================
|
|
|
44 |
*
|
|
|
45 |
** Type: BitVecT
|
|
|
46 |
** Type: BitVecP
|
|
|
47 |
** Repr: <private>
|
|
|
48 |
*
|
|
|
49 |
* This is the bit vector type.
|
|
|
50 |
*
|
|
|
51 |
***=== FUNCTIONS ============================================================
|
|
|
52 |
*
|
|
|
53 |
** Function: void bitvec_set_size
|
|
|
54 |
* PROTO_S ((unsigned size))
|
|
|
55 |
** Exceptions:
|
|
|
56 |
*
|
|
|
57 |
* This function should be called once, before any bit vectors are
|
|
|
58 |
* initialised. Its argument should specify the number of bits in a bit
|
|
|
59 |
* vector. The bits will be numbered from zero to one less than the number
|
|
|
60 |
* specified.
|
|
|
61 |
*
|
|
|
62 |
** Function: void bitvec_init
|
|
|
63 |
* PROTO_S ((BitVecP bitvec))
|
|
|
64 |
** Exceptions: XX_dalloc_no_memory
|
|
|
65 |
*
|
|
|
66 |
* This function initialises the specified bit vector. Initially, all bits
|
|
|
67 |
* are zero.
|
|
|
68 |
*
|
|
|
69 |
** Function: void bitvec_copy
|
|
|
70 |
* PROTO_S ((BitVecP to, BitVecP from))
|
|
|
71 |
** Exceptions: XX_dalloc_no_memory
|
|
|
72 |
*
|
|
|
73 |
* This function initialises the to bit vector from the from bit vector. It
|
|
|
74 |
* is not necessary to have initialised the to bit vector with the
|
|
|
75 |
* `bitvec_init' function previously.
|
|
|
76 |
*
|
|
|
77 |
** Function: void bitvec_replace
|
|
|
78 |
* PROTO_S ((BitVecP to, BitVecP from))
|
|
|
79 |
** Exceptions:
|
|
|
80 |
*
|
|
|
81 |
* This function copies the from bit vector into the to bit vector. The to
|
|
|
82 |
* bit vector must have been initialised previously.
|
|
|
83 |
*
|
|
|
84 |
** Function: void bitvec_empty
|
|
|
85 |
* PROTO_S ((BitVecP bitvec))
|
|
|
86 |
** Exceptions:
|
|
|
87 |
*
|
|
|
88 |
* This function sets all of the bits in the specified bit vector to zero.
|
|
|
89 |
*
|
|
|
90 |
** Function: BoolT bitvec_is_empty
|
|
|
91 |
* PROTO_S ((BitVecP bitvec))
|
|
|
92 |
** Exceptions:
|
|
|
93 |
*
|
|
|
94 |
* This function returns true if all of the bits in the specified bit vector
|
|
|
95 |
* are zero, and false otherwise.
|
|
|
96 |
*
|
|
|
97 |
** Function: BoolT bitvec_is_full
|
|
|
98 |
* PROTO_S ((BitVecP bitvec))
|
|
|
99 |
** Exceptions:
|
|
|
100 |
*
|
|
|
101 |
* This function returns true if all of the bits in the specified bit vector
|
|
|
102 |
* are set, and false otherwise.
|
|
|
103 |
*
|
|
|
104 |
** Function: void bitvec_set
|
|
|
105 |
* PROTO_S ((BitVecP bitvec, unsigned bit))
|
|
|
106 |
** Exceptions:
|
|
|
107 |
*
|
|
|
108 |
* This function sets the specified bit in the specified bit vector to one.
|
|
|
109 |
* Bits are numbered from zero. If the bit is out of range, then the effect
|
|
|
110 |
* of this function is undefined.
|
|
|
111 |
*
|
|
|
112 |
** Function: BoolT bitvec_is_set
|
|
|
113 |
* PROTO_S ((BitVecP bitvec, unsigned bit))
|
|
|
114 |
** Exceptions:
|
|
|
115 |
*
|
|
|
116 |
* This function returns true if the specified bit in the specified bit vector
|
|
|
117 |
* is set to one, and false otherwise. Bits are numbered from zero. If the
|
|
|
118 |
* bit is out of range, the effect of this function is undefined.
|
|
|
119 |
*
|
|
|
120 |
** Function: void bitvec_or
|
|
|
121 |
* PROTO_S ((BitVecP to, BitVecP from))
|
|
|
122 |
** Exceptions:
|
|
|
123 |
*
|
|
|
124 |
* This function performs an in-place bitwise or of the to bit vector and the
|
|
|
125 |
* from bit vector, leaving the result in the to bit vector.
|
|
|
126 |
*
|
|
|
127 |
** Function: void bitvec_and
|
|
|
128 |
* PROTO_S ((BitVecP to, BitVecPfrom))
|
|
|
129 |
** Exceptions:
|
|
|
130 |
*
|
|
|
131 |
* This function performs an in-place bitwise and of the to bit vector and the
|
|
|
132 |
* from bit vector, leaving the result in the to bit vector.
|
|
|
133 |
*
|
|
|
134 |
** Function: void bitvec_not
|
|
|
135 |
* PROTO_S ((BitVecP to))
|
|
|
136 |
** Exceptions:
|
|
|
137 |
*
|
|
|
138 |
* This function performs an in-place bitwise negation of the to bit vector.
|
|
|
139 |
*
|
|
|
140 |
** Function: BoolT bitvec_equal
|
|
|
141 |
* PROTO_S ((BitVecP bitvec1, BitVecP bitvec2))
|
|
|
142 |
** Exceptions:
|
|
|
143 |
*
|
|
|
144 |
* This function returns true if both of the specified bit vectors are equal,
|
|
|
145 |
* and false otherwise.
|
|
|
146 |
*
|
|
|
147 |
** Function: BoolT bitvec_intersects
|
|
|
148 |
* PROTO_S ((BitVecP bitvec1, BitVecP bitvec2))
|
|
|
149 |
** Exceptions:
|
|
|
150 |
*
|
|
|
151 |
* This function returns true if the bitwise and of the specified bit vectors
|
|
|
152 |
* contains at least one bit that is set to one, and false otherwise.
|
|
|
153 |
*
|
|
|
154 |
** Function: unsigned bitvec_num_bits
|
|
|
155 |
* PROTO_S ((BitVecP bitvec))
|
|
|
156 |
** Exceptions:
|
|
|
157 |
*
|
|
|
158 |
* This function returns the number of bits in the bit vector that are set to
|
|
|
159 |
* one.
|
|
|
160 |
*
|
|
|
161 |
** Function: unsigned bitvec_first_bit
|
|
|
162 |
* PROTO_S ((BitVecP bitvec))
|
|
|
163 |
** Exceptions:
|
|
|
164 |
*
|
|
|
165 |
* This function returns the index of the first bit in the specified bit
|
|
|
166 |
* vector that is set to one.
|
|
|
167 |
*
|
|
|
168 |
** Function: BoolT bitvec_next_bit
|
|
|
169 |
* PROTO_S ((BitVecP bitvec, unsigned *next_ref))
|
|
|
170 |
** Exceptions:
|
|
|
171 |
*
|
|
|
172 |
* This function looks for the first bit set to one in the specified bit
|
|
|
173 |
* vector with a higher index than that specified in the number pointed to by
|
|
|
174 |
* next_ref. If such a bit is found, then the index of that bit is written
|
|
|
175 |
* back into next_ref, and the function returns true. If no such bit is
|
|
|
176 |
* found, then the function returns false.
|
|
|
177 |
*
|
|
|
178 |
** Function: void bitvec_destroy
|
|
|
179 |
* PROTO_S ((BitVecP bitvec))
|
|
|
180 |
** Exceptions:
|
|
|
181 |
*
|
|
|
182 |
* This function destroys the specified bit vector. After this, it should be
|
|
|
183 |
* reinitialised before it is used.
|
|
|
184 |
*
|
|
|
185 |
** Function: void write_bitvec_indices
|
|
|
186 |
* PROTO_S ((OStreamP ostream, BitVecP bitvec))
|
|
|
187 |
** Exceptions: XX_dalloc_no_memory, XX_ostream_write_error
|
|
|
188 |
*
|
|
|
189 |
* This function writes out to the specified ostream the indices of all bits
|
|
|
190 |
* in the specified bit vector that are set to one.
|
|
|
191 |
*
|
|
|
192 |
**** Change log:
|
|
|
193 |
* $Log: bitvec.h,v $
|
|
|
194 |
* Revision 1.1.1.1 1998/01/17 15:57:45 release
|
|
|
195 |
* First version to be checked into rolling release.
|
|
|
196 |
*
|
|
|
197 |
* Revision 1.2 1994/12/15 09:57:01 smf
|
|
|
198 |
* Brought into line with OSSG C Coding Standards Document, as per
|
|
|
199 |
* "CR94_178.sid+tld-update".
|
|
|
200 |
*
|
|
|
201 |
* Revision 1.1.1.1 1994/07/25 16:05:47 smf
|
|
|
202 |
* Initial import of library shared files.
|
|
|
203 |
*
|
|
|
204 |
**/
|
|
|
205 |
|
|
|
206 |
/****************************************************************************/
|
|
|
207 |
|
|
|
208 |
#ifndef H_BITVEC
|
|
|
209 |
#define H_BITVEC
|
|
|
210 |
|
|
|
211 |
#include "os-interface.h"
|
|
|
212 |
#include "dalloc.h"
|
|
|
213 |
#include "ostream.h"
|
|
|
214 |
|
|
|
215 |
/*--------------------------------------------------------------------------*/
|
|
|
216 |
|
|
|
217 |
typedef struct BitVecT {
|
|
|
218 |
ByteP bits;
|
|
|
219 |
} BitVecT, *BitVecP;
|
|
|
220 |
|
|
|
221 |
/*--------------------------------------------------------------------------*/
|
|
|
222 |
|
|
|
223 |
extern void bitvec_set_size
|
|
|
224 |
PROTO_S ((unsigned));
|
|
|
225 |
extern void bitvec_init
|
|
|
226 |
PROTO_S ((BitVecP));
|
|
|
227 |
extern void bitvec_copy
|
|
|
228 |
PROTO_S ((BitVecP, BitVecP));
|
|
|
229 |
extern void bitvec_replace
|
|
|
230 |
PROTO_S ((BitVecP, BitVecP));
|
|
|
231 |
extern void bitvec_empty
|
|
|
232 |
PROTO_S ((BitVecP));
|
|
|
233 |
extern BoolT bitvec_is_empty
|
|
|
234 |
PROTO_S ((BitVecP));
|
|
|
235 |
extern BoolT bitvec_is_full
|
|
|
236 |
PROTO_S ((BitVecP));
|
|
|
237 |
extern void bitvec_set
|
|
|
238 |
PROTO_S ((BitVecP, unsigned));
|
|
|
239 |
extern BoolT bitvec_is_set
|
|
|
240 |
PROTO_S ((BitVecP, unsigned));
|
|
|
241 |
extern void bitvec_or
|
|
|
242 |
PROTO_S ((BitVecP, BitVecP));
|
|
|
243 |
extern void bitvec_and
|
|
|
244 |
PROTO_S ((BitVecP, BitVecP));
|
|
|
245 |
extern void bitvec_not
|
|
|
246 |
PROTO_S ((BitVecP));
|
|
|
247 |
extern BoolT bitvec_equal
|
|
|
248 |
PROTO_S ((BitVecP, BitVecP));
|
|
|
249 |
extern BoolT bitvec_intersects
|
|
|
250 |
PROTO_S ((BitVecP, BitVecP));
|
|
|
251 |
extern unsigned bitvec_num_bits
|
|
|
252 |
PROTO_S ((BitVecP));
|
|
|
253 |
extern unsigned bitvec_first_bit
|
|
|
254 |
PROTO_S ((BitVecP));
|
|
|
255 |
extern BoolT bitvec_next_bit
|
|
|
256 |
PROTO_S ((BitVecP, unsigned *));
|
|
|
257 |
extern void bitvec_destroy
|
|
|
258 |
PROTO_S ((BitVecP));
|
|
|
259 |
|
|
|
260 |
extern void write_bitvec_indices
|
|
|
261 |
PROTO_S ((OStreamP, BitVecP));
|
|
|
262 |
|
|
|
263 |
#endif /* !defined (H_BITVEC) */
|
|
|
264 |
|
|
|
265 |
/*
|
|
|
266 |
* Local variables(smf):
|
|
|
267 |
* eval: (include::add-path-entry "../os-interface" "../generated")
|
|
|
268 |
* end:
|
|
|
269 |
**/
|