Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
hasher.c
Go to the documentation of this file.00001 #undef UINT
00002 #define UINT unsigned int
00003
00004 #if 1
00005 # define SLOTS 8191
00006 #else
00007 # define SLOTS 27449
00008 #endif
00009
00010 #include <stdio.h>
00011
00012 static UINT hasher( char *str )
00013 {
00014 UINT hh , jj,kk ; char *cpt ;
00015
00016 if( str == NULL ) return 0 ;
00017 if( str[0] == '\0' ) return 1 ;
00018
00019 hh = 0 ;
00020 for( cpt=str ; *cpt != '\0' ; cpt++ ){
00021 jj = (65537*(UINT)(*cpt)) ; cpt++ ;
00022 kk = 17389*(UINT)(*cpt) ;
00023 hh = 13*hh + (jj << 8) + kk ;
00024 if( *cpt == '\0' ) break ;
00025 }
00026
00027 hh = ((hh & 0xaaaaaaaa) >> 1)
00028 | ((hh & 0x55555555) << 1) ;
00029
00030 return (hh % SLOTS) ;
00031 }
00032
00033 int main( int argc , char *argv[] )
00034 {
00035 int ii ; UINT hh ;
00036 for( ii=1 ; ii < argc ; ii++ )
00037 printf("%s -> %u\n",argv[ii],hasher(argv[ii])) ;
00038 exit(0);
00039 }