James Koppel
James Koppel

Reputation: 1617

What is this hash function?

I was reverse-engineering the archive file format used by an old game, and discovered that it hashed filenames using the following function (decompiled by hand):

int hash(char* filename) {
  unsigned int a = 0;
  int b = 0;
  for(int i = strlen(filename)-1; i>=0; i--)
   char c = toupper(filename[i]);
   a=(a<<5)+(a>>25);
   b+=c;
   a+=b+c;
  }
  return a;
}

I'm wondering if this is anything standard, or if it's just something random picked by the developers.

Upvotes: 2

Views: 335

Answers (1)

Nickolay Olshevsky
Nickolay Olshevsky

Reputation: 14160

It doesn't represent any standard hash function, just simple 'hand-made'.

Upvotes: 2

Related Questions