Created
November 29, 2016 15:29
-
-
Save zhouqiang-cl/0af86b3cbdc8801ed9468e7cfee3126c to your computer and use it in GitHub Desktop.
common lisp 的函数 MAKE-HASH-TABLE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
语法 | |
make-hash-table &key test size rehash-size rehash-threshold => hash-table | |
参数和值 | |
test --- 一个指示符. eq, eql, equal, equalp 函数中的一个, 默认是eql | |
size --- 一个正整数 | |
rehash-size --- 一个正整数或者浮点数 | |
rehash-threshold --- 0-1 之间的一个实数 | |
hash-table --- 一个 hash table 对象 | |
描述 | |
创建一个 hash table | |
test 测试 key 是怎么比较的, 如果用 test 函数探测到这个key和某一个key 相同, 则认为这个对象存在 | |
size 初始化的时候有多少个 key 空间 | |
rehash-size 表示当空间满的时候一次增加多少个空间 | |
rehash-threshold 在空间增长前有多少空间可以得到的比例, 表示 hash table 的最大占用率 | |
代码 | |
* (setq table (make-hash-table)) | |
#<HASH-TABLE :TEST EQL :COUNT 0 {1004B01933}> | |
* (setf (gethash "one" table) 1) | |
1 | |
* (gethash "one" table) | |
NIL | |
NIL | |
* (setq table (make-hash-table :test 'equal)) | |
#<HASH-TABLE :TEST EQUAL :COUNT 0 {1004B580C3}> | |
* (setf (gethash "one" table) 1) | |
1 | |
* (gethash "one" table) | |
1 | |
T |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment