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 __BIT_H_SEEN__ |
43 |
#define __BIT_H_SEEN__ |
44 |
|
45 |
/** Data structure for holding bit lists. */ |
46 |
struct BitList { |
47 |
unsigned long length; |
48 |
}; |
49 |
|
50 |
extern struct BitList *CreateBList(unsigned long len); |
51 |
/**< |
52 |
* <!-- struct BitList *CreateBList(len) --> |
53 |
* <!-- unsigned long len; --> |
54 |
* Create a bit list with len elements. The elements are all initialized to 0. |
55 |
*/ |
56 |
|
57 |
extern struct BitList *CreateFBList(unsigned long len); |
58 |
/**< |
59 |
* <!-- struct BitList *CreateFBList(len) --> |
60 |
* <!-- unsigned long len; --> |
61 |
* Create a bit list with len elements. The elements are all initialized to 1. |
62 |
*/ |
63 |
|
64 |
extern struct BitList *ExpandBList(struct BitList *bl, unsigned long len); |
65 |
/**< |
66 |
* <!-- struct BitList *ExpandBList(bl,len) --> |
67 |
* <!-- struct BitList *bl; --> |
68 |
* <!-- unsigned long len; --> |
69 |
* The function will expand bl into a longer bitlist. It copies all the |
70 |
* previous values from the original bit list, and it initializes all |
71 |
* the added entries to 0. It returns the new bitlist and the old bitlist |
72 |
* is not usable anymore. |
73 |
*/ |
74 |
|
75 |
extern struct BitList *ExpandFBList(struct BitList *bl, unsigned long len); |
76 |
/**< |
77 |
* <!-- struct BitList *ExpandBList(bl,len) --> |
78 |
* <!-- struct BitList *bl; --> |
79 |
* <!-- unsigned long len; --> |
80 |
* The function will expand bl into a longer bitlist. It copies all the |
81 |
* previous values from the original bit list, and it initializes all |
82 |
* the added entries to 1. It returns the new bitlist and the old bitlist |
83 |
* is not usable anymore. |
84 |
*/ |
85 |
|
86 |
extern void DestroyBList(struct BitList *bl); |
87 |
/**< |
88 |
* <!-- void DestroyBList(bl) --> |
89 |
* <!-- struct BitList *bl; --> |
90 |
* Deallocate the memory for bl. |
91 |
*/ |
92 |
|
93 |
extern struct BitList *CopyBList(CONST struct BitList *bl); |
94 |
/**< |
95 |
* <!-- struct BitList *CopyBList(bl) --> |
96 |
* <!-- struct BitList *bl; --> |
97 |
* Make a copy of bl and return it. The length of the copy equals that of bl, |
98 |
* and all the elements of the copy have the same value as the corresponding |
99 |
* elements in bl. |
100 |
*/ |
101 |
|
102 |
extern void OverwriteBList(CONST struct BitList *src, struct BitList *target); |
103 |
/**< |
104 |
* <!-- struct BitList *OverwriteBList(src,target) --> |
105 |
* <!-- struct BitList *src, *target; --> |
106 |
* <!-- src and target must be the same length or this function will -->not return. |
107 |
* Copies the bit information from src into target. Overwrites anything |
108 |
* that is in target. |
109 |
* src and target must be the same length or this function will not return. |
110 |
* src and target must not be NULL. |
111 |
*/ |
112 |
|
113 |
extern unsigned long BitListBytes(CONST struct BitList *bl); |
114 |
/**< |
115 |
* <!-- unsigned long BitListBytes(bl) --> |
116 |
* <!-- struct BitList *bl; --> |
117 |
* <!-- unsigned long bytes; --> |
118 |
* Returns the number of bytes allocated to the bitlist. |
119 |
*/ |
120 |
|
121 |
extern void SetBit(struct BitList *bl, unsigned long pos); |
122 |
/**< |
123 |
* <!-- void SetBit(bl,pos) --> |
124 |
* <!-- struct BitList *bl; --> |
125 |
* <!-- unsigned long pos; --> |
126 |
* Set the pos'th bit of bl to 1. |
127 |
*/ |
128 |
|
129 |
extern void ClearBit(struct BitList *bl, unsigned long pos); |
130 |
/**< |
131 |
* <!-- void ClearBit(bl,pos) --> |
132 |
* <!-- struct BitList *bl; --> |
133 |
* <!-- unsigned long pos; --> |
134 |
* Set the pos'th bit of bl to 0. |
135 |
*/ |
136 |
|
137 |
extern void CondSetBit(struct BitList *bl, unsigned long pos, int cond); |
138 |
/**< |
139 |
* <!-- void CondSetBit(bl,pos,cond) --> |
140 |
* <!-- struct BitList *bl; --> |
141 |
* <!-- unsigned long pos; --> |
142 |
* <!-- int cond; --> |
143 |
* If cond is true, set the pos'th bit of bl to 1; otherwise, set it to 0. |
144 |
*/ |
145 |
|
146 |
ASC_DLLSPEC(int ) ReadBit(CONST struct BitList *bl, unsigned long pos); |
147 |
/**< |
148 |
* <!-- int ReadBit(bl,pos) --> |
149 |
* <!-- struct BitList *bl; --> |
150 |
* <!-- unsigned long pos; --> |
151 |
* Return a true value if bit pos is 1, otherwise return FALSE. |
152 |
*/ |
153 |
|
154 |
extern void IntersectBLists(struct BitList *bl1, CONST struct BitList *bl2); |
155 |
/**< |
156 |
* <!-- void IntersectBList(bl1,bl2) --> |
157 |
* <!-- struct BitList *bl1; --> |
158 |
* <!-- const struct BitList *bl2; --> |
159 |
* This routine returns the intersection of bl1 and bl2 which is stored in |
160 |
* bl1. bl2 is unchanged, unless of course bl1 and bl2 are the same. |
161 |
*/ |
162 |
|
163 |
extern void UnionBLists(struct BitList *bl1, CONST struct BitList *bl2); |
164 |
/**< |
165 |
* <!-- void UnionBLists(bl1,bl2) --> |
166 |
* <!-- struct BitList *bl1; --> |
167 |
* <!-- const struct BitList *bl2; --> |
168 |
* This routine returns the union of bl1 and bl2 which is stored in bl1. |
169 |
* bl2 is unchanged. |
170 |
*/ |
171 |
|
172 |
#ifdef NDEBUG |
173 |
/** Retrieve the bit list length. */ |
174 |
#define BLength(bl) ((bl)->length) |
175 |
#else |
176 |
/** Retrieve the bit list length. */ |
177 |
#define BLength(bl) BLengthF(bl) |
178 |
#endif |
179 |
extern unsigned long BLengthF(CONST struct BitList *bl); |
180 |
/**< |
181 |
* <!-- macro BLength(bl) --> |
182 |
* <!-- unsigned long BLengthF(bl) --> |
183 |
* <!-- const struct BitList *bl; --> |
184 |
* Return the length of bl. |
185 |
*/ |
186 |
|
187 |
ASC_DLLSPEC(int ) BitListEmpty(CONST struct BitList *bl); |
188 |
/**< |
189 |
* <!-- int BitListEmpty(bl) --> |
190 |
* <!-- const struct BitList *bl; --> |
191 |
* Return a true value if bl is empty; otherwise, it returns a false value. |
192 |
*/ |
193 |
|
194 |
extern int CompBList(struct BitList *b1, struct BitList *b2); |
195 |
/**< |
196 |
* <!-- int CompBList(bl,b2) --> |
197 |
* <!-- const struct BitList *bl; --> |
198 |
* <!-- const struct BitList *b2; --> |
199 |
* Return 1 if bl is equal to b2, return 0 otherwise |
200 |
*/ |
201 |
|
202 |
extern unsigned long FirstNonZeroBit(CONST struct BitList *bl); |
203 |
/**< |
204 |
* <!-- unsigned long FirstNonZeroBit(bl) --> |
205 |
* <!-- const struct BitList *bl; --> |
206 |
* Return the first non-zero bit. If it is unable to find a non-zero |
207 |
* it will return a number greater than BLength(bl). |
208 |
*/ |
209 |
|
210 |
#endif /* __BIT_H_SEEN__ */ |
211 |
|