コード例 #1
0
ファイル: pbltest.c プロジェクト: peterGraf/pbl
int main( int argc, char * argv[ ] )
{
    void * ht;
    int    rc;

    char * data;

    ht = pblHtCreate();

    rc = pblHtInsert( ht, "123", 4, "123" );
    rc = pblHtInsert( ht, "124", 4, "124" );
    rc = pblHtInsert( ht, "125", 4, "125" );
    rc = pblHtInsert( ht, "123", 4, "123" );
    rc = pblHtInsert( ht, "123", 3, "123" );

    data = pblHtLookup( ht, "123", 4 );
    data = pblHtLookup( ht, "123", 3 );
    data = pblHtLookup( ht, "124", 4 );
    data = pblHtLookup( ht, "125", 4 );
    data = pblHtLookup( ht, "126", 4 );

    for( data = pblHtFirst( ht ); data; data = pblHtNext( ht ))
    {
        data = pblHtCurrent( ht );
    }

    rc = pblHtRemove( ht, "125", 4 );

    data = pblHtFirst( ht );

    rc = pblHtDelete( ht );

    while( !pblHtRemove( ht, 0, 0 ));

    rc = pblHtInsert( ht, "123", 4, "123" );
    rc = pblHtInsert( ht, "124", 4, "124" );
    rc = pblHtInsert( ht, "125", 4, "125" );
    rc = pblHtInsert( ht, "123", 4, "123" );
    rc = pblHtInsert( ht, "123", 3, "123" );

    for( data = pblHtFirst( ht ); data; data = pblHtNext( ht ))
    {
        pblHtRemove( ht, 0, 0 );
    }

    rc = pblHtDelete( ht );

    return rc;
}
コード例 #2
0
ファイル: check_iterator.c プロジェクト: baskard/stasis
/** Take two iterators, and make sure they represent the same set. */
static void iterator_test(int xid,
			 lladdIterator_t * reference_impl,
			 lladdIterator_t * tested_impl) {

  pblHashTable_t * hash = pblHtCreate();

  int numEntries = 0;

  while(Titerator_next(xid, reference_impl)) {
    int    keySize,  valSize;
    byte  *key,     *val,    *valScratch;

    keySize = Titerator_key(xid, reference_impl,   &key);
    valSize = Titerator_value(xid, reference_impl, &valScratch);
    val = stasis_malloc(valSize, byte);
    memcpy(val, valScratch, valSize);  // pblHtInsert stores values a pointers to application managed memory.

    pblHtInsert(hash, key, keySize, val);
    numEntries ++;
  }

  while(Titerator_next(xid, tested_impl)) {
    numEntries --;

    int    keySize,  valSize;
    byte  *key,     *val,    *valScratch;

    keySize = Titerator_key(xid, tested_impl,   &key);
    valSize = Titerator_value(xid, tested_impl, &valScratch);

    val = pblHtLookup(hash, key, keySize);

    assert(val);

    assert(!memcmp(val, valScratch, valSize));

    free(val);

    pblHtRemove(hash, key, keySize);

  }

  assert(!numEntries);

}
コード例 #3
0
ファイル: pblhttst.c プロジェクト: pangkunpeng1987/pbl
/*
 * test frame for the hash table library
 *
 * this test frame calls the hash table library,
 * it does not have any parameters, it is meant for
 * debugging the hash table library
 */
