;; Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.1;; All rights reserved.2;; Copyright (C) 2007, Gabriel Dos Reis.3;; All rights reserved.4;;5;; Redistribution and use in source and binary forms, with or without6;; modification, are permitted provided that the following conditions are7;; met:8;;9;; - Redistributions of source code must retain the above copyright10;; notice, this list of conditions and the following disclaimer.11;;12;; - Redistributions in binary form must reproduce the above copyright13;; notice, this list of conditions and the following disclaimer in14;; the documentation and/or other materials provided with the15;; distribution.16;;17;; - Neither the name of The Numerical ALgorithms Group Ltd. nor the18;; names of its contributors may be used to endorse or promote products19;; derived from this software without specific prior written permission.20;;21;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS22;; IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED23;; TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A24;; PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER25;; OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,26;; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,27;; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR28;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF29;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING30;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS31;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.323334(IMPORT-MODULE "types")35(in-package "BOOT")3637;17.0 Operations on Hashtables38;17.1 Creation3940(defun MAKE-HASHTABLE (id1 &optional (id2 nil))41(declare (ignore id2))42(let ((test (case id143((EQ ID) #'eq)44(CVEC #'equal)45(EQL #'eql)46((UEQUAL EQUAL) #'equal)47(otherwise (error "bad arg to make-hashtable")))))48(make-hash-table :test test)))4950;17.2 Accessing5152(defmacro HGET (table key &rest default)53`(gethash ,key ,table ,@default))5455(defun HKEYS (table)56(let (keys)57(maphash58#'(lambda (key val) (declare (ignore val)) (push key keys)) table)59keys))6061#+AKCL62(clines "int mem_value(x ,i)object x;int i; { return ((short *)x)[i];}")63#+AKCL64(defentry memory-value-short(object int) (int "mem_value"))6566;(memory-value-short (make-hash-table :test 'equal) 12) is 0,1,or 267;depending on whether the test is eq,eql or equal.68#+AKCL69(defun HASHTABLE-CLASS (table)70(case (memory-value-short table 12)71(0 'EQ)72(1 'EQL)73(2 'EQUAL)74(t "error unknown hash table class")))7576;17.4 Searching and Updating7778(defun HPUT (table key value) (setf (gethash key table) value))7980(defun HPUT* (table alist)81(mapc #'(lambda (pair) (hput table (car pair) (cdr pair))) alist))8283(defmacro HREM (table key) `(remhash ,key ,table))8485(defun HREMPROP (table key property)86(let ((plist (gethash key table)))87(if plist (setf (gethash key table)88(delete property plist :test #'equal :key #'car)))))8990;17.5 Updating9192(define-function 'HCLEAR #'clrhash)9394;17.6 Miscellaneous9596(define-function 'HASHTABLEP #'hash-table-p)9798(define-function 'HASHEQ #'sxhash)99100(define-function 'HASHUEQUAL #'sxhash)101102(define-function 'HASHCVEC #'sxhash)103104(define-function 'HASHID #'sxhash)105106107