示例#1
0
    i8 pwr = 0x400; // start with 1024
    int diff=2<<30;
    for(int i=0; i < 32; i++)
    {
        pwr<<=1;
        if(pwr > base) {
            break;
        } else {
            diff = base - pwr;
        }
    }
    if( (pwr - base) > diff) {
        // use previous pwr
        pwr >>=1;
    } 
    i8 p2 = w_findprime(pwr);

    if(debug) {
        cout 
        << "base  " << base 
        << " closest power of 2 " << pwr 
        << " findprime -> " << p2
        << endl;
    } 
    if(printpower) cout  << pwr << endl;
    if(printprime) cout  << p2 << endl;

    // i8 p1 = w_findprime(base);

    // Work backward from p1 to bpool size to request.
    i8 nbufpages = ((p2 * 9)-8)/16  ;
示例#2
0
void testit() {
    ::srand (4344); // for repeatability
    for (int i = 0; i < HASH_COUNT; ++i) {
        _hash_seeds[i] = ((uint32_t) ::rand() << 16) + ::rand();
    }



    cout << "tries=" << tries << endl;

    dump();

#define page_sz 8192ull

    int64_t nbufpages=(_size * 1024 - 1)/page_sz + 1; // sm.cpp passes to
            // bf_m constructor
    int64_t nbuckets=(16*nbufpages+8)/9; // bf_core_m constructor

    int64_t _prime = w_findprime(int64_t(nbuckets));
    if(!use_prime) { // override
        _prime = _prime_replacement;
    }

    cout << "For requested bp size "<< _size << ": "
    << endl
    << "\t nbufpages=" << nbufpages << " of page size " << page_sz << ","
    << endl
    << "\t nbuckets (from bf_core_m constructor)="  << nbuckets << ","
    << endl;
    if(use_prime) {
        cout << "\t use prime " ;
    }
    cout
        << " _size=" << _prime
    << endl;

    _size = _prime;

    int *buckets = new int[_size];
    for(int i=0; i < _size; i++)
    { buckets[i]=0; }

    for(int i=0; i < tries; i++)
    {
#define START 0
        int j= START + i;

        bfpid_t p(1,5,j);
        for (int k=0; k < hash_count; k++)
        {
            unsigned h=::hash(k,p);
            if(prnt) {
                cout << ::hex << "0x" << h  << ::dec
                <<  "  \t "  << p
                <<  " hash # " << k ;
                if(buckets[int(h)] > 0) cout << " XXXXXXXXXXXXXXXXXXXX ";
                cout << endl;
            }

            buckets[int(h)]++;
        }

    }

    int worst=0;
    int ttl=0;
    for(int i=0; i < _size; i++)
    {
        int collisions=buckets[i]-1;
        if(collisions > 0) {
            ttl += collisions;
            if(collisions > worst) worst=collisions;
        }
    }
    cout << "SUMMARY: buckets: " << _size
        << endl
        << " tries: " << tries << "(x " << hash_count
        << " hashes=" << tries*hash_count << ");  "
        << endl
        << " collisions: " << ttl
        << " ( " << 100*float(ttl)/float(tries*hash_count) << " %) "
        << endl
        << " worst case (max bkt len): " << worst
        << endl;

    delete[] buckets;

}