I want to have a dictionary that assigns a value to a set of integers.
For example key
is [1 2 3]
and value
will have certain value.
The thing is that [3 2 1]
needs to be treated the same in my case so hash needs to be equal, if I go with hash approach.
The set will have 2 to 10 items.
Sum of items is usually fixed so we cannot make hashcode according to sum, which is a first natural idea here.
Not a homework task, actually facing this problem in my code.
This set is basically IEnumerable<int>
in C# so any data structure is fine to store them.
Any help appreciated. Performance is pretty important here too.
An immediate thought: we could sum up items^2
and already get some kind of better hash, but still I would like to hear some thoughts.
EDIT: hmm really sorry guys, everyone suggests ordering, didn't come to my mind that I needed to say that actually ordering and hashing is the current solution I use and I am considering faster alternatives.