/[ascend]/trunk/ascend/utilities/bit.h
ViewVC logotype

Contents of /trunk/ascend/utilities/bit.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3263 - (show annotations) (download) (as text)
Wed Nov 15 22:27:25 2017 UTC (11 months ago) by jpye
File MIME type: text/x-chdr
File size: 5298 byte(s)
expanding tests of bit.c

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 this program. If not, see <http://www.gnu.org/licenses/>.
25 */
26
27 /** @file
28 * The module is used for keeping bit lists (lists of 0/1 values).
29 * Routines are provided for creating lists, set list elements,
30 * changing list elements, and other set-like operations.<br><br>
31 *
32 * Bits are numbered 0 .. (BLength(list)-1)
33 * <pre>
34 * When #including bit.h, make sure these files are #included first:
35 * #include "utilities/ascConfig.h"
36 * #include "compiler.h"
37 * </pre>
38 */
39
40 #ifndef ASC_BIT_H
41 #define ASC_BIT_H
42
43 #include <ascend/general/platform.h>
44
45 /** @addtogroup utilities_bit Utilities Bit-list
46 @{
47 */
48
49 /** Data structure for holding bit lists. */
50 struct BitList {
51 unsigned long length;
52 };
53
54 ASC_DLLSPEC struct BitList *CreateBList(unsigned long len);
55 /**<
56 * Create a bit list with len elements. The elements are all initialized to 0.
57 */
58
59 ASC_DLLSPEC struct BitList *CreateFBList(unsigned long len);
60 /**<
61 * Create a bit list with len elements. The elements are all initialized to 1.
62 */
63
64 ASC_DLLSPEC struct BitList *ExpandBList(struct BitList *bl, unsigned long len);
65 /**<
66 * The function will expand bl into a longer bitlist. It copies all the
67 * previous values from the original bit list, and it initializes all
68 * the added entries to 0. It returns the new bitlist and the old bitlist
69 * is not usable anymore.
70 */
71
72 ASC_DLLSPEC struct BitList *ExpandFBList(struct BitList *bl, unsigned long len);
73 /**<
74 * The function will expand bl into a longer bitlist. It copies all the
75 * previous values from the original bit list, and it initializes all
76 * the added entries to 1. It returns the new bitlist and the old bitlist
77 * is not usable anymore.
78 */
79
80 ASC_DLLSPEC void DestroyBList(struct BitList *bl);
81 /**<
82 * Deallocate the memory for bl.
83 */
84
85 ASC_DLLSPEC struct BitList *CopyBList(CONST struct BitList *bl);
86 /**<
87 * Make a copy of bl and return it. The length of the copy equals that of bl,
88 * and all the elements of the copy have the same value as the corresponding
89 * elements in bl.
90 */
91
92 extern void OverwriteBList(CONST struct BitList *src, struct BitList *target);
93 /**<
94 * Copies the bit information from src into target. Overwrites anything
95 * that is in target.
96 * src and target must be the same length or this function will not return.
97 * src and target must not be NULL.
98 */
99
100 ASC_DLLSPEC unsigned long BitListBytes(CONST struct BitList *bl);
101 /**<
102 * Returns the number of bytes allocated to the bitlist (including
103 both the data bits as well as the 'struct BitList' overhead).
104 */
105
106 ASC_DLLSPEC void SetBit(struct BitList *bl, unsigned long pos);
107 /**<
108 * Set the pos'th bit of bl to 1.
109 */
110
111 ASC_DLLSPEC void ClearBit(struct BitList *bl, unsigned long pos);
112 /**<
113 * Set the pos'th bit of bl to 0.
114 */
115
116 extern void CondSetBit(struct BitList *bl, unsigned long pos, int cond);
117 /**<
118 * If cond is true, set the pos'th bit of bl to 1; otherwise, set it to 0.
119 */
120
121 ASC_DLLSPEC int ReadBit(CONST struct BitList *bl, unsigned long pos);
122 /**<
123 Return a true value if bit pos is 1, otherwise return FALSE.
124 @note: this 'true value' will not equal one; it will just be non-zero.
125
126 */
127
128 extern void IntersectBLists(struct BitList *bl1, CONST struct BitList *bl2);
129 /**<
130 * This routine returns the intersection of bl1 and bl2 which is stored in
131 * bl1. bl2 is unchanged, unless of course bl1 and bl2 are the same.
132 */
133
134 extern void UnionBLists(struct BitList *bl1, CONST struct BitList *bl2);
135 /**<
136 * This routine returns the union of bl1 and bl2 which is stored in bl1.
137 * bl2 is unchanged.
138 */
139
140 #ifdef NDEBUG
141 /** Retrieve the bit list length. */
142 #define BLength(bl) ((bl)->length)
143 #else
144 /** Retrieve the bit list length. */
145 #define BLength(bl) BLengthF(bl)
146 #endif
147 ASC_DLLSPEC unsigned long BLengthF(CONST struct BitList *bl);
148 /**<
149 * Return the length of bl.
150 */
151
152 ASC_DLLSPEC int BitListEmpty(CONST struct BitList *bl);
153 /**<
154 * Return a true value if bl is empty; otherwise, it returns a false value.
155 */
156
157 ASC_DLLSPEC int CompBList(struct BitList *b1, struct BitList *b2);
158 /**<
159 * Return 1 if bl is equal to b2, return 0 otherwise
160 */
161
162 extern unsigned long FirstNonZeroBit(CONST struct BitList *bl);
163 /**<
164 * Return the first non-zero bit. If it is unable to find a non-zero
165 * it will return a number greater than BLength(bl).
166 */
167
168 /* @} */
169
170 #endif /* ASC_BIT_H */
171

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