I am trying to write a hashing algorithm that's gonna successfully hash System.Windows.Input.Key values with modifier key states, for instance:
ctrl = false
shift = true
alt = false
capslock = true
numlock = false
scroll lock = false
key: A
So a key value like this should be separated from others with different states for ctrl, shift, alt, etc. But since these are just true or false, I am not sure how to make it distinct for the hash values?
Any ideas? It just have to be unique enough to handle all possible key combinations.
I would build a class containing all values able to compute it's own hash code, like:
Credits to this Jon Skeet's answer for the
GetHashCode()
implementation.N.B.
this class can be effectively used as a
Dictionary
key, intoHashSet
or in LINQDistinct()
and other LINQ sets' operations.EDIT:
I'd like to enforce the fact that you mustn't use the hash code as dictionary key, but use the whole class instead.
You cannot rely on the uniqueness of the hash-codes because hashing it's subjected to collisions.