* dynl.c (scm_dynamic_call, scm_dynamic_args_call): Wrap dynamic
[bpt/guile.git] / ice-9 / hcons.scm
1 ;;; installed-scm-file
2
3 ;;;; Copyright (C) 1995, 1996 Free Software Foundation, Inc.
4 ;;;;
5 ;;;; This program is free software; you can redistribute it and/or modify
6 ;;;; it under the terms of the GNU General Public License as published by
7 ;;;; the Free Software Foundation; either version 2, or (at your option)
8 ;;;; any later version.
9 ;;;;
10 ;;;; This program is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;;;; GNU General Public License for more details.
14 ;;;;
15 ;;;; You should have received a copy of the GNU General Public License
16 ;;;; along with this software; see the file COPYING. If not, write to
17 ;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 ;;;; Boston, MA 02111-1307 USA
19 ;;;;
20
21 \f
22 (define-module #/ice-9/hcons)
23
24 \f
25 ;;; {Eq? hash-consing}
26 ;;;
27 ;;; A hash conser maintains a private universe of pairs s.t. if
28 ;;; two cons calls pass eq? arguments, the pairs returned are eq?.
29 ;;;
30 ;;; A hash conser does not contribute life to the pairs it returns.
31 ;;;
32
33 (define-public (hashq-cons-hash pair n)
34 (modulo (logxor (hashq (car pair) 4194303)
35 (hashq (cdr pair) 4194303))
36 n))
37
38 (define-public (hashq-cons-assoc key l)
39 (and l (or (and (pair? l)
40 (pair? (car l))
41 (pair? (caar l))
42 (eq? (car key) (caaar l))
43 (eq? (cdr key) (cdaar l))
44 (car l))
45 (hashq-cons-assoc key (cdr l)))))
46
47 (define-public (hashq-cons-get-handle table key)
48 (hashx-get-handle hashq-cons-hash hashq-cons-assoc table key #f))
49
50 (define-public (hashq-cons-create-handle! table key init)
51 (hashx-create-handle! hashq-cons-hash hashq-cons-assoc table key init))
52
53 (define-public (hashq-cons-ref table key)
54 (hashx-ref hashq-cons-hash hashq-cons-assoc table key #f))
55
56 (define-public (hashq-cons-set! table key val)
57 (hashx-set! hashq-cons-hash hashq-cons-assoc table key val))
58
59 (define-public (hashq-cons table a d)
60 (car (hashq-cons-create-handle! table (cons a d) #f)))
61
62 (define-public (hashq-conser hash-tab-or-size)
63 (let ((table (if (vector? hash-tab-or-size)
64 hash-tab-or-size
65 (make-doubly-weak-hash-table hash-tab-or-size))))
66 (lambda (a d) (hashq-cons table a d))))
67
68
69 \f
70
71 (define-public (make-gc-buffer n)
72 (let ((ring (make-list n #f)))
73 (append! ring ring)
74 (lambda (next)
75 (set-car! ring next)
76 (set! ring (cdr ring))
77 next)))