Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

hashing

Name: Anonymous 2011-12-04 12:34

tell me a good and fast hashing algorithm /prog/. I will be using it to compare relatively big data with each other.

Name: Anonymous 2011-12-04 12:37

unsigned long hash(unsigned long data, unsigned long hash_table_size)
{
  return data % hash_table_size;
}

Name: Anonymous 2011-12-04 12:42

>>2
by relatively big I mean a few kb. And it is not for a hash table, I will use the hashed value to quickly compare two data with each other.

Name: Anonymous 2011-12-04 13:07


long long hash(char *b)
{
  long long hash = 0;
  int l = strlen(b);
  for(;l>=0;--l)
    hash = b[l] + h << 5;
  h ^= (h >> 20) ^ (h >> 12);
  return h ^ (h >> 7) ^ (h >> 4)
}

Name: Anonymous 2011-12-04 15:26

>>4
I am thinking h is hash?

Name: Anonymous 2011-12-04 16:30

MD5 is relatively fast, and can be used if you don't need any security. If you do need cryptographic collision resistance, you want SHA-256.

There's much faster hash algorithms, but the ones I can think of at the top of my head are all intended for hash tables and the like, and 32-bit integers are too small for collision resistance, which means you have to double check any positive match.
If 32-bit is enough for you, just use CRC32. It's widely supported, and has hardware acceleration on new Intel CPUs

Don't change these.
Name: Email:
Entire Thread Thread List