#include #include #include #include "..\mytypes.h" #include "Judy.h" #define TAG printf( "%s:%u\n", __FILE__, __LINE__ ) char *odo( char *odo ) { I32 wheel = (I32)strlen( odo )-1; while( odo[ wheel ] == 'z' && wheel >= 0 ) odo[ wheel-- ] = 'a'; return wheel < 0 ? NULL : ( ++odo[ wheel ], odo ); } int main( int argc, char **argv ) { char *name = argc > 1 ? argv[ 1 ] : "aaaa"; U32 size = (U32)strlen( name ); U64 addr = 1ull; void *addrByName = judy_open( size, 0 ); // size of keys (+1 for nulls added internally) void *nameByAddr = judy_open( 0, 1 ); // size calculated internally as depth * 8 (or 4 for 32-bit) ULONG64 start, end, hz = 2394046161; int cpuInfo[4]; do { JudySlot *addrSlot = judy_cell( addrByName, name, size ); JudySlot *nameSlot = judy_cell( nameByAddr, (void*)&addr, 1 ); *addrSlot = addr; *nameSlot = (U64)_strdup( name ); ++addr; } while( odo( name ) ); printf( "Check memory: " ); getc( stdin ); __cpuid( cpuInfo, 0 ); start = __rdtsc(); do { JudySlot *addrSlot = judy_slot( addrByName, name, size ); U64 gotAddr = *addrSlot; JudySlot *nameSlot = judy_slot( nameByAddr, (void*)&gotAddr, 1 ); char *gotName = (char*)*nameSlot; if( strcmp( name, gotName ) ) fprintf( stderr, "name:'%s' != gotName:'%s'\n", name, gotName ), exit( -__LINE__ ); } while( odo( name ) ); __cpuid( cpuInfo, 0 ); end = __rdtsc(); printf( "Bidi lookup of %u pairs took: %.3f seconds\n", (int)pow( (double)26, (double)size ), (double)( end - start) / (double)hz ) ; printf( "Check memory: " ); getc( stdin ); return 1; }