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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3264 - (show annotations) (download) (as text)
Wed Nov 15 22:54:36 2017 UTC (10 months, 4 weeks ago) by jpye
File MIME type: text/x-chdr
File size: 5420 byte(s)
remaining tests for 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 Expand bl into a longer bitlist. It copies all the previous values from
67 the original bit list, and it initializes all the added entries to 0.
68 @return the new bitlist
69 @note the old bitlist 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.
77 @return the new bitlist (the old bitlist 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 ASC_DLLSPEC 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. The value of 'pos' must be in the range
109 from 0 to bl->length.
110 */
111
112 ASC_DLLSPEC void ClearBit(struct BitList *bl, unsigned long pos);
113 /**<
114 Set the pos'th bit of bl to 0. The value of 'pos' must be in the range
115 from 0 to bl->length.
116 */
117
118 ASC_DLLSPEC void CondSetBit(struct BitList *bl, unsigned long pos, int cond);
119 /**<
120 If cond is true, set the pos'th bit of bl to 1; otherwise, set it to 0.
121 */
122
123 ASC_DLLSPEC int ReadBit(CONST struct BitList *bl, unsigned long pos);
124 /**<
125 Return a true value if bit pos is 1, otherwise return FALSE.
126 The value of 'pos' must be in the range from 0 to bl->length.
127 @note: this 'true value' will not equal one; it will just be non-zero.
128 */
129
130 ASC_DLLSPEC void IntersectBLists(struct BitList *bl1, CONST struct BitList *bl2);
131 /**<
132 This routine returns the intersection of bl1 and bl2 which is stored in
133 bl1. bl2 is unchanged, unless of course bl1 and bl2 are the same.
134 */
135
136 ASC_DLLSPEC void UnionBLists(struct BitList *bl1, CONST struct BitList *bl2);
137 /**<
138 This routine returns the union of bl1 and bl2 which is stored in bl1.
139 bl2 is unchanged.
140 */
141
142 #ifdef NDEBUG
143 /** Retrieve the bit list length. */
144 #define BLength(bl) ((bl)->length)
145 #else
146 /** Retrieve the bit list length. */
147 #define BLength(bl) BLengthF(bl)
148 #endif
149 ASC_DLLSPEC unsigned long BLengthF(CONST struct BitList *bl);
150 /**<
151 Return the length of bl.
152 */
153
154 ASC_DLLSPEC int BitListEmpty(CONST struct BitList *bl);
155 /**<
156 Return a true value if bl is empty; otherwise, it returns a false value.
157 */
158
159 ASC_DLLSPEC int CompBList(struct BitList *b1, struct BitList *b2);
160 /**<
161 Return 1 if bl is equal to b2, return 0 otherwise
162 */
163
164 ASC_DLLSPEC unsigned long FirstNonZeroBit(CONST struct BitList *bl);
165 /**<
166 Return the position of the first non-zero bit (where 0 is the first position)
167 If it is unable to find a non-zero it will return a number greater than BLength(bl).
168 */
169
170 /* @} */
171
172 #endif /* ASC_BIT_H */
173

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