java – C中的HashCodeBuilder
发布时间:2020-12-15 08:30:37 所属栏目:Java 来源:网络整理
导读:如果我想在 Java中为给定对象生成哈希,我知道的最简单方法是使用Apache Commons HashCodeBuilder : public class Person { String name; int age; boolean smoker; ... public int hashCode() { // you pick a hard-coded,randomly chosen,non-zero,odd num
如果我想在
Java中为给定对象生成哈希,我知道的最简单方法是使用Apache Commons
HashCodeBuilder :
public class Person { String name; int age; boolean smoker; ... public int hashCode() { // you pick a hard-coded,randomly chosen,non-zero,odd number // ideally different for each class return new HashCodeBuilder(17,37). append(name). append(age). append(smoker). toHashCode(); } } C中有类似的东西吗? 解决方法
使用
boost::hash_combine.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |