Coda Distributed File System
bitmap.h
Go to the documentation of this file.
1/* BLURB gpl
2
3 Coda File System
4 Release 8
5
6 Copyright (c) 1987-2025 Carnegie Mellon University
7 Additional copyrights listed below
8
9This code is distributed "AS IS" without warranty of any kind under
10the terms of the GNU General Public Licence Version 2, as shown in the
11file LICENSE. The technical and financial contributors to Coda are
12listed in the file CREDITS.
13
14 Additional copyrights
15 none currently
16
17#*/
18
19#ifndef _BITMAP_H_
20#define _BITMAP_H_ 1
21/*
22 * bitmap.h
23 * Created Feb 13, 1992 -- Puneet Kumar
24 * Declaration of a bitmap class
25 */
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#include <stdint.h>
32
33#ifdef __cplusplus
34}
35#endif
36
37#include <coda_tsa.h>
38
39#define ALLOCMASK 255
40#define HIGHBIT 128
41/* Bitmap for keeping status of N elements of an array.
42 * The class keeps an array of size = 1/8th N
43 * Each elements status is stored in a bit
44 * 1 --> that element is not free
45 * 0 --> that element is free
46 */
47
48/* Values of bitmap::malloced; must be 8 bits so can't use enums */
49#define BITMAP_NOTVIANEW 193 /* must be on stack */
50#define BITMAP_VIANEW 221 /* on heap, via operator new */
51
52class bitmap {
53 // friend ostream& operator<<(ostream& s, bitmap *b);
54 uint8_t recoverable; /* is this bitmap recoverable */
55 uint8_t malloced; /* was bitmap allocated via new? */
56 int mapsize; /* 1/8 size of array of elements */
57 char *map; /* bitmap showing status of the elements */
58
65 void SetValue(int index, int value) TRANSACTION_OPTIONAL;
66
74 void SetRangeValue(int start, int len, int value);
75
76public:
85 void *operator new(size_t size, int recable = 0) TRANSACTION_OPTIONAL;
86
93 void operator delete(void *ptr) TRANSACTION_OPTIONAL;
94
101 bitmap(int inputmapsize = 0, int recable = 0);
102
106 ~bitmap();
107
113 void Resize(int newsize) TRANSACTION_OPTIONAL;
114
120 void Grow(int newsize);
121
128
134 void FreeIndex(int index);
135
142 void FreeRange(int start, int len);
143
149 void SetIndex(int index) TRANSACTION_OPTIONAL;
150
157 void SetRange(int start, int len);
158
166 void CopyRange(int start, int len, bitmap &b);
167
174 int Value(int index);
175
181 int Count();
182
188 int Size();
189
194
201
208 int operator!=(bitmap &b); // test for inequality
209
213 void print();
214
220 void print(FILE *fp);
221
227 void print(int fd);
228};
229
230#endif /* _BITMAP_H_ */
Definition: bitmap.h:52
int Value(int index)
Definition: bitmap.cc:321
void FreeIndex(int index)
Definition: bitmap.cc:311
int GetFreeIndex() TRANSACTION_OPTIONAL
Definition: bitmap.cc:188
int operator!=(bitmap &b)
Definition: bitmap.cc:400
void Grow(int newsize)
Definition: bitmap.cc:181
void CopyRange(int start, int len, bitmap &b)
Definition: bitmap.cc:235
bitmap(int inputmapsize=0, int recable=0)
Definition: bitmap.cc:87
void operator=(bitmap &b) TRANSACTION_OPTIONAL
Definition: bitmap.cc:367
void SetRange(int start, int len)
Definition: bitmap.cc:306
void print()
Definition: bitmap.cc:417
void Resize(int newsize) TRANSACTION_OPTIONAL
Definition: bitmap.cc:135
void SetIndex(int index) TRANSACTION_OPTIONAL
Definition: bitmap.cc:301
int Size()
Definition: bitmap.cc:347
void purge() TRANSACTION_OPTIONAL
Definition: bitmap.cc:354
void FreeRange(int start, int len)
Definition: bitmap.cc:316
int Count()
Definition: bitmap.cc:335
~bitmap()
Definition: bitmap.cc:117
unsigned char uint8_t
Definition: coda.h:101
#define TRANSACTION_OPTIONAL
Definition: coda_tsa.h:109