如何编写一个好的hashCode()用于排列? [英] How to write a good hashCode() for permutations?

查看:158
本文介绍了如何编写一个好的hashCode()用于排列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的程序中,我处理了大量 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 HashMaps and HashSets, and I need a good hashCode() that avoids too many collisions.

所有我认为会导致碰撞或溢出的解决方案。
如何为排列写一个好的hashCode?

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()用于排列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