示例#1
0
void 
CIdDeMux<TBV, TBVFact>::SetCoordinatesFast(unsigned        id, 
                                           const unsigned* coord,
                                           bool            set_flag)
{
    size_t N = GetN();
    for (size_t i = 0; i < N; ++i) {
        TDimVector& dv = PutDimVector(i);
        unsigned c = coord[i];
        if (dv.size() <= c) {
            dv.resize(c+1);
        }
        TBitVector* bv = dv[c].get();
        if (set_flag == false && bv == 0) {
            continue; // nothing to do
        }
        if (!bv) {
            dv[c] = bv = TBVFactory::Create();
        }
        bv->set(id, set_flag);
    } // for i
}
示例#2
0
static
void s_TEST_SetBit()
{
    TBitVector   bv;    // Bitvector variable declaration.

    unsigned cnt = bv.count();
    assert(cnt == 0);

    // Set some bits.

    bv.set(10);
    bv.set(100);
    bv.set(1000000);

    // New bitvector's count.
    cnt = bv.count();
    assert(cnt == 3);

    // Print the bitvector.

    unsigned value = bv.get_first();
    do
    {
        value = bv.get_next(value);
        if (value)
        {
            assert(value == 10 || value == 100 || value == 1000000);
        }
        else
        {
            break;
        }
    } while(1);

    cout << endl;

    bv.clear();   // Clean up.
    
    cnt = bv.count();
    assert(cnt == 0);

    // We also can use operators to set-clear bits;

    bv[10] = true;
    bv[100] = true;
    bv[10000] = true;

    cnt = bv.count();
    assert(cnt == 3);

    if (bv[10])
    {
        bv[10] = false;
    }
    
    cnt = bv.count();
    assert(cnt == 2);
}