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