I'll be nice and point out this part for you specifically from the article:
1 2 3 4
Don't post homework questions
Programmers are good at spotting homework questions; most of us have done them ourselves.
Those questions are for you to work out, so that you will learn from the experience.
It is OK to ask for hints, but not for entire solutions.
Actually also these sections are needed to the OP:
* Before You Ask
* Use meaningful, specific subject headers
* Be precise and informative about your problem
* Be explicit about your question
@maikel,
First of all, that is not a hashing algorithm. All you're doing is returning hardcoded values based on other seemingly hardcoded values. I don't even know what that's meant to be or do. Regardless of that code being totally useless as far as hashing goes, please don't post code for homework questions.
Technically, yes, it is. Although not the type of hash function you're probably thinking of.
A hash function is any well-defined procedure or mathematical function that converts a large, possibly variable-sized amount of data into a small datum, usually a single integer that may serve as an index to an array.
In this case, as Dufresne has pointed out, that's called a "minimal perfect hash".
Since the OP was asked to hash a very specific set of data, a generic hash function would be an unnecessary -- and probably undesirably -- complication.
I assumed OP meant a, for want of a better word, "real" hashing function like SHA* or MD*. One that could be used to hash e.g. passwords, files, etc.
Since the OP was asked to hash a very specific set of data, a generic hash function would be an unnecessary -- and probably undesirably -- complication.
I suppose. My guess was that OP wanted a hashing function that worked generally, but you're probably right.
Did you ever heard of "Hash-Tables"s? What do you call maps that hash into a specific set of indeces? IMHO its really funny to speak of "real" hash functions and call SHA* or MD*...