Ejemplo n.º 1
0
//bitset1.logicaland(bitset2,andbitset);
static JSVAL bs_logicaland(JSARGS args) {
    HandleScope scope;
    EWAHBoolArray<LENGTH>* bs = (EWAHBoolArray<LENGTH>*) External::Unwrap(args[0]);
    if (!bs) {
        return v8::ThrowException(v8::String::New("In logicaland bitset 1 is Null"));
    }
    EWAHBoolArray<LENGTH>* bs2 = (EWAHBoolArray<LENGTH>*) External::Unwrap(args[1]);
    if (!bs2) {
        return v8::ThrowException(v8::String::New("In logicaland bitset 2 is Null"));
    }
    EWAHBoolArray<LENGTH>* bs3 = (EWAHBoolArray<LENGTH>*) External::Unwrap(args[2]);
    if (!bs3) {
        return v8::ThrowException(v8::String::New("In logicaland bitset 2 is Null"));
    }
    
    bs->logicaland(*bs2, *bs3);
    
    return scope.Close(Null());
}
Ejemplo n.º 2
0
bool testEWAHBoolArrayLogical() {
    cout << "[testing EWAHBoolArrayLogical] word size = "<< sizeof(uword) << endl;
    bool isOk(true);
    EWAHBoolArray<uword> myarray1;
    EWAHBoolArray<uword> myarray2;

    uword allones =  static_cast<uword> (~0LL);
    const uint32_t N = 16;
    uword x1[N] = { 1, 0, 54, 24, 145, 0, 0, 0, allones,
                    allones,allones,
                    43, 0, 0, 0, 1
                  };
    uword x2[N] = { allones, 1, 0, 0, 0, 0, 0, 0, 0,
                    allones,
                    allones, allones, 0,4, 0, 0
                  };
    uword xand[N];
    uword xxor[N];
    size_t usedN = 10;
    if(sizeof(uword)>2) return true;

    for (uint32_t k = 0; k < usedN; ++k) {
        myarray1.addWord(x1[k]);
        myarray2.addWord(x2[k]);
        xand[k] = static_cast<uword>(x1[k] & x2[k]);
        xxor[k] = static_cast<uword>(x1[k] | x2[k]);
    }
    EWAHBoolArray<uword> myand;
    EWAHBoolArray<uword> myor;
    EWAHBoolArray<uword> myxor;
    EWAHBoolArray<uword> myxoralt;

    myarray1.logicaland(myarray2, myand);
    myarray1.logicalor(myarray2, myor);
    myarray1.logicalxor(myarray2, myxor);
    EWAHBoolArray<uword> tmp(myand);
    tmp.inplace_logicalnot();
    myor.logicaland(tmp, myxoralt);
    if(myxoralt != myxor) {
        isOk = false;
        if (!isOk)
            cout << testfailed << endl;
        return isOk;
    }

    EWAHBoolArrayIterator<uword> i = myand.uncompress();
    EWAHBoolArrayIterator<uword> j = myor.uncompress();
    EWAHBoolArrayIterator<uword> it1 = myarray1.uncompress();
    EWAHBoolArrayIterator<uword> it2 = myarray2.uncompress();
    for (uint32_t k = 0; k < usedN; ++k) {
        const uword m1 = it1.next();
        const uword m2 = it2.next();
        if (!i.hasNext()) {
            if((m1 & m2) != 0) {
                cout << "type 1 error" << endl;
                isOk = false;
                break;
            }
        } else {
            const uword inter = i.next();
            if (inter != xand[k]) {
                cout << "type 4 error" << endl;
                isOk = false;
                break;
            }
        }
        if (!j.hasNext()) {
            if((m1 | m2) != 0) {
                cout << "type 3 error" << endl;
                isOk = false;
                break;
            }
        } else {
            const uword jor = j.next();
            if (jor != xxor[k]) {
                cout << "type 6 error OR" << endl;
                isOk = false;
                break;
            }
        }

    }
    if (!isOk)
        cout << testfailed << endl;
    return isOk;
}