コード例 #1
0
ファイル: singh.cpp プロジェクト: etep/hash-stats
int main( int argc, char ** argv ) {
    
    double a = 0.8;
    
    const bool runInserts = true;
    bool runDeletes = true;
    
    const uint64_t ngen = 2;
    const uint64_t ninserts = uint64_t( a * double( m*n ) );
    
    table = new bool[ m*n ];
    indices = new uint64_t[ ninserts ];

    memset(   table, 0, m*n*sizeof( bool ) );
    memset( indices, 0, ninserts*sizeof( uint64_t ) );
    
    load = 0ULL;
    uint64_t u = 0ULL;

    if( runInserts ) {
        for( uint64_t i = 0ULL; i < ninserts; i++ ) {

            indices[ i ] = Insert();
        
            if( i % (ninserts/10) == 0ULL ) {
                cout << "i = " << SETDEC( 10 ) << i << ", load = " << load << endl;
            }
            u++;
        }
    }
    
    if( runDeletes ) {
        for( uint64_t i = 0ULL; i < (m*n*ngen); i++ ) {
            
            // delete:
            const uint64_t delIdx = rng.RandU64() % u;
            Delete( indices[ delIdx ] );
        
            indices[ delIdx ] = Insert();

            if( i % (m*n/10) == 0ULL ) {
                cout << "i = " << SETDEC( 10 ) << i << ", load = " << load << endl;
            }
        }
    }
    
    const uint64_t keys_over = u - load;
    const double o = double( keys_over ) / (m*n);
    
    cout << "keys inserted: " << u << endl;
    cout << "keys in table: " << load << endl;
    cout << "keys overflow: " << keys_over << endl;
    cout << "overflow pcnt: " << (100*o) << endl;
}
コード例 #2
0
ファイル: singh.cpp プロジェクト: etep/hash-stats
uint64_t Insert( void ) {
    
    const uint64_t key = rng.RandU64();
    
    const uint32_t bucket = key % m;
    
    const uint32_t begIdx = 0 + bucket*n;
    const uint32_t endIdx = n + bucket*n;
    
    uint32_t occ = 0;
    uint32_t tidx = 0xFFFFFFFF;

    for( uint32_t idx = begIdx; idx < endIdx; idx++ ) {

        const bool val = table[ idx ];
        bool found = false;

        if( val ) {
            occ++;
        }
        else if( !found ) {
            tidx = idx;
            found = true;
        }
    }
    
    if( occ == n ) {
        // overflow
        assert( tidx == 0xFFFFFFFF );
        return m*n;
    }

    assert( tidx != 0xFFFFFFFF );
    assert( table[ tidx ] == false );
    table[ tidx ] = true;
    load++;
    return tidx;    
}