Weak hash tables allow the garbage collector to reclaim some of the
entries if they are not strongly referenced elsewhere. ECL supports
four kinds of weakness in hash tables: :key, :value,
:key-and-value and :key-or-value.
To make hash table weak, programmer has to provide :weakness
keyword argument to cl:make-hash-table with the desired kind of
weakness value (nil means that the hash table has only strong
references).
For more information see Weak References - Data Types and Implementation by Bruno Haible.
Returns type of the hash table weakness. Possible return values are:
:key, :value, :key-and-value, :key-or-value
or nil.
By default ECL doesn’t protect hash tables from simultaneous access
for performance reasons. Read and write access may is synchronized
when :synchronized keyword argument to make-hash-table is
t - (make-hash-table :synchronized t).
Predicate answering whether hash table is synchronized or not.
Returns freshly consed list of pairs (key . val) being contents
of the hash table.
Fills ht with values being list of (key . val). Hash
table may have some content already, but conflicting keys will be
overwritten.
make-hash-table may accept arbitrary :test keyword for
the equivalence predicate. If it is not one of the standard predicates
(:eq, :eql, :equal, :equalp) a keyword
argument :hashing-function must be a function accepting one
argument and returning a positive fixnum. Otherwise the argument is
ignored.
CL-USER> (defparameter *ht*
(make-hash-table :synchronized t
:weakness :key-or-value))
*HT*
CL-USER> (ext:hash-table-weakness *ht*)
:KEY-OR-VALUE
CL-USER> (ext:hash-table-synchronized-p *ht*)
T
CL-USER> (ext:hash-table-fill *ht* '((:foo 3) (:bar 4) (:quux 5)))
#<hash-table 000055b1229e0b40>
CL-USER> (ext:hash-table-content *ht*)
((#<weak-pointer 000055b121866350> . #<weak-pointer 000055b121866320>)
(#<weak-pointer 000055b121866370> . #<weak-pointer 000055b121866360>)
(#<weak-pointer 000055b121866390> . #<weak-pointer 000055b121866380>))
Common Lisp and C equivalence
| Lisp symbol | C function |
|---|---|
| clrhash | cl_object cl_clrhash(cl_object hash_table) |
| gethash | cl_object cl_gethash(cl_narg narg, cl_object key, cl_object hash_table, ...) |
| (setf gethash) | cl_object si_hash_set(cl_object key, cl_object hash_table, cl_object value) |
| hash-table-count | cl_object cl_hash_table_count(cl_object hash_table) |
| hash-table-p | cl_object cl_hash_table_p(cl_object hash_table) |
| hash-table-rehash-size | cl_object cl_hash_table_rehash_size(cl_object hash_table) |
| hash-table-rehash-threshold | cl_object cl_hash_table_rehash_threshold(cl_object hash_table) |
| hash-table-size | cl_object cl_hash_table_size(cl_object hash_table) |
| hash-table-test | cl_object cl_hash_table_test(cl_object hash_table) |
| make-hash-table | cl_object cl_make_hash_table(cl_narg narg, ...) |
| maphash | cl_object cl_maphash(cl_object function, cl_object hash_table) |
| remhash | cl_object cl_remhash(cl_object key, cl_object hash_table) |
| sxhash | cl_object cl_sxhash(cl_object object) |