Skip to content

Commit badb6ee

Browse files
committed
Improving and, andnot
1 parent 650dbea commit badb6ee

File tree

5 files changed

+37
-15
lines changed

5 files changed

+37
-15
lines changed

include/ewah/boolarray.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#include <vector>
1717

1818
#include "ewahutil.h"
19-
// uncomment this for debugging
20-
//#define EWAHASSERT
2119

2220
namespace ewah {
2321
/**

include/ewah/ewah-inl.h

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -330,15 +330,18 @@ template <class uword> size_t EWAHBoolArray<uword>::numberOfWords() const {
330330
}
331331

332332
template <class uword>
333-
void EWAHBoolArray<uword>::checkWordCount(std::string message) const {
333+
void EWAHBoolArray<uword>::assertWordCount(std::string message) const {
334334
#ifdef EWAHASSERT
335335
size_t tot = numberOfWords();
336336
size_t expected = (sizeinbits + wordinbits - 1) / wordinbits;
337337
if (expected != tot) {
338-
std::cerr << "[checkWordCount] " << message << std::endl;
339-
std::cerr << "[checkWordCount] number of words " << tot << std::endl;
340-
std::cerr << "[checkWordCount] expected number of words " << expected
338+
std::cerr << "[assertWordCount] wordinbits " << wordinbits << std::endl;
339+
std::cerr << "[assertWordCount] sizeinbits " << sizeinbits << std::endl;
340+
std::cerr << "[assertWordCount] " << message << std::endl;
341+
std::cerr << "[assertWordCount] number of words " << tot << std::endl;
342+
std::cerr << "[assertWordCount] expected number of words " << expected
341343
<< std::endl;
344+
debugprintout();
342345
throw std::runtime_error("bug");
343346
}
344347
#endif
@@ -1413,11 +1416,14 @@ void EWAHBoolArray<uword>::logicaland(const EWAHBoolArray &a,
14131416
rlwj.discardLiteralWordsWithReload(nbre_literal);
14141417
}
14151418
}
1416-
container.setSizeInBits(sizeInBits());
1419+
BufferedRunningLengthWord<uword> &remain = rlwj.size() > 0 ? rlwj : rlwi;
1420+
while(remain.size() > 0) {
1421+
container.addStreamOfEmptyWords(false, remain.size());
1422+
if (!remain.next()) { break; }
1423+
}
14171424
container.setSizeInBits(sizeInBits() > a.sizeInBits() ? sizeInBits()
14181425
: a.sizeInBits());
1419-
container.correctWordCount();
1420-
container.checkWordCount("logicaland");
1426+
container.assertWordCount("logicaland");
14211427
}
14221428

14231429
template <class uword>
@@ -1473,13 +1479,17 @@ void EWAHBoolArray<uword>::logicalandnot(const EWAHBoolArray &a,
14731479
rlwj.discardLiteralWordsWithReload(nbre_literal);
14741480
}
14751481
}
1476-
const bool i_remains = rlwi.size() > 0;
1477-
if (i_remains) {
1482+
if(rlwi.size() > 0) {
14781483
rlwi.discharge(container);
1484+
container.setSizeInBits(sizeInBits());
1485+
} else {
1486+
while(rlwj.size() > 0) {
1487+
container.addStreamOfEmptyWords(false, rlwj.size());
1488+
if (!rlwj.next()) { break; }
1489+
}
1490+
container.setSizeInBits(a.sizeInBits());
14791491
}
1480-
container.setSizeInBits(sizeInBits());
1481-
container.correctWordCount();
1482-
container.checkWordCount("logicalandnot");
1492+
container.assertWordCount("logicalandnot");
14831493
}
14841494

14851495
template <class uword>

include/ewah/ewah.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ template <class uword = uint32_t> class EWAHBoolArray {
687687
inline void fastaddStreamOfDirtyWords(const uword *v, const size_t number);
688688

689689
private:
690-
void checkWordCount(std::string message) const;
690+
void assertWordCount(std::string message) const;
691691
void correctWordCount();
692692
size_t numberOfWords() const;
693693
// private because does not increment the size in bits

tests/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,19 @@ function(add_cpp_test TEST_NAME)
88
target_include_directories(${TEST_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/cpp)
99
add_test(NAME ${TEST_NAME} COMMAND "${TEST_NAME}" "${CMAKE_CURRENT_BINARY_DIR}/data/" )
1010
target_link_libraries(${TEST_NAME} PUBLIC ewah)
11+
if(NOT MSVC)
12+
target_compile_options(
13+
${TEST_NAME} PUBLIC
14+
-Werror -Wall -Wextra -Weffc++ -Wsign-compare -Wshadow -Wwrite-strings
15+
-Wpointer-arith -Winit-self -Wconversion -Wno-sign-conversion
16+
)
17+
endif()
18+
1119
endfunction(add_cpp_test)
1220

1321
add_cpp_test(unit)
1422

23+
24+
25+
26+

tests/unit.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
* (c) Daniel Lemire, http://lemire.me/en/
66
*/
7+
#define EWAHASSERT
78
#include "ewah/boolarray.h"
89
#include "ewah/ewah.h"
910
#include <fstream>
@@ -290,6 +291,7 @@ template <class uword> bool testAndNotEWAHBoolArray() {
290291
cout << bout << endl;
291292
if (bout.numberOfOnes() != 1) {
292293
cout << "expected answer : 1 " << endl;
294+
cout << "got answer : " << bout.numberOfOnes() << endl;
293295
return false;
294296
}
295297
return true;

0 commit comments

Comments
 (0)