Iterates over all entries in the hash-table. For each entry, the function is called with two arguments--the key and the value of that entry.
The consequences are unspecified if any attempt is made to add or remove an entry from the hash-table while a maphash is in progress, with two exceptions: the function can use can use setf of gethash to change the value part of the entry currently being processed, or it can use remhash to remove that entry.
(defparameter *table* (make-hash-table))
→*TABLE*
(dotimes (i 10) (setf (gethash i *table*) i))
→(let ((sum-of-squares 0)) (maphash #'(lambda (key val) (let ((square (* val val))) (incf sum-of-squares square) (setf (gethash key *table*) square)))
table*)sum-of-squares)
→285
(hash-table-count *table*)
→10
(maphash #'(lambda (key val) (when (oddp val) (remhash key *table*)))
table*) <r>NIL </r>(hash-table-count *table*)
→5
(maphash #'(lambda (k v) (print (list k v))) *table*)
▷(0 0) (8 64) (2 4) (6 36) (4 16)
→NIL </blockquote>
====Side Effects==== None, other than any which might be done by the function.
====Affected By==== None.
====Exceptional Situations==== None.
====See Also====
{\secref\TraversalRules}
====Notes==== None.
\issue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}