File: clos-stablehash1.lisp

package info (click to toggle)
clisp 1%3A2.49-8.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 45,160 kB
  • sloc: lisp: 79,960; ansic: 48,257; xml: 26,814; sh: 12,846; fortran: 7,286; makefile: 1,456; perl: 164
file content (35 lines) | stat: -rw-r--r-- 1,382 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
;;;; Common Lisp Object System for CLISP
;;;; Objects with stable hash code
;;;; Part 1: Class definition.
;;;; Bruno Haible 2004-05-15

(in-package "CLOS")

;;; ===========================================================================

;;; The class <standard-stablehash> allows CLOS instances to have a
;;; GC-invariant EQ hash code.
;;; Used for (make-hash-table :test 'stablehash-eq).

(defvar *<standard-stablehash>-defclass*
  '(defclass standard-stablehash ()
     (($hashcode :initform (sys::random-posfixnum))) ; GC invariant hash code
     (:fixed-slot-locations t)))

;; Fixed slot locations.
(defconstant *<standard-stablehash>-hashcode-location* 1)

;; No need for accessors. The hashcode is used by hashtabl.d.

;; Initialization of a <standard-stablehash> instance.
(defun shared-initialize-<standard-stablehash> (object situation &rest args
                                                &key &allow-other-keys)
  (if *classes-finished*
    (apply #'%shared-initialize object situation args) ; == (call-next-method)
    ; Bootstrapping: Simulate the effect of #'%shared-initialize.
    (when (eq situation 't) ; called from initialize-instance?
      (setf (standard-instance-access object *<standard-stablehash>-hashcode-location*)
            (sys::random-posfixnum))))
  object)

;;; ===========================================================================