changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / lisp/std/hash-table.lisp

changeset 698: 96958d3eb5b0
parent: a0dfde3cb3c4
author: Richard Westhaver <ellis@rwest.io>
date: Fri, 04 Oct 2024 22:04:59 -0400
permissions: -rw-r--r--
description: fixes
1 ;;; std/hash-table.lisp --- Standard Hash Tables
2 
3 ;;
4 
5 ;;; Code:
6 (in-package :std/hash-table)
7 
8 (declaim (inline maphash-keys))
9 (defun maphash-keys (function table)
10  "Like MAPHASH, but calls FUNCTION with each key in the hash table TABLE."
11  (maphash (lambda (k v)
12  (declare (ignore v))
13  (funcall function k))
14  table))
15 
16 (declaim (inline maphash-values))
17 (defun maphash-values (function table)
18  "Like MAPHASH, but calls FUNCTION with each value in the hash table TABLE."
19  (maphash (lambda (k v)
20  (declare (ignore k))
21  (funcall function v))
22  table))
23 
24 (defun hash-table-keys (table)
25  "Returns a list containing the keys of hash table TABLE."
26  (let ((keys nil))
27  (maphash-keys (lambda (k)
28  (push k keys))
29  table)
30  keys))
31 
32 (defun hash-table-values (table)
33  "Returns a list containing the values of hash table TABLE."
34  (let ((values nil))
35  (maphash-values (lambda (v)
36  (push v values))
37  table)
38  values))
39 
40 (defun hash-table-alist (table)
41  "Returns an association list containing the keys and values of hash table
42 TABLE."
43  (let ((alist nil))
44  (maphash (lambda (k v)
45  (push (cons k v) alist))
46  table)
47  alist))