Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
//bitset1.set(1);
static JSVAL bs_set(JSARGS args) {
    HandleScope scope;
    EWAHBoolArray<LENGTH>* bs = (EWAHBoolArray<LENGTH>*) External::Unwrap(args[0]);
    if (!bs) {
        return v8::ThrowException(v8::String::New("In set bitset is Null"));
    }
    int v = args[1]->IntegerValue();
    
    bs->set(v);
    return scope.Close(Null());
}
Ejemplo n.º 3
0
bool testNot() {
    cout << "[testing Not]" << endl;
    bool isOk = true;
    EWAHBoolArray<uword> bitset;
    for (int i = 0; i <= 184; i++) {
        bitset.set(i);
    }
    if (bitset.numberOfOnes() != 185) {
        isOk = false;
    }

    bitset.inplace_logicalnot();
    if (bitset.numberOfOnes() != 0) {
        isOk = false;
    }
    return isOk;
}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
bool testNanJiang() {
    cout << "[testing NanJiang] sizeof(uword)=" << sizeof(uword) << endl;
    EWAHBoolArray<uword> b;
    b.set(5);
    if (b.numberOfOnes() != 1)
        return false;
    b.inplace_logicalnot();
    if (b.numberOfOnes() != 5)
        return false;
    BoolArray<uword> b2;
    b2.set(5);
    if (b2.numberOfOnes() != 1)
        return false;
    b2.inplace_logicalnot();
    if (b2.numberOfOnes() != 5)
        return false;
    return true;
}
Ejemplo n.º 6
0
    static EWAHBoolArray<uint64_t>* readOneBitmap(ifstream* inputStream) {
        EWAHBoolArray<uint64_t>* ewah = new EWAHBoolArray<uint64_t>;

        uint32_t sizeInBits = 0;
        inputStream->read((char *)&sizeInBits, 4);
        sizeInBits = swapBytesIfNecessary(sizeInBits);

        uint32_t numberOfOnes = 0;
        inputStream->read((char *)&numberOfOnes, 4);
        numberOfOnes = swapBytesIfNecessary(numberOfOnes);

        uint32_t tmp = 0;
        for (unsigned long i = 0; i<numberOfOnes; ++i) {
            inputStream->read((char *)&tmp, 4);
            tmp = swapBytesIfNecessary(tmp);
            ewah->set(tmp);
        }

        ewah->setSizeInBits(sizeInBits);
        return ewah;
    }
Ejemplo n.º 7
0
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;
}
Ejemplo n.º 8
0
bool testGet() {
    cout << "[testing Get] sizeof(uword)=" << sizeof(uword) << endl;
    bool isOk = true;

    for (size_t gap = 29; gap < 10000; gap *= 10) {
        EWAHBoolArray<uword> x;
        for (uint32_t k = 0; k < 100; ++k)
            x.set(k * gap);
        for (size_t k = 0; k < 100 * gap; ++k)
            if (x.get(k)) {
                if (k % gap != 0) {
                    cout << "spotted an extra set bit at " << k << " gap = "
                         << gap << endl;
                    return false;
                }
            } else if (k % gap == 0) {
                cout<<
                    "missed a set bit " << k
                    << " gap = " << gap<<endl;
                return false;
            }
    }
    return isOk;
}
Ejemplo n.º 9
0
void init( EWAHBoolArray<uword>& ba, size_t N, size_t x[] )
{
    for ( size_t ix= 0; ix < N; ++ix )
        ba.set( x[ix] );
}