问题描述
在我的程序中,我处理了大量 n 大小的列表,它们都是[1,..., n ]的排列组合。我的问题是我把这些置换放在 HashMap
s和 HashSet
s中,我需要一个很好的 hashCode()
避免了太多的冲突。
In my program, I handle a lot of lists of size n that all are permutations of [1,...,n]. My problem is that I put these permutations in HashMap
s and HashSet
s, and I need a good hashCode()
that avoids too many collisions.
所有我认为会导致碰撞或溢出的解决方案。
如何为排列写一个好的hashCode? p>
All the solutions I have thought of lead to either a lot of collisions or an overflow.How can I write a good hashCode for permutations ?
推荐答案
您是否尝试过使用''?您可以调整桶的旋转量,以查看它是否与哈希分布有很大差异。
Have you tried a 'rotating hash'? You could adjust the barrel rotate amount to see if it makes much difference to the hash distribution.
这篇关于如何编写一个好的hashCode()用于排列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!