Hashes now use integers instead of fixnums, it seems?

This commit is contained in:
Suzanne Soy 2021-04-04 19:51:27 +01:00
parent 864d8b110e
commit 7a01fad928
2 changed files with 14 additions and 20 deletions

View File

@ -104,17 +104,11 @@ same if the @tc[database] and @tc[index] is the same for both nodes.
(eq? (raw-node-database a) (raw-node-database b)) (eq? (raw-node-database a) (raw-node-database b))
(equal? (raw-node-index a) (raw-node-index b)))) (equal? (raw-node-index a) (raw-node-index b))))
(λ (a r) (λ (a r)
(fxxor (eq-hash-code (raw-node-database a)) (bitwise-xor (eq-hash-code (raw-node-database a))
(let ([i (r (raw-node-index a))]) (r (raw-node-index a))))
(if (fixnum? i)
i
(error "index too big")))))
(λ (a r) (λ (a r)
(fxxor (eq-hash-code (raw-node-database a)) (bitwise-xor (eq-hash-code (raw-node-database a))
(let ([i (r (raw-node-index a))]) (r (raw-node-index a)))))]
(if (fixnum? i)
i
(error "index too big"))))))]
The following function can then be used to test if two nodes are the same, based The following function can then be used to test if two nodes are the same, based
on the contents of their @tc[raw] field: on the contents of their @tc[raw] field:
@ -227,7 +221,7 @@ them with a special marker.
@chunk[<node-hash> @chunk[<node-hash>
(: node-hash ( (fieldᵢ/τ ) (: node-hash ( (fieldᵢ/τ )
( (node-id fieldᵢ/τ Any Any) ( Any Fixnum) Fixnum))) ( (node-id fieldᵢ/τ Any Any) ( Any Integer) Integer)))
(define (node-hash nd racket-recur-hash) (define (node-hash nd racket-recur-hash)
(if (eq? (raw-node-database ((struct-accessor node-id raw) nd)) (if (eq? (raw-node-database ((struct-accessor node-id raw) nd))
'unique-copy) 'unique-copy)
@ -281,9 +275,9 @@ To combine hash codes, we simply compute their @elem[#:style 'tt]{xor}. Later
versions of this library may use more sophisticated mechanisms. versions of this library may use more sophisticated mechanisms.
@chunk[<combine-hash-codes> @chunk[<combine-hash-codes>
(: combine-hash-codes ( Fixnum * Fixnum)) (: combine-hash-codes ( Integer * Integer))
(define (combine-hash-codes . fixnums) (define (combine-hash-codes . hashes)
(apply fxxor fixnums))] (apply bitwise-xor hashes))]
@subsection{Caching node equality} @subsection{Caching node equality}

View File

@ -235,13 +235,13 @@ nodes have the same shape, but cannot by themselves create logical cycles.
#t)) #t))
(λ (a rec-hash) (λ (a rec-hash)
(fxxor (rec-hash 'id) (bitwise-xor (rec-hash 'id)
(rec-hash (force ((struct-accessor pid fieldᵢ) a))) (rec-hash (force ((struct-accessor pid fieldᵢ) a)))
)) ))
(λ (a rec-hash) (λ (a rec-hash)
(fxxor (rec-hash 'id) (bitwise-xor (rec-hash 'id)
(rec-hash (force ((struct-accessor pid fieldᵢ) a))) (rec-hash (force ((struct-accessor pid fieldᵢ) a)))
))))] ))))]
@section{Pre-declaring structs} @section{Pre-declaring structs}