Exemplo n.º 1
0
uint32_t random_uint32(void)
{
    return xorshift32(&_state32);
}
Exemplo n.º 2
0
void test4 ( ) {
#define TXT_NUMBITS (128)
#define VAL_MINBYTES (PT_BITLEN_TO_BYTELEN(16))
#define VAL_MAXBYTES (PT_BITLEN_TO_BYTELEN(TXT_NUMBITS))
#define VAL_VARBYTES (VAL_MAXBYTES - VAL_MINBYTES)

	char* keysTxt = malloc ( PT_BITLEN_TO_BYTELEN(TXT_NUMBITS) * NUMELEMENTSTXT );
	uint64_t *valsTxt = malloc ( PT_BITLEN_TO_BYTELEN(64) * NUMELEMENTSTXT );

	t = clock ( );
	uint32_t lenBytes;
	char* pKey = keysTxt;
	for ( i = 0; i < NUMELEMENTSTXT ; ++i ) {
		// at least 16 bits, at most 128 bits of non-null bytes
		lenBytes = ( xorshift32 ( ) % ( VAL_VARBYTES + 1 ) ) + VAL_MINBYTES;
		for ( k = 0; k < lenBytes ; ++k ) {
			*pKey = (char) ( ( ( xorshift32 ( ) & ( TXT_NUMBITS - 1 ) ) + 32 ) & ( 0xFF ) );
			pKey++;
		}
		for ( ; k < PT_BITLEN_TO_BYTELEN( TXT_NUMBITS ) ; ++k ) {
			*pKey++ = 0;
		}
	}
	t = clock ( ) - t;
	printf ( "TreeTxt : Creating " TOSTR(NUMELEMENTSTXT)" random keys took %f seconds\n", (float) t / CLOCKS_PER_SEC );
	if ( pKey != ( keysTxt + PT_BITLEN_TO_BYTELEN(TXT_NUMBITS) * NUMELEMENTSTXT ) ) {
		printf ( "TreeTxt: Overwrote key array!" );
	}
	/*
	 char* ptKey2 = keysTxt;
	 for ( i = 0; i < 10 ; ++i ) {
	 printf ( "\t%u: %s\n", i, ptKey2 );
	 ptKey2 += PREFIX_TREE_BITLEN_TO_BYTELEN( 128 );
	 }
	 */

	pt_index treeTxt;
	pt_index_init ( &treeTxt, TXT_NUMBITS, 64 );

	t = clock ( );
	pKey = keysTxt;
	uint64_t *pValOrg = valsTxt;
	for ( i = 0; i < NUMELEMENTSTXT ; ++i ) {
		*pValOrg = xorshift64 ( );
		pt_add ( &treeTxt, pKey, pValOrg ); // I know that this will be stored inline

		pKey += PT_BITLEN_TO_BYTELEN( TXT_NUMBITS );
		++pValOrg;
	}
	t = clock ( ) - t;
	printf ( "TreeTxt : Inserting " TOSTR(NUMELEMENTSTXT)" keys took %f seconds\n", (float) t / CLOCKS_PER_SEC );

	t = clock ( );
	uint32_t numBadValues = 0;
	uint32_t numNullPointers = 0;
	pKey = keysTxt;
	pValOrg = valsTxt;
	for ( i = 0; i < NUMELEMENTSTXT ; ++i ) {
		pVal = pt_find ( &treeTxt, pKey );
		numNullPointers += ( pVal == NULL );
		numBadValues += ( pVal == NULL ) || ( memcmp ( pVal, pValOrg, PT_BITLEN_TO_BYTELEN( TXT_NUMBITS ) ) != 0 );

		pKey += PT_BITLEN_TO_BYTELEN( TXT_NUMBITS );
		++pValOrg;
	}
	numBadValues -= numNullPointers;
	t = clock ( ) - t;
	printf ( "TreeTxt : Verifying " TOSTR(NUMELEMENTS)" keys took %f seconds. %u bad values found. %u null pointers.\n", (float) t / CLOCKS_PER_SEC, numBadValues, numNullPointers );

	free ( keysTxt );
	free ( valsTxt );
	keysTxt = NULL;
	valsTxt = NULL;
}