Looking for a non-cryptographic hash function that returns a single character
Posted
by
makerofthings7
on Programmers
See other posts from Programmers
or by makerofthings7
Published on 2012-11-20T21:47:24Z
Indexed on
2012/11/20
23:20 UTC
Read the original article
Hit count: 247
Suppose I have a dictionary of ASCII words stored in uppercase. I also want to save those words into separate files so that the total word count of each file is approximately the same. By simply looking at the word I need to know which file it should be in (if it's there at all). Duplicate words should go into the same file and overwrite the last one.
My first attempt at solving this problem is to use .NET's object.GetHashCode()
function and .Trim()
to get one of the "random" characters that pop up. I asked a similar question here
If I only use one character of object.GetHashCode()
I would get a hash code character of A..Z or 0..9. However saving the result of GetHashCode to disk is a no-no so I need a substitute.
Question:
What algorithm (or subset of an algorithm) is appropriate for pigeonholing strings
into a single character or range of characters (Like hex 0..F offers 16 chars)?
Real world usage:
I'll use this answer to modify the Partition key used in Azure Table storage as described here
© Programmers or respective owner