1 |
/* |
2 |
* Bit lists |
3 |
* by Tom Epperly |
4 |
* Version: $Revision: 1.7 $ |
5 |
* Version control file: $RCSfile: bit.h,v $ |
6 |
* Date last modified: $Date: 1997/09/08 18:07:32 $ |
7 |
* Last modified by: $Author: ballan $ |
8 |
* |
9 |
* This file is part of the Ascend Language Interpreter. |
10 |
* |
11 |
* Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly |
12 |
* |
13 |
* The Ascend Language Interpreter is free software; you can redistribute |
14 |
* it and/or modify it under the terms of the GNU General Public License as |
15 |
* published by the Free Software Foundation; either version 2 of the |
16 |
* License, or (at your option) any later version. |
17 |
* |
18 |
* The Ascend Language Interpreter is distributed in hope that it will be |
19 |
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
21 |
* General Public License for more details. |
22 |
* |
23 |
* You should have received a copy of the GNU General Public License |
24 |
* along with the program; if not, write to the Free Software Foundation, |
25 |
* Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named |
26 |
* COPYING. |
27 |
*/ |
28 |
|
29 |
/** @file |
30 |
* The module is used for keeping bit lists (lists of 0/1 values). |
31 |
* Routines are provided for creating lists, set list elements, |
32 |
* changing list elements, and other set-like operations.<br><br> |
33 |
* |
34 |
* Bits are numbered 0 .. (BLength(list)-1) |
35 |
* <pre> |
36 |
* When #including bit.h, make sure these files are #included first: |
37 |
* #include "utilities/ascConfig.h" |
38 |
* #include "compiler.h" |
39 |
* </pre> |
40 |
*/ |
41 |
|
42 |
#ifndef ASC_BIT_H |
43 |
#define ASC_BIT_H |
44 |
|
45 |
/** addtogroup compiler Compiler |
46 |
@{ |
47 |
*/ |
48 |
|
49 |
/** Data structure for holding bit lists. */ |
50 |
struct BitList { |
51 |
unsigned long length; |
52 |
}; |
53 |
|
54 |
extern struct BitList *CreateBList(unsigned long len); |
55 |
/**< |
56 |
* <!-- struct BitList *CreateBList(len) --> |
57 |
* <!-- unsigned long len; --> |
58 |
* Create a bit list with len elements. The elements are all initialized to 0. |
59 |
*/ |
60 |
|
61 |
extern struct BitList *CreateFBList(unsigned long len); |
62 |
/**< |
63 |
* <!-- struct BitList *CreateFBList(len) --> |
64 |
* <!-- unsigned long len; --> |
65 |
* Create a bit list with len elements. The elements are all initialized to 1. |
66 |
*/ |
67 |
|
68 |
extern struct BitList *ExpandBList(struct BitList *bl, unsigned long len); |
69 |
/**< |
70 |
* <!-- struct BitList *ExpandBList(bl,len) --> |
71 |
* <!-- struct BitList *bl; --> |
72 |
* <!-- unsigned long len; --> |
73 |
* The function will expand bl into a longer bitlist. It copies all the |
74 |
* previous values from the original bit list, and it initializes all |
75 |
* the added entries to 0. It returns the new bitlist and the old bitlist |
76 |
* is not usable anymore. |
77 |
*/ |
78 |
|
79 |
extern struct BitList *ExpandFBList(struct BitList *bl, unsigned long len); |
80 |
/**< |
81 |
* <!-- struct BitList *ExpandBList(bl,len) --> |
82 |
* <!-- struct BitList *bl; --> |
83 |
* <!-- unsigned long len; --> |
84 |
* The function will expand bl into a longer bitlist. It copies all the |
85 |
* previous values from the original bit list, and it initializes all |
86 |
* the added entries to 1. It returns the new bitlist and the old bitlist |
87 |
* is not usable anymore. |
88 |
*/ |
89 |
|
90 |
extern void DestroyBList(struct BitList *bl); |
91 |
/**< |
92 |
* <!-- void DestroyBList(bl) --> |
93 |
* <!-- struct BitList *bl; --> |
94 |
* Deallocate the memory for bl. |
95 |
*/ |
96 |
|
97 |
extern struct BitList *CopyBList(CONST struct BitList *bl); |
98 |
/**< |
99 |
* <!-- struct BitList *CopyBList(bl) --> |
100 |
* <!-- struct BitList *bl; --> |
101 |
* Make a copy of bl and return it. The length of the copy equals that of bl, |
102 |
* and all the elements of the copy have the same value as the corresponding |
103 |
* elements in bl. |
104 |
*/ |
105 |
|
106 |
extern void OverwriteBList(CONST struct BitList *src, struct BitList *target); |
107 |
/**< |
108 |
* <!-- struct BitList *OverwriteBList(src,target) --> |
109 |
* <!-- struct BitList *src, *target; --> |
110 |
* <!-- src and target must be the same length or this function will -->not return. |
111 |
* Copies the bit information from src into target. Overwrites anything |
112 |
* that is in target. |
113 |
* src and target must be the same length or this function will not return. |
114 |
* src and target must not be NULL. |
115 |
*/ |
116 |
|
117 |
extern unsigned long BitListBytes(CONST struct BitList *bl); |
118 |
/**< |
119 |
* <!-- unsigned long BitListBytes(bl) --> |
120 |
* <!-- struct BitList *bl; --> |
121 |
* <!-- unsigned long bytes; --> |
122 |
* Returns the number of bytes allocated to the bitlist. |
123 |
*/ |
124 |
|
125 |
extern void SetBit(struct BitList *bl, unsigned long pos); |
126 |
/**< |
127 |
* <!-- void SetBit(bl,pos) --> |
128 |
* <!-- struct BitList *bl; --> |
129 |
* <!-- unsigned long pos; --> |
130 |
* Set the pos'th bit of bl to 1. |
131 |
*/ |
132 |
|
133 |
extern void ClearBit(struct BitList *bl, unsigned long pos); |
134 |
/**< |
135 |
* <!-- void ClearBit(bl,pos) --> |
136 |
* <!-- struct BitList *bl; --> |
137 |
* <!-- unsigned long pos; --> |
138 |
* Set the pos'th bit of bl to 0. |
139 |
*/ |
140 |
|
141 |
extern void CondSetBit(struct BitList *bl, unsigned long pos, int cond); |
142 |
/**< |
143 |
* <!-- void CondSetBit(bl,pos,cond) --> |
144 |
* <!-- struct BitList *bl; --> |
145 |
* <!-- unsigned long pos; --> |
146 |
* <!-- int cond; --> |
147 |
* If cond is true, set the pos'th bit of bl to 1; otherwise, set it to 0. |
148 |
*/ |
149 |
|
150 |
ASC_DLLSPEC int ReadBit(CONST struct BitList *bl, unsigned long pos); |
151 |
/**< |
152 |
* <!-- int ReadBit(bl,pos) --> |
153 |
* <!-- struct BitList *bl; --> |
154 |
* <!-- unsigned long pos; --> |
155 |
* Return a true value if bit pos is 1, otherwise return FALSE. |
156 |
*/ |
157 |
|
158 |
extern void IntersectBLists(struct BitList *bl1, CONST struct BitList *bl2); |
159 |
/**< |
160 |
* <!-- void IntersectBList(bl1,bl2) --> |
161 |
* <!-- struct BitList *bl1; --> |
162 |
* <!-- const struct BitList *bl2; --> |
163 |
* This routine returns the intersection of bl1 and bl2 which is stored in |
164 |
* bl1. bl2 is unchanged, unless of course bl1 and bl2 are the same. |
165 |
*/ |
166 |
|
167 |
extern void UnionBLists(struct BitList *bl1, CONST struct BitList *bl2); |
168 |
/**< |
169 |
* <!-- void UnionBLists(bl1,bl2) --> |
170 |
* <!-- struct BitList *bl1; --> |
171 |
* <!-- const struct BitList *bl2; --> |
172 |
* This routine returns the union of bl1 and bl2 which is stored in bl1. |
173 |
* bl2 is unchanged. |
174 |
*/ |
175 |
|
176 |
#ifdef NDEBUG |
177 |
/** Retrieve the bit list length. */ |
178 |
#define BLength(bl) ((bl)->length) |
179 |
#else |
180 |
/** Retrieve the bit list length. */ |
181 |
#define BLength(bl) BLengthF(bl) |
182 |
#endif |
183 |
extern unsigned long BLengthF(CONST struct BitList *bl); |
184 |
/**< |
185 |
* <!-- macro BLength(bl) --> |
186 |
* <!-- unsigned long BLengthF(bl) --> |
187 |
* <!-- const struct BitList *bl; --> |
188 |
* Return the length of bl. |
189 |
*/ |
190 |
|
191 |
ASC_DLLSPEC int BitListEmpty(CONST struct BitList *bl); |
192 |
/**< |
193 |
* <!-- int BitListEmpty(bl) --> |
194 |
* <!-- const struct BitList *bl; --> |
195 |
* Return a true value if bl is empty; otherwise, it returns a false value. |
196 |
*/ |
197 |
|
198 |
extern int CompBList(struct BitList *b1, struct BitList *b2); |
199 |
/**< |
200 |
* <!-- int CompBList(bl,b2) --> |
201 |
* <!-- const struct BitList *bl; --> |
202 |
* <!-- const struct BitList *b2; --> |
203 |
* Return 1 if bl is equal to b2, return 0 otherwise |
204 |
*/ |
205 |
|
206 |
extern unsigned long FirstNonZeroBit(CONST struct BitList *bl); |
207 |
/**< |
208 |
* <!-- unsigned long FirstNonZeroBit(bl) --> |
209 |
* <!-- const struct BitList *bl; --> |
210 |
* Return the first non-zero bit. If it is unable to find a non-zero |
211 |
* it will return a number greater than BLength(bl). |
212 |
*/ |
213 |
|
214 |
/* @} */ |
215 |
|
216 |
#endif /* ASC_BIT_H */ |
217 |
|