Grumpy
Grumpy

Reputation: 2243

smallest checksum on a string

scratching my head over this.

I have 350 strings average 90 chars long, all strings are unique. Now, I want to generate a unique id for each string.

I tried the sum of chars in the string which gave two doubles, the returned sum is not unique enough. Anybody any idea how to approach this? I thought of hash(), is that the best solution?

abcdef will return the same as abcdfe

Upvotes: 0

Views: 885

Answers (2)

bill simpson
bill simpson

Reputation: 46

If you have a fixed set of strings and you will only need to look those up then find a minimal perfect hash function. http://en.wikipedia.org/wiki/Perfect_hash_function

Upvotes: 3

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798744

Checksums and hashes will never be unique. Call the first string "1" and go from there.

Upvotes: 1

Related Questions