int pblHASHTABLE_TestFrame( int argc, char * argv[ ] )
{
    pblHashTable_t * ht;
    int    rc;
    size_t size;

    char * data;

    ht = pblHtCreate();
    fprintf( stdout, "pblHtCreate() ht = %p\n", ht );

    rc = pblHtInsert( ht, "123", 4, "123" );
    fprintf( stdout, "pblHtInsert( ht, 123, 4, 123 ) rc = %d\n", rc );

    rc = pblHtInsert( ht, "124", 4, "124" );
    fprintf( stdout, "pblHtInsert( ht, 124, 4, 124 ) rc = %d\n", rc );

    rc = pblHtInsert( ht, "125", 4, "125" );
    fprintf( stdout, "pblHtInsert( ht, 125, 4, 125 ) rc = %d\n", rc );

    rc = pblHtInsert( ht, "123", 4, "123" );
    fprintf( stdout, "pblHtInsert( ht, 123, 4, 123 ) rc = %d\n", rc );

    rc = pblHtInsert( ht, "123", 3, "123" );
    fprintf( stdout, "pblHtInsert( ht, 123, 3, 123 ) rc = %d\n", rc );

    data = pblHtLookup( ht, "123", 4 );
    fprintf( stdout, "pblHtLookup( ht, 123, 4 ) data = %s\n",
             data ? data : "NULL" );

    data = pblHtLookup( ht, "123", 3 );
    fprintf( stdout, "pblHtLookup( ht, 123, 3 ) data = %s\n",
             data ? data : "NULL" );

    data = pblHtLookup( ht, "124", 4 );
    fprintf( stdout, "pblHtLookup( ht, 124, 4 ) data = %s\n",
             data ? data : "NULL" );

    data = pblHtLookup( ht, "125", 4 );
    fprintf( stdout, "pblHtLookup( ht, 125, 4 ) data = %s\n",
             data ? data : "NULL" );

    data = pblHtLookup( ht, "126", 4 );
    fprintf( stdout, "pblHtLookup( ht, 126, 4 ) data = %s\n",
             data ? data : "NULL" );


    for( data = pblHtFirst( ht ); data; data = pblHtNext( ht ))
    {
        data = pblHtCurrent( ht );
        fprintf( stdout, "pblHtCurrent( ht ) data = %s\n",
                 data ? data : "NULL" );
        size = 0;
        data = pblHtCurrentKey( ht, &size );
        fprintf( stdout, "pblHtCurrentKey( ht, &size ) data = %s, size %ld\n",
                 data ? data : "NULL", (long int)size );

    }

    rc = pblHtRemove( ht, "125", 4 );
    fprintf( stdout, "pblHtRemove( ht, 125, 4 ) rc = %d\n", rc );

    data = pblHtFirst( ht );
    fprintf( stdout, "pblHtFirst( ht ) data = %s\n", data ? data : "NULL" );

    rc = pblHtDelete( ht );
    fprintf( stdout, "pblHtDelete( ht, 125, 4 ) rc = %d\n", rc );

    while( !pblHtRemove( ht, 0, 0 ));

    rc = pblHtInsert( ht, "123", 4, "123" );
    fprintf( stdout, "pblHtInsert( ht, 123, 4, 123 ) rc = %d\n", rc );

    rc = pblHtInsert( ht, "124", 4, "124" );
    fprintf( stdout, "pblHtInsert( ht, 124, 4, 124 ) rc = %d\n", rc );

    rc = pblHtInsert( ht, "125", 4, "125" );
    fprintf( stdout, "pblHtInsert( ht, 125, 4, 125 ) rc = %d\n", rc );

    rc = pblHtInsert( ht, "123", 4, "123" );
    fprintf( stdout, "pblHtInsert( ht, 123, 4, 123 ) rc = %d\n", rc );

    rc = pblHtInsert( ht, "123", 3, "123" );
    fprintf( stdout, "pblHtInsert( ht, 123, 3, 123 ) rc = %d\n", rc );


    for( data = pblHtFirst( ht ); data; data = pblHtNext( ht ))
    {
        pblHtRemove( ht, 0, 0 );
    }

    rc = pblHtDelete( ht );
    fprintf( stdout, "pblHtDelete( ht ) rc = %d\n", rc );

    return( rc );
}
コード例 #4
0
ファイル: lockManagerImpl.c プロジェクト: Zhoutall/stasis
static void * pblHtLookup_r(pblHashTable_t * h, void * key, size_t keylen) {
  pthread_mutex_lock(&stasis_lock_manager_ht_mut);
  void * ret = pblHtLookup(h, key, keylen);
  pthread_mutex_unlock(&stasis_lock_manager_ht_mut);
  return ret;
}