Quote:Original post by hplus0603
To get the hash of some block of data:unsigned int hash( unsigned char const * base, size_t size ) { return crc32( base, size );}
To get the table index, given the hash:unsigned int table_index( unsigned int h ) { assert( !(table_size&(table_size-1)) ); return h & (table_size-1);}
This works for all non-0 powers of 2 for table_size. It also works for most kinds of data that you want to hash. If you don't have a crc32 function laying around (you'll find it in zip, zlib, etc), then you can use a linear congruential rng instead:// note: I haven't tuned the specific constants used, they are // just examples. You probably want to tweak them so you get a // good spread in the lower bits given similar inputs.unsigned int hash( unsigned char const * base, size_t size ) { unsigned int v = 0x54321; while( size > 0 ) { v = v*0xffeeddcb + *base + 0x938265; ++base; --size; } return v;}
Ohhhhkkkayayyy.....You lost me :P hahaha. Could you explain that a little more indepth, such as what to do with collison in thos cases, as well as what exactly each function does, and kinda step by step as to how I would impliment this? I raided my uni's library, and got "Itroduction to data structures and algorithms with C++ by Glenn W. Rowe (c) 1997 So i'll read that so I atleast know some of the terms :P Has anyone else read this book? Is it good or?
Cheers! =)