Skip to content

Commit e4cff7a

Browse files
committed
Better docs
1 parent bc9059f commit e4cff7a

File tree

3 files changed

+68
-11
lines changed

3 files changed

+68
-11
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,27 @@ Versions 0.5 and above assume that the compiler supports the C++11 standard.
122122
make example
123123
./example
124124

125+
# Quick code sample
126+
127+
```C++
128+
#include "ewah.h"
129+
130+
typedef EWAHBoolArray<uint32_t> bitmap;
131+
132+
bitmap bitset1 =
133+
bitmap::bitmapOf(9, 1, 2, 1000, 1001, 1002, 1003, 1007, 1009, 100000);
134+
std::cout << "first bitset : " << bitset1 << std::endl;
135+
bitmap bitset2 = bitmap::bitmapOf(5, 1, 3, 1000, 1007, 100000);
136+
std::cout << "second bitset : " << bitset2 << std::endl;
137+
bitmap bitset3 = bitmap::bitmapOf(3, 10, 11, 12);
138+
std::cout << "third bitset : " << bitset3 << std::endl;
139+
bitmap orbitset = bitset1 | bitset2;
140+
bitmap andbitset = bitset1 & bitset2;
141+
bitmap xorbitset = bitset1 ^ bitset2;
142+
bitmap andnotbitset = bitset1 - bitset2;
143+
```
144+
145+
125146
# Example
126147
127148
Please see example.cpp.

example.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,40 @@
77
#include <stdlib.h>
88
#include "ewah.h"
99

10+
void easydemo() {
11+
typedef EWAHBoolArray<uint32_t> bitmap;
12+
bitmap bitset1 =
13+
bitmap::bitmapOf(9, 1, 2, 1000, 1001, 1002, 1003, 1007, 1009, 100000);
14+
std::cout << "first bitset : " << bitset1 << std::endl;
15+
bitmap bitset2 = bitmap::bitmapOf(5, 1, 3, 1000, 1007, 100000);
16+
std::cout << "second bitset : " << bitset2 << std::endl;
17+
bitmap bitset3 = bitmap::bitmapOf(3, 10, 11, 12);
18+
std::cout << "third bitset : " << bitset3 << std::endl;
19+
bitmap orbitset = bitset1 | bitset2;
20+
bitmap andbitset = bitset1 & bitset2;
21+
bitmap xorbitset = bitset1 ^ bitset2;
22+
bitmap andnotbitset = bitset1 - bitset2;
23+
24+
std::cout << "logical and: " << andbitset << std::endl;
25+
std::cout << "memory usage of compressed bitset = " << andbitset.sizeInBytes()
26+
<< " bytes" << std::endl;
27+
// we will display the and
28+
std::cout << "logical or: " << orbitset << std::endl;
29+
std::cout << "memory usage of compressed bitset = " << orbitset.sizeInBytes()
30+
<< " bytes" << std::endl;
31+
// we will display the xor
32+
std::cout << "logical xor: " << xorbitset << std::endl;
33+
std::cout << "memory usage of compressed bitset = " << xorbitset.sizeInBytes()
34+
<< " bytes" << std::endl;
35+
std::cout << "union of all three bitsets = " << (orbitset | bitset3)
36+
<< std::endl;
37+
const bitmap *mybitmaps[] = {&bitset1, &bitset2, &bitset3};
38+
std::cout << "fast union of all three bitsets = "
39+
<< fast_logicalor(3, mybitmaps) << std::endl;
40+
41+
std::cout << std::endl;
42+
}
43+
1044
template <class bitmap> void demo() {
1145
bitmap bitset1 =
1246
bitmap::bitmapOf(9, 1, 2, 1000, 1001, 1002, 1003, 1007, 1009, 100000);
@@ -109,6 +143,8 @@ int main(void) {
109143
std::cout << std::endl;
110144
std::cout << "====compressed example====" << std::endl;
111145
std::cout << std::endl;
146+
easydemo();
147+
112148
demo<EWAHBoolArray<uint32_t>>();
113149
demoSerialization<EWAHBoolArray<uint32_t>>();
114150
std::cout << "==== benchmark intersecs === " << std::endl;

src/unit.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ template <class uword> bool testCardinalityEWAHBoolArray() {
186186
template <class uword> bool testLargeDirty() {
187187
cout << "[testing LargeDirty] sizeof(uword)=" << sizeof(uword)
188188
<< endl;
189-
size_t N = 8000000;
189+
size_t N = 200000000;
190190
vector<uint32_t> bigarray1(N);
191191
vector<uint32_t> bigarray2(N);
192192
for(size_t k = 0; k < N; k++) {
@@ -195,36 +195,36 @@ template <class uword> bool testLargeDirty() {
195195
}
196196
EWAHBoolArray<uword> b1 = EWAHBoolArray<uword>();
197197
EWAHBoolArray<uword> b2 = EWAHBoolArray<uword>();
198-
for(size_t k = 0; k < N; k++) {
198+
for(size_t k = 0; (8*k) < N; k++) {
199199
b1.set(8 * k);
200-
b2.set(64 * k);
200+
}
201+
for(size_t k = 0; (64*k) < N; k++) {
202+
b1.set(64 * k);
201203
}
202204

203-
EWAHBoolArray<uword> b3 = EWAHBoolArray<uword>::bitmapOf(3,1,10,1000);
204-
EWAHBoolArray<uword> b4 = EWAHBoolArray<uword>::bitmapOf(3,1,10,1000);
205+
EWAHBoolArray<uword> b3 = EWAHBoolArray<uword>::bitmapOf(3,1,10,1001);
206+
EWAHBoolArray<uword> b4 = EWAHBoolArray<uword>::bitmapOf(3,1,10,1001);
205207

206-
if (b1.numberOfOnes() != N) {
207-
return false;
208-
}
209-
if (b2.numberOfOnes() != N) {
210-
return false;
211-
}
212208
if (b3.numberOfOnes() != 3) {
209+
std::cout<< "bad b3 count" << b4.numberOfOnes()<<std::endl;
213210
return false;
214211
}
215212
b3 = b3 | b1;
216213
b4 = b4 | b2;
217214
b3 = b3 | b2;
218215
b4 = b4 | b1;
219216
if( b3 != b4 ) {
217+
std::cout<< "b3 != b4"<<std::endl;
220218
return false;
221219
}
222220
b4 = b4 - b1;
223221
if (b4.numberOfOnes() != 3) {
222+
std::cout<< "bad b4 count" << b4.numberOfOnes()<<std::endl;
224223
return false;
225224
}
226225
b3 = b3 ^ b4;
227226
if( b3 != b1 ) {
227+
std::cout<< "b3 != b1"<<std::endl;
228228
return false;
229229
}
230230

0 commit comments

Comments
 (0)