1.1--- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2+++ b/lisp/std/hash-table.lisp Mon Apr 22 23:14:47 2024 -0400
1.3@@ -0,0 +1,47 @@
1.4+;;; std/hash-table.lisp --- Standard Hash Tables
1.5+
1.6+;;
1.7+
1.8+;;; Code:
1.9+(in-package :std/hash-table)
1.10+
1.11+(declaim (inline maphash-keys))
1.12+(defun maphash-keys (function table)
1.13+ "Like MAPHASH, but calls FUNCTION with each key in the hash table TABLE."
1.14+ (maphash (lambda (k v)
1.15+ (declare (ignore v))
1.16+ (funcall function k))
1.17+ table))
1.18+
1.19+(declaim (inline maphash-values))
1.20+(defun maphash-values (function table)
1.21+ "Like MAPHASH, but calls FUNCTION with each value in the hash table TABLE."
1.22+ (maphash (lambda (k v)
1.23+ (declare (ignore k))
1.24+ (funcall function v))
1.25+ table))
1.26+
1.27+(defun hash-table-keys (table)
1.28+ "Returns a list containing the keys of hash table TABLE."
1.29+ (let ((keys nil))
1.30+ (maphash-keys (lambda (k)
1.31+ (push k keys))
1.32+ table)
1.33+ keys))
1.34+
1.35+(defun hash-table-values (table)
1.36+ "Returns a list containing the values of hash table TABLE."
1.37+ (let ((values nil))
1.38+ (maphash-values (lambda (v)
1.39+ (push v values))
1.40+ table)
1.41+ values))
1.42+
1.43+(defun hash-table-alist (table)
1.44+ "Returns an association list containing the keys and values of hash table
1.45+TABLE."
1.46+ (let ((alist nil))
1.47+ (maphash (lambda (k v)
1.48+ (push (cons k v) alist))
1.49+ table)
1.50+ alist))