Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

open-axiom repository from github

24005 views
1
;; Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
2
;; All rights reserved.
3
;; Copyright (C) 2007, Gabriel Dos Reis.
4
;; All rights reserved.
5
;;
6
;; Redistribution and use in source and binary forms, with or without
7
;; modification, are permitted provided that the following conditions are
8
;; met:
9
;;
10
;; - Redistributions of source code must retain the above copyright
11
;; notice, this list of conditions and the following disclaimer.
12
;;
13
;; - Redistributions in binary form must reproduce the above copyright
14
;; notice, this list of conditions and the following disclaimer in
15
;; the documentation and/or other materials provided with the
16
;; distribution.
17
;;
18
;; - Neither the name of The Numerical ALgorithms Group Ltd. nor the
19
;; names of its contributors may be used to endorse or promote products
20
;; derived from this software without specific prior written permission.
21
;;
22
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
23
;; IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24
;; TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25
;; PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
26
;; OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27
;; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28
;; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29
;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30
;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31
;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32
;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34
35
(IMPORT-MODULE "types")
36
(in-package "BOOT")
37
38
;17.0 Operations on Hashtables
39
;17.1 Creation
40
41
(defun MAKE-HASHTABLE (id1 &optional (id2 nil))
42
(declare (ignore id2))
43
(let ((test (case id1
44
((EQ ID) #'eq)
45
(CVEC #'equal)
46
(EQL #'eql)
47
((UEQUAL EQUAL) #'equal)
48
(otherwise (error "bad arg to make-hashtable")))))
49
(make-hash-table :test test)))
50
51
;17.2 Accessing
52
53
(defmacro HGET (table key &rest default)
54
`(gethash ,key ,table ,@default))
55
56
(defun HKEYS (table)
57
(let (keys)
58
(maphash
59
#'(lambda (key val) (declare (ignore val)) (push key keys)) table)
60
keys))
61
62
#+AKCL
63
(clines "int mem_value(x ,i)object x;int i; { return ((short *)x)[i];}")
64
#+AKCL
65
(defentry memory-value-short(object int) (int "mem_value"))
66
67
;(memory-value-short (make-hash-table :test 'equal) 12) is 0,1,or 2
68
;depending on whether the test is eq,eql or equal.
69
#+AKCL
70
(defun HASHTABLE-CLASS (table)
71
(case (memory-value-short table 12)
72
(0 'EQ)
73
(1 'EQL)
74
(2 'EQUAL)
75
(t "error unknown hash table class")))
76
77
;17.4 Searching and Updating
78
79
(defun HPUT (table key value) (setf (gethash key table) value))
80
81
(defun HPUT* (table alist)
82
(mapc #'(lambda (pair) (hput table (car pair) (cdr pair))) alist))
83
84
(defmacro HREM (table key) `(remhash ,key ,table))
85
86
(defun HREMPROP (table key property)
87
(let ((plist (gethash key table)))
88
(if plist (setf (gethash key table)
89
(delete property plist :test #'equal :key #'car)))))
90
91
;17.5 Updating
92
93
(define-function 'HCLEAR #'clrhash)
94
95
;17.6 Miscellaneous
96
97
(define-function 'HASHTABLEP #'hash-table-p)
98
99
(define-function 'HASHEQ #'sxhash)
100
101
(define-function 'HASHUEQUAL #'sxhash)
102
103
(define-function 'HASHCVEC #'sxhash)
104
105
(define-function 'HASHID #'sxhash)
106
107