【问题标题】:Getting hashes of any type of objects in Common Lisp在 Common Lisp 中获取任何类型对象的哈希值
【发布时间】:2011-12-30 09:16:45
【问题描述】:

我正在尝试在 Common Lisp 中实现一些数据结构(如 HAMP 哈希数组映射的 trie),我需要获取要存储在这些数据结构中的对象的 32 位或 64 位哈希。

我知道我可以将对象放入 Common Lisp 哈希表(使用 (make-hash-table) 创建),但我找不到获取对象哈希的方法,例如 Java 的 hashCode 或 Python 的 hash . Common Lisp 有这样的功能吗?如果没有,CL 的标准哈希表如何从任意类型的对象生成哈希?

【问题讨论】:

    标签: hash lisp common-lisp


    【解决方案1】:

    函数sxhash为其参数返回一个哈希值。详情:sxhash.

    * (sxhash 'fred)
    4287909749829334992
    * (sxhash 'joe)
    23906557261513707
    * (sxhash 'fred)
    4287909749829334992
    

    【讨论】:

    • 太棒了!谢谢。看起来 sxhash 在我的 64 位 SBCL 系统上生成 62 位哈希。
    • sxhash 的返回值被标准定义为一个非负的fixnum。一个好的实现可能会利用所有的非负固定数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-19
    • 1970-01-01
    • 2012-03-31
    • 1970-01-01
    相关资源
    最近更新 更多