;;;; ;;;; srfi-69.stk -- Basic Hash-tables Implementation ;;;; ;;;; Copyright © 2005-2007 Erick Gallesio - I3S-CNRS/ESSI ;;;; ;;;; ;;;; This program is free software; you can redistribute it and/or modify ;;;; it under the terms of the GNU General Public License as published by ;;;; the Free Software Foundation; either version 2 of the License, or ;;;; (at your option) any later version. ;;;; ;;;; This program is distributed in the hope that it will be useful, ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;;; GNU General Public License for more details. ;;;; ;;;; You should have received a copy of the GNU General Public License ;;;; along with this program; if not, write to the Free Software ;;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, ;;;; USA. ;;;; ;;;; Author: Erick Gallesio [eg@essi.fr] ;;;; Creation date: 27-Oct-2005 23:09 (eg) ;;;; Last file update: 10-Apr-2007 19:13 (eg) ;;;; (define *%default-hash-size* (expt 2 29)) ;; ====================================================================== ;; The SRFI-69 hash functions ;; They are not defined by default since ;; - they are not prefixed by hash-table ;; - string-hash conflicts with SRFI-13 ;; - the bound default parameter is a weird idea ;; - string-hash is useless with STklos standard hash-table-hash function (define (hash obj :optional (bound *%default-hash-size*)) (modulo (hash-table-hash obj) bound)) (define (string-hash obj :optional (bound *%default-hash-size*)) (if (string? obj) (modulo (hash-table-hash obj) bound) (error "bad string ~S" obj))) (define (string-ci-hash obj :optional (bound *%default-hash-size*)) (if (string? obj) (modulo (hash-table-hash (string-downcase obj)) bound) (error "bad string ~S" obj))) (define (hash-by-identity obj :optional (bound *%default-hash-size*)) (modulo (address-of obj) bound)) ;; ====================================================================== ;; Redefine make-hash-table and alist->hash-table to use equal? instead of ;; eq? as default comparison function (define %old-make-hash-table make-hash-table) (define %old-alist->hash-table alist->hash-table) (define (make-hash-table :optional (comp equal?) (hash hash)) (%old-make-hash-table comp hash)) ;; hash-table-for-each is called hash-table-walk in SRFI-69 (define hash-table-walk hash-table-for-each) ;; Name used in srfi69 (provide "srfi-69")