I finally managed to build a 64-bit version of Judy.
I started with this one-file/1250 line version and hacked out all the -DSTANDALONE and -DASKITIS stuff along with all the BIG_ENDIAN stuff; extracted a Judy.h; and got the filesize down to 965 lines and built it into a dll:
C:\test\Judy>cl /W3 /Ot /favor:INTEL64 /MT /LD Judy.c
Microsoft (R) C/C++ Optimizing Compiler Version 15.00.21022.08 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
Judy.c
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation. All rights reserved.
/out:Judy.dll
/dll
/implib:Judy.lib
Judy.obj
Creating library Judy.lib and object Judy.exp
I then wrote a C program to us it to create two Judy arrays and stored my test data 'aaaaa'..'zzzzz' paired with a 64-bit integer: #include <windows.h>
#include <stdio.h>
#include <math.h>
#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 n
+ulls added internally)
void *nameByAddr = judy_open( 0, 1 ); // size calculated intern
+ally 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' != g
+otName:'%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;
}
built it against the dll: C:\test\Judy>cl /W3 /Ot JudyTest.c Judy.lib
Microsoft (R) C/C++ Optimizing Compiler Version 15.00.21022.08 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
JudyTest.c
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation. All rights reserved.
/out:JudyTest.exe
JudyTest.obj
Judy.lib
A run: C:\test\Judy>JudyTest.exe aaaaa
Check memory:
Bidi lookup of 11881376 pairs took: 6.325 seconds
Check memory: 524,332k
Then I built it as an Inline::C module, adding method wrappers for the important functions:
Unfortunately, in this form, the runtime increase -- mostly I think due to the perl->C->perl transitions -- from 6.5 seconds to over 25s: C:\test\Judy>perl Judy.pm -ODO=aaaaa
Memory before building Judy: 10,760 K
Memory after building Judy: 347,660 K
Bidi lookups of 11881376 pairs took:25.197204113 seconds
Memory after lookups: 347,680 K
So, whilst it does use somewhat less memory than my BiMap version; is also somewhat slower.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
|