bool testJoergBukowski() { cout << "[testing JoergBukowski]" << endl; bool isOk(true); vector<uint32_t> positions; positions.push_back(0); positions.push_back(36778); positions.push_back(51863); positions.push_back(134946); positions.push_back(137330); positions.push_back(147726); positions.push_back(147990); positions.push_back(151884); positions.push_back(156404); positions.push_back(158486); positions.push_back(159622); positions.push_back(163159); positions.push_back(164599); string indexfile("testingewahboolarray.bin"); ::remove(indexfile.c_str()); EWAHBoolArray<uword> myarray; for (vector<uint32_t>::const_iterator i = positions.begin(); i != positions.end(); ++i) { myarray.set(*i); ofstream out(indexfile.c_str(), ios::out | ios::binary); myarray.write(out); out.close(); EWAHBoolArray<uword> recovered; ifstream in(indexfile.c_str(), ios::binary); recovered.read(in); in.close(); vector < size_t > vals; recovered.appendSetBits(vals); if (vals.size() != static_cast<size_t> (i - positions.begin() + 1)) { cout << "failed to recover right number" << endl; isOk = false; } if (!equal(vals.begin(), vals.end(), positions.begin())) { cout << "failed to recover" << endl; isOk = false; } vals.clear(); for (typename EWAHBoolArray<uword>::const_iterator j = recovered.begin(); j != recovered.end(); ++j) vals.push_back(static_cast<uint32_t> (*j)); if (vals.size() != static_cast<size_t> (i - positions.begin() + 1)) { cout << "failed to recover right number -- iterator" << endl; isOk = false; } if (!equal(vals.begin(), vals.end(), positions.begin())) { cout << "failed to recover -- iterator" << endl; isOk = false; } } if (isOk) ::remove(indexfile.c_str()); if (!isOk) cout << testfailed << endl; return isOk; }
//EWAHBoolArray<LENGTH>::const_iterator i = bitset1.begin(); i!=bitset1.end(); ++i static JSVAL bs_it_isend(JSARGS args) { HandleScope scope; EWAHBoolArray<LENGTH>* bs = (EWAHBoolArray<LENGTH>*) External::Unwrap(args[0]); if (!bs) { return v8::ThrowException(v8::String::New("In it_isend bitset is Null")); } EWAHBoolArray<LENGTH>::const_iterator* it = (EWAHBoolArray<LENGTH>::const_iterator*) External::Unwrap(args[1]); if (!it) { return v8::ThrowException(v8::String::New("In it_isend it is Null")); } int ret = ( (*it)==(bs->end()) ); return scope.Close(Integer::New(ret)); }
static JSVAL bs_tostring(JSARGS args) { HandleScope scope; EWAHBoolArray<LENGTH>* bs = (EWAHBoolArray<LENGTH>*) External::Unwrap(args[0]); if (!bs) { return v8::ThrowException(v8::String::New("In tostring bitset is Null")); } std::stringstream ss; //cout<<"first bitset : "<<endl; for(EWAHBoolArray<LENGTH>::const_iterator i = bs->begin(); i!=bs->end(); ++i) ss<<*i<<","; Handle<String> res = String::New(ss.str().c_str()); return scope.Close(res); }
bool testSetGet() { cout << "[testing EWAH set/get] sizeof(uword)="<<sizeof(uword)<<endl; EWAHBoolArray<uword> ewcb; uint32_t val[] = { 5, 4400, 44600, 55400, 1000000 }; for (int k = 0; k < 5; ++k) { ewcb.set(val[k]); } size_t counter = 0; bool isOk = true; for (typename EWAHBoolArray<uword>::const_iterator i = ewcb.begin(); i != ewcb.end(); ++i) { if(val[counter++]!=*i) { cout<<"Failed test set/get"<<endl; isOk = false; } } return isOk; }
bool testSerialization() { cout << "[testing Serialization] word size = " << sizeof(uword)<< endl; EWAHBoolArray<uword> bitmap; for(int i = 0; i < 1<<31; i= 2*i +3) { bitmap.set(static_cast<size_t>(i)); } stringstream ss; EWAHBoolArray<uword> lmyarray; for (int k = 0; k < 10; ++k) { bitmap.write(ss); lmyarray.read(ss); if (lmyarray != bitmap) { return false; } typename EWAHBoolArray<uword>::const_iterator i = bitmap.begin(); typename EWAHBoolArray<uword>::const_iterator j = lmyarray.begin(); for (; i != bitmap.end(); ++i, ++j) { if (*i != *j) return false; } } return true; }
//EWAHBoolArray<LENGTH>::const_iterator i = bitset1.begin(); i!=bitset1.end(); ++i static JSVAL bs_it_end(JSARGS args) { HandleScope scope; EWAHBoolArray<LENGTH>* bs = (EWAHBoolArray<LENGTH>*) External::Unwrap(args[0]); if (!bs) { return v8::ThrowException(v8::String::New("In it_end bitset is Null")); } EWAHBoolArray<LENGTH>::const_iterator* it = new EWAHBoolArray<LENGTH>::const_iterator(bs->end()); //*it = bitset1.end(); //add iterator for auto del add_obj((void*)it, auto_del_bs_it); return scope.Close(External::Wrap(it)); }