-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathozbcbitmap.h
175 lines (134 loc) · 3.7 KB
/
ozbcbitmap.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
This code is released under the
Gnu Lesser General Public Licensev3.0:
https://www.gnu.org/licenses/lgpl-3.0.en.html
(c) Lorenzo Vannucci
*/
#ifndef OZBCBITMAP
#define OZBCBITMAP
#include <inttypes.h>
#include <vector>
/*
OZBCBitmap is a compressed bitmap class.
The bitmap is rappresented from
a vector of 16bits words.
There are two type of words:
1): 1bit word_type=0 | 7bit bytes_zero | 8bit byte_word
2): 1bit word_type=1 | 15bit 128_bytes_zero
*/
class OZBCBitmap{
private:
std::vector<uint16_t> buffer;
uint32_t num_bytes;
OZBCBitmap logical_or_xor(OZBCBitmap &b, bool is_or);
public:
OZBCBitmap();
/**
* Set the ith bit to true (starting at zero).
* You must set the bitmap in increasing order:
* set(15), set(16), set(1000) is ok.
* set(0), set(100), set(50) is not ok.
* Once that bit ith is setted, you cannot change the value
* of bits 0 to ith.
*/
void set(uint32_t i);
/**
* Computes the logical and with another OZBCBitmap
* and return a new OZBCBitmap answer.
*/
OZBCBitmap logicaland(OZBCBitmap &b);
/**
* Computes the logical or with another OZBCBitmap
* and return a new OZBCBitmap answer.
*/
OZBCBitmap logicalor(OZBCBitmap &b);
/**
* Computes the logical xor with another OZBCBitmap
* and return a new OZBCBitmap answer.
*/
OZBCBitmap logicalxor(OZBCBitmap &b);
/**
* Return the size of bitmap in bytes
* + 4 bytes needed to serialize the bitmap.
* If portable=false return the size of bitmap in memory.
*/
uint32_t size(bool portable);
/**
* Write the bitmap on buffer 'b' of length 'len'
* ('len' must be >= then 'return value')
* and return the number of bytes written:
* if(write_header == 0)
* return sizeBitmapOnDisk(true).
*
* if(write_header != 0)
* return sizeBitmapOnDisk(false).
*
* If an error occured return 0.
*/
uint32_t writeToBuffer(char *b, uint32_t len, bool write_header);
/**
* Read a bitmap from a buffer 'b' with length 'len'
* saved with writeBitmapOnBuffer method
* and return the number of bytes readed.
* If you have stored the bitmap with write_header != 0,
* you need to set 'size'
* of the bitmap. Else if you have stored the bitmap
* with num_words==0 you don't need to know the bitmap size,
* in this case you must set 'size = 0'.
*
* If an error occured return 0.
*/
uint32_t readFromBuffer(char *b, uint32_t len, uint32_t size);
/**
* Write the bitmap on file 'f'
* and return the number of bytes written:
* if(write_header == 0)
* return sizeBitmapOnDisk(true).
*
* if(write_header != 0)
* return sizeBitmapOnDisk().
*
* If an error occured return 0.
*/
uint32_t writeToFile(FILE *f, bool write_header);
/**
* Read a bitmap from a file 'f'
* saved with writeBitmapOnFile method
* and return the number of bytes readed.
* If you have stored the bitmap with write_header != 0,
* you need to set 'size'
* of the bitmap. Else if you have stored the bitmap
* with write_header == 0 you don't need to know bitmap size,
* in this case you must set 'size = 0'.
*
* If an error occured return 0.
*/
uint32_t readFromFile(FILE *f, uint32_t size);
/**
* Print on file each word of buffer in this format:
* word_type|bytes_zero|dirty_byte
*
* word_type, bytes_zero and dirty_word are printed in binary.
* If word_type=1 there isn't dirty_byte.
*/
void print(FILE *f);
/**
* Swap the content of this bitmap with another bitmap.
*/
void swap(OZBCBitmap &b);
/**
* Return a copy of this bitmap.
*/
OZBCBitmap copy();
/**
* Reset this bitmap and free buffer memory.
*/
void reset();
/**
* Return a vector<uint32_t> contaning the position of the set
* bits in increasing order.
*/
std::vector<uint32_t> toVector();
~OZBCBitmap();
};
#endif