如何在 Clojure 中获取整个引用的 sha1?
我想比较参考部分的两个副本,看看它们是否已更改。我如何获得地图和任何子叶的 sha1?
I would like to compare two copies of parts of a ref to see if they have changed. How can I get a sha1 of a map and any sub leaves?
我想比较参考部分的两个副本,看看它们是否已更改。我如何获得地图和任何子叶的 sha1?
I would like to compare two copies of parts of a ref to see if they have changed. How can I get a sha1 of a map and any sub leaves?
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
根据您想要执行的具体操作,您可能会发现仅通过“散列”函数使用普通 Java hashCode() 比尝试使用 SHA 更简单:
在大多数情况下,这足以确定两个映射是否不同。
请注意,当两个对象具有相同的哈希值时,SHA 或任何其他哈希码都不能保证相等 - 许多对象可能具有相同的哈希值。因此,如果哈希值相同,您仍然需要检查两个对象的值是否相等。
此外,请注意计算哈希值比使用 = 进行简单比较更昂贵。因此,只有当您能够存储哈希值并重新使用它进行多次比较时,使用哈希技术才有意义。
Depending on exactly what you want to do, you may find just using the normal Java hashCode() via the "hash" function is simpler than trying to use SHA:
This is enough in most cases to determine if two maps are different.
Note that neither SHA or any other hashcode guarantee equality when two objects have the same hash - many objects can potentially have the same hash. As a consequence, if the hash is the same you will still have to check whether the two objects are equal in value
Also, be aware that computing hashes is more expensive than a simple comparison using =. So it only makes sense to use a hashing technique if you are able to store the hash value and re-use it for many comparisons.