hash-table-rehash-size
hash-table-rehash-size Function
Syntax:
hash-table-rehash-size hash-table → rehash-size
Arguments and Values:
hash-table—a hash table.
rehash-size—a real of type (or (integer 1 *) (float (1.0) *)).
Description:
Returns the current rehash size of hash-table, suitable for use in a call to make-hash-table in order to produce a hash table with state corresponding to the current state of the hash-table.
Examples:
(setq table (make-hash-table :size 100 :rehash-size 1.4))
→ #<HASH-TABLE EQL 0/100 2556371>
(hash-table-rehash-size table) → 1.4
Exceptional Situations:
Should signal an error of type type-error if hash-table is not a hash table.
See Also:
make-hash-table, hash-table-rehash-threshold
Notes:
If the hash table was created with an integer rehash size, the result is an integer , indicating that the rate of growth of the hash-table when rehashed is intended to be additive; otherwise, the result
Hash
is a float, indicating that the rate of growth of the hash-table when rehashed is intended to be multiplicative. However, this value is only advice to the implementation; the actual amount by which the hash-table will grow upon rehash is implementation-dependent.
Expanded Reference: hash-table-rehash-size
Basic Usage
hash-table-rehash-size returns the rehash size of a hash table, indicating how the table grows when it needs to be expanded.
;; Default rehash size is implementation-dependent
(let ((ht (make-hash-table)))
(numberp (hash-table-rehash-size ht)))
=> T
Multiplicative Growth (Float)
When a float is specified, it represents a multiplicative growth factor. For example, 1.5 means the table grows to 1.5 times its current size.
(let ((ht (make-hash-table :rehash-size 1.5)))
(hash-table-rehash-size ht))
=> 1.5
Additive Growth (Integer)
When an integer is specified, it represents the number of entries to add during rehashing.
(let ((ht (make-hash-table :rehash-size 200)))
(integerp (hash-table-rehash-size ht)))
=> T
Querying for Table Duplication
The rehash size can be used alongside other parameters to create a copy of a hash table with the same configuration.
(let* ((original (make-hash-table :rehash-size 2.0
:rehash-threshold 0.8
:test #'equal))
(clone (make-hash-table
:rehash-size (hash-table-rehash-size original)
:rehash-threshold (hash-table-rehash-threshold original)
:test (hash-table-test original))))
(hash-table-rehash-size clone))
=> 2.0
Float vs. Integer Rehash Size
;; Float rehash size indicates multiplicative growth
(let ((ht (make-hash-table :rehash-size 1.7)))
(floatp (hash-table-rehash-size ht)))
=> T
;; Integer rehash size indicates additive growth
(let ((ht (make-hash-table :rehash-size 50)))
(integerp (hash-table-rehash-size ht)))
=> T