There are five hash table inspection modes. They can be accessed in either the LispWorks IDE Inspector tool or the REPL inspector.
A brief introduction to the representation of hash tables is necessary so that you can fully understand what you gain from the new modes.
Internally, a hash table is a structure containing, among other things,
When keys and values are added to the table, sufficiently similar keys are converted into the same index in the vector. When this happens, the similar keys and values are kept together in a chain that hangs off this place in the vector.
The different inspection modes provide views of different pieces of this structure:
This mode is the "normal" view of a hash table; as a table of keys and values. When you inspect an item you inspect the value of the item.
This mode provides a raw view of the whole hash table structure. When you inspect an item you are inspecting the value of that slot in the hash table structure.
This mode is a variation of the normal view, where a hash table is viewed simply as a list of lists. When you inspect an item you are inspecting a list containing a key and a value.
This mode shows how long the chains in the hash table are, so that you can tell how efficiently it is being used. For example, if all chains contained fewer than two items the hash table would be being used well.
This mode shows the statistical information from
HASH-TABLE-STATISTICS
as a histogram.
Here is an example of hash table inspection.
CL-USER 1 > (defvar *hash* (make-hash-table))
*HASH*
CL-USER 2 > (setf (gethash 'lisp *hash*) 'programming
(gethash 'java *hash*) 'programming
(gethash 'c *hash*) 'programming
(gethash 'c++ *hash*) 'programming
(gethash 'english *hash*) 'natural
(gethash 'german *hash*) 'natural)
NATURAL
CL-USER 3 > (inspect *hash*)
#<EQL Hash Table{6} 21C15D97> is a HASH-TABLE
C++ PROGRAMMING
JAVA PROGRAMMING
ENGLISH NATURAL
C PROGRAMMING
GERMAN NATURAL
LISP PROGRAMMING
CL-USER 4 : Inspect 1 > :m
* 1. HASH-TABLE
2. STRUCTURE
3. ENUMERATED-HASH-TABLE
4. HASH-TABLE-STATISTICS
5. HASH-TABLE-HISTOGRAM
STRUCTURE
mode displays the raw representation of the hash table:
CL-USER 5 : Inspect 1 > :m 2
#<EQL Hash Table{6} 21C15D97> is a HASH-TABLE
KIND EQL
SIZE 37
REHASH-SIZE 2.0
REHASH-THRESHOLD 1.0
THRESHOLD 37
COUNTER 525
NUMBER-ENTRIES 6
TABLE #(#%((LISP . PROGRAMMING) NIL) NIL NIL NIL NIL ...)
NO-DESTRUCT-REHASH NIL
POWER2 NIL
HASH-REM SYSTEM::DIVIDE-GENERAL
HASH-FN SYSTEM::EQL-HASHFN
GETHASH-FN SYSTEM::GETHASH-EQL
PUTHASH-FN SYSTEM::PUTHASH-EQL
REMHASH-FN SYSTEM::REMHASH-EQL
GET-TLATTER-FN SYSTEM::GET-TLATTER-EQL
WEAK-KIND NIL
USER-STUFF NIL
MODIFICATION-COUNTER 0
FAST-LOCK-SLOT 0
In
ENUMERATED-HASH-TABLE
mode you can recursively inspect keys and values by entering the index. This is especially useful in cases where the key or value is unreadable and so cannot be entered into the REPL:
CL-USER 6 : Inspect 1 > :m 3
#<EQL Hash Table{6} 21C15D97> is an Enumerated HASH TABLE
0 (C++ PROGRAMMING)
1 (JAVA PROGRAMMING)
2 (ENGLISH NATURAL)
3 (C PROGRAMMING)
4 (GERMAN NATURAL)
5 (LISP PROGRAMMING)
CL-USER 7 : Inspect 1 > 5
(LISP PROGRAMMING) is a LIST
0 LISP
1 PROGRAMMING
CL-USER 8 : Inspect 2 > :u
The
HASH-TABLE-STATISTICS
mode shows that
*hash*
has 31 chains, of which 25 are empty and 6 have one entry::
CL-USER 9 : Inspect 1 > :m 4
#<EQL Hash Table{6} 21C15D97> is a HASH-TABLE (statistical view)
chain of length 0 : 31
chain of length 1 : 6
In HASH-TABLE-HISTOGRAM mode the same information is represented as a histogram:
CL-USER 10 : Inspect 1 > :m 5
#<EQL Hash Table{6} 21C15D97> is a HASH-TABLE (histogram view)
chain of length 0 : "*******************************"
chain of length 1 : "******"
CL-USER 11 : Inspect 1 > :q
#<EQL Hash Table{6} 21C15D97>
LispWorks User Guide and Reference Manual - 21 Dec 2011