aboutsummaryrefslogtreecommitdiffstats
path: root/lib/cuprate/implementation/srfi-125-eq-map.scm
blob: 3a1d7b9c3973519711d61d799bdc96a4bf623b59 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
(define (make-eq-map)
  (define counter-table (make-hash-table (make-eq-comparator)))
  (define used-table (make-hash-table (make-eq-comparator)))
  (define counter 0)
  (lambda (msg obj)
    (case msg
      ((contains?) (hash-table-contains? counter-table obj))
      ((cycle-counter) (let ((num (hash-table-ref counter-table obj)))
                         (hash-table-set! used-table obj #t)
                         (string->symbol
                          (string-append "#"
                                         (number->string num)
                                         "#"))))
      ((cycle-used?) (hash-table-contains? used-table obj))
      ((intern!) (hash-table-set! counter-table obj counter)
                 (set! counter (+ counter 1)))
      (else (error "invalid message" msg)))))