Hash function on list independant of order of items in it

后端 未结 9 934
无人共我
无人共我 2021-01-19 21:54

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

9条回答
  •  青春惊慌失措
    2021-01-19 22:47

    Why not something like

    public int GetOrderIndependantHashCode(IEnumerable source)
    {
        return (source.Select(x => x*x).Sum()
                + source.Select(x => x*x*x).Sum()
                + source.Select(x => x*x*x*x).Sum()) & 0x7FFFFF;
    }
    

提交回复
热议问题