/[ascend]/trunk/base/generic/compiler/bit.h
ViewVC logotype

Contents of /trunk/base/generic/compiler/bit.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download) (as text)
Fri Oct 29 20:54:12 2004 UTC (19 years, 11 months ago) by aw0a
Original Path: trunk/ascend4/compiler/bit.h
File MIME type: text/x-chdr
File size: 6097 byte(s)
Setting up web subdirectory in repository
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 * The module is used for keeping lists of 0/1 values. Routines are provided
29 * for creating lists, set list elements, changing list elements, and other
30 * set like operations.
31 *
32 * Bits are numbered 0 .. (BLength(list)-1)
33 */
34
35 /*
36 * When #including bit.h, make sure these files are #included first:
37 * #include "compiler.h"
38 */
39
40
41 #ifndef __BIT_H_SEEN__
42 #define __BIT_H_SEEN__
43
44
45 struct BitList {
46 unsigned long length;
47 };
48
49 extern struct BitList *CreateBList(unsigned long);
50 /*
51 * struct BitList *CreateBList(len)
52 * unsigned long len;
53 * Create a bit list with len elements. The elements are all initialized to
54 * 0.
55 */
56
57 extern struct BitList *CreateFBList(unsigned long);
58 /*
59 * struct BitList *CreateFBList(len)
60 * unsigned long len;
61 * Create a bit list with len elements. The elements are all initialized to
62 * 1.
63 */
64
65 extern struct BitList *ExpandBList(struct BitList *,unsigned long);
66 /*
67 * struct BitList *ExpandBList(bl,len)
68 * struct BitList *bl;
69 * unsigned long len;
70 * The function will expand bl into a longer bitlist. It copies all the
71 * previous values from the original bit list, and it initializes all
72 * the added entries to 0. It returns the new bitlist and the old bitlist
73 * is not usable anymore.
74 */
75
76 extern struct BitList *ExpandFBList(struct BitList *,unsigned long);
77 /*
78 * struct BitList *ExpandBList(bl,len)
79 * struct BitList *bl;
80 * unsigned long len;
81 * The function will expand bl into a longer bitlist. It copies all the
82 * previous values from the original bit list, and it initializes all
83 * the added entries to 1. It returns the new bitlist and the old bitlist
84 * is not usable anymore.
85 */
86
87 extern void DestroyBList(struct BitList *);
88 /*
89 * void DestroyBList(bl)
90 * struct BitList *bl;
91 * Deallocate the memory for bl.
92 */
93
94 extern struct BitList *CopyBList(CONST struct BitList *);
95 /*
96 * struct BitList *CopyBList(bl)
97 * struct BitList *bl;
98 * Make a copy of bl and return it. The length of the copy equals that of bl,
99 * and all the elements of the copy have the same value as the corresponding
100 * elements in bl.
101 */
102
103 extern void OverwriteBList(CONST struct BitList *, struct BitList *);
104 /*
105 * struct BitList *OverwriteBList(src,target)
106 * struct BitList *src, *target;
107 * src and target must be the same length or this function will not return.
108 * Copies the bit information from src into target, overwriting anything
109 * that is in target.
110 * src and target must not be NULL.
111 */
112
113 extern unsigned long BitListBytes(CONST struct BitList *);
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 *,unsigned long);
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 *,unsigned long);
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 *,unsigned long,int);
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 extern int ReadBit(CONST struct BitList *,unsigned long);
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 *,CONST struct BitList *);
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 *,CONST struct BitList *);
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 #define BLength(bl) ((bl)->length)
174 #else
175 #define BLength(bl) BLengthF(bl)
176 #endif
177 extern unsigned long BLengthF(CONST struct BitList *);
178 /*
179 * macro BLength(bl)
180 * unsigned long BLengthF(bl)
181 * const struct BitList *bl;
182 * Return the length of bl.
183 */
184
185 extern int BitListEmpty(CONST struct BitList *);
186 /*
187 * int BitListEmpty(bl)
188 * const struct BitList *bl;
189 * Return a true value if bl is empty; otherwise, it returns a false value.
190 */
191
192
193 extern int CompBList(struct BitList *,struct BitList *);
194 /*
195 * int CompBList(bl,b2)
196 * const struct BitList *bl;
197 * const struct BitList *b2;
198 * Return 1 if bl is equal to b2, return 0 otherwise
199 */
200
201 extern unsigned long FirstNonZeroBit(CONST struct BitList *);
202 /*
203 * unsigned long FirstNonZeroBit(bl)
204 * const struct BitList *bl;
205 * Return the first non-zero bit. If it is unable to find a non-zero
206 * it will return a number greater than BLength(bl).
207 */
208 #endif /* __BIT_H_SEEN__ */

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22