tlds
Transactional Operations for Linked Data Structures
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
bitmap.h
Go to the documentation of this file.
1 /* =============================================================================
2  *
3  * bitmap.h
4  *
5  * =============================================================================
6  *
7  * Copyright (C) Stanford University, 2006. All Rights Reserved.
8  * Author: Chi Cao Minh
9  *
10  * =============================================================================
11  *
12  * For the license of bayes/sort.h and bayes/sort.c, please see the header
13  * of the files.
14  *
15  * ------------------------------------------------------------------------
16  *
17  * For the license of kmeans, please see kmeans/LICENSE.kmeans
18  *
19  * ------------------------------------------------------------------------
20  *
21  * For the license of ssca2, please see ssca2/COPYRIGHT
22  *
23  * ------------------------------------------------------------------------
24  *
25  * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the
26  * header of the files.
27  *
28  * ------------------------------------------------------------------------
29  *
30  * For the license of lib/rbtree.h and lib/rbtree.c, please see
31  * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree
32  *
33  * ------------------------------------------------------------------------
34  *
35  * Unless otherwise noted, the following license applies to STAMP files:
36  *
37  * Copyright (c) 2007, Stanford University
38  * All rights reserved.
39  *
40  * Redistribution and use in source and binary forms, with or without
41  * modification, are permitted provided that the following conditions are
42  * met:
43  *
44  * * Redistributions of source code must retain the above copyright
45  * notice, this list of conditions and the following disclaimer.
46  *
47  * * Redistributions in binary form must reproduce the above copyright
48  * notice, this list of conditions and the following disclaimer in
49  * the documentation and/or other materials provided with the
50  * distribution.
51  *
52  * * Neither the name of Stanford University nor the names of its
53  * contributors may be used to endorse or promote products derived
54  * from this software without specific prior written permission.
55  *
56  * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY
57  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
59  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE
60  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
61  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
62  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
63  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
64  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
66  * THE POSSIBILITY OF SUCH DAMAGE.
67  *
68  * =============================================================================
69  */
70 
71 
72 #ifndef BITMAP_H
73 #define BITMAP_H 1
74 
75 
76 #include "types.h"
77 
78 
79 #ifdef __cplusplus
80 extern "C" {
81 #endif
82 
83 
84 typedef struct bitmap {
85  long numBit;
86  long numWord;
88 } bitmap_t;
89 
90 
91 /* =============================================================================
92  * bitmap_alloc
93  * -- Returns NULL on failure
94  * =============================================================================
95  */
96 bitmap_t*
97 bitmap_alloc (long numBit);
98 
99 
100 /* =============================================================================
101  * Pbitmap_alloc
102  * -- Returns NULL on failure
103  * =============================================================================
104  */
105 bitmap_t*
106 Pbitmap_alloc (long numBit);
107 
108 
109 /* =============================================================================
110  * bitmap_free
111  * =============================================================================
112  */
113 void
114 bitmap_free (bitmap_t* bitmapPtr);
115 
116 
117 /* =============================================================================
118  * Pbitmap_free
119  * =============================================================================
120  */
121 void
122 Pbitmap_free (bitmap_t* bitmapPtr);
123 
124 
125 /* =============================================================================
126  * bitmap_set
127  * -- Sets ith bit to 1
128  * -- Returns TRUE on success, else FALSE
129  * =============================================================================
130  */
131 bool_t
132 bitmap_set (bitmap_t* bitmapPtr, long i);
133 
134 
135 /* =============================================================================
136  * bitmap_clear
137  * -- Clears ith bit to 0
138  * -- Returns TRUE on success, else FALSE
139  * =============================================================================
140  */
141 bool_t
142 bitmap_clear (bitmap_t* bitmapPtr, long i);
143 
144 
145 /* =============================================================================
146  * bitmap_clearAll
147  * -- Clears all bit to 0
148  * =============================================================================
149  */
150 void
151 bitmap_clearAll (bitmap_t* bitmapPtr);
152 
153 
154 /* =============================================================================
155  * bitmap_isSet
156  * -- Returns TRUE if ith bit is set, else FALSE
157  * =============================================================================
158  */
159 bool_t
160 bitmap_isSet (bitmap_t* bitmapPtr, long i);
161 
162 
163 /* =============================================================================
164  * bitmap_findClear
165  * -- Returns index of first clear bit
166  * -- If start index is negative, will start from beginning
167  * -- If all bits are set, returns -1
168  * =============================================================================
169  */
170 long
171 bitmap_findClear (bitmap_t* bitmapPtr, long startIndex);
172 
173 
174 /* =============================================================================
175  * bitmap_findSet
176  * -- Returns index of first set bit
177  * -- If all bits are clear, returns -1
178  * =============================================================================
179  */
180 long
181 bitmap_findSet (bitmap_t* bitmapPtr, long startIndex);
182 
183 
184 /* =============================================================================
185  * bitmap_getNumClear
186  * =============================================================================
187  */
188 long
189 bitmap_getNumClear (bitmap_t* bitmapPtr);
190 
191 
192 /* =============================================================================
193  * bitmap_getNumSet
194  * =============================================================================
195  */
196 long
197 bitmap_getNumSet (bitmap_t* bitmapPtr);
198 
199 
200 /* =============================================================================
201  * bitmap_copy
202  * =============================================================================
203  */
204 void
205 bitmap_copy (bitmap_t* dstPtr, bitmap_t* srcPtr);
206 
207 
208 /* =============================================================================
209  * bitmap_toggleAll
210  * =============================================================================
211  */
212 void
213 bitmap_toggleAll (bitmap_t* bitmapPtr);
214 
215 
216 #define PBITMAP_ALLOC(n) Pbitmap_alloc(n)
217 #define PBITMAP_FREE(b) Pbitmap_free(b)
218 #define PBITMAP_SET(b, i) bitmap_set(b, i)
219 #define PBITMAP_CLEAR(b, i) bitmap_clear(b, i)
220 #define PBITMAP_CLEARALL(b) bitmap_clearAll(b)
221 #define PBITMAP_ISSET(b, i) bitmap_isSet(b, i)
222 #define PBITMAP_FINDCLEAR(b, i) bitmap_findClear(b, i)
223 #define PBITMAP_FINDSET(b, i) bitmap_findSet(b, i)
224 #define PBITMAP_GETNUMCLEAR(b) bitmap_getNumClear(b)
225 #define PBITMAP_GETNUMSET(b) bitmap_getNumSet(b)
226 #define PBITMAP_COPY(b) bitmap_copy(b)
227 #define PBITMAP_TOGGLEALL(b) bitmap_toggleAll(b)
228 
229 
230 #ifdef __cplusplus
231 }
232 #endif
233 
234 
235 #endif /* BITMAP_H */
236 
237 
238 /* =============================================================================
239  *
240  * End of bitmap.h
241  *
242  * =============================================================================
243  */
void bitmap_toggleAll(bitmap_t *bitmapPtr)
Definition: bitmap.c:353
void bitmap_clearAll(bitmap_t *bitmapPtr)
Definition: bitmap.c:213
bool_t bitmap_set(bitmap_t *bitmapPtr, long i)
Definition: bitmap.c:176
long numWord
Definition: bitmap.h:86
void bitmap_free(bitmap_t *bitmapPtr)
Definition: bitmap.c:149
long bitmap_getNumSet(bitmap_t *bitmapPtr)
Definition: bitmap.c:319
int bool_t
Definition: portable_defns.h:32
bitmap_t * bitmap_alloc(long numBit)
Definition: bitmap.c:91
Definition: bitmap.h:84
struct bitmap bitmap_t
bitmap_t * Pbitmap_alloc(long numBit)
Definition: bitmap.c:120
bool_t bitmap_clear(bitmap_t *bitmapPtr, long i)
Definition: bitmap.c:195
long bitmap_getNumClear(bitmap_t *bitmapPtr)
Definition: bitmap.c:306
void bitmap_copy(bitmap_t *dstPtr, bitmap_t *srcPtr)
Definition: bitmap.c:341
long bitmap_findSet(bitmap_t *bitmapPtr, long startIndex)
Definition: bitmap.c:285
void Pbitmap_free(bitmap_t *bitmapPtr)
Definition: bitmap.c:161
long numBit
Definition: bitmap.h:85
long bitmap_findClear(bitmap_t *bitmapPtr, long startIndex)
Definition: bitmap.c:261
bool_t bitmap_isSet(bitmap_t *bitmapPtr, long i)
Definition: bitmap.c:242
ulong_t * bits
Definition: bitmap.h:87