Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Set hash-table size to number of entries in hash-table-copy

As reported by John Croisant before this patch hash-table-copied
tables would report a size of 0.  This is due to *make-hash-table
setting the number of entries to 0 regardless of the size of the
hash-table's vector.

This patch also adds a test to the testsuite.

Signed-off-by: felix <felix@call-with-current-continuation.org>
  • Loading branch information...
commit 735a6304b138dce0ca5a47577ff23a9a884d12df 1 parent a741336
@ckeen ckeen authored bunny351 committed
Showing with 27 additions and 16 deletions.
  1. +18 −16 srfi-69.scm
  2. +9 −0 tests/hash-table-tests.scm
View
34 srfi-69.scm
@@ -668,22 +668,24 @@
(lambda (ht)
(let* ([vec1 (##sys#slot ht 1)]
[len (##sys#size vec1)]
- [vec2 (make-vector len '())] )
- (do ([i 0 (fx+ i 1)])
- [(fx>= i len)
- (*make-hash-table
- (##sys#slot ht 3) (##sys#slot ht 4)
- (##sys#slot ht 2)
- (##sys#slot ht 5) (##sys#slot ht 6)
- (##sys#slot ht 7) (##sys#slot ht 8)
- (##sys#slot ht 9) vec2)]
- (##sys#setslot vec2 i
- (let copy-loop ([bucket (##sys#slot vec1 i)])
- (if (null? bucket)
- '()
- (let ([pare (##sys#slot bucket 0)])
- (cons (cons (##sys#slot pare 0) (##sys#slot pare 1))
- (copy-loop (##sys#slot bucket 1))))))) ) ) ) ) )
+ [vec2 (make-vector len '())]
+ [ht2 (do ([i 0 (fx+ i 1)])
+ [(fx>= i len)
+ (*make-hash-table
+ (##sys#slot ht 3) (##sys#slot ht 4)
+ (##sys#slot ht 2)
+ (##sys#slot ht 5) (##sys#slot ht 6)
+ (##sys#slot ht 7) (##sys#slot ht 8)
+ (##sys#slot ht 9) vec2)]
+ (##sys#setslot vec2 i
+ (let copy-loop ([bucket (##sys#slot vec1 i)])
+ (if (null? bucket)
+ '()
+ (let ([pare (##sys#slot bucket 0)])
+ (cons (cons (##sys#slot pare 0) (##sys#slot pare 1))
+ (copy-loop (##sys#slot bucket 1))))))) )])
+ (##sys#setslot ht2 2 (##sys#slot ht 2))
+ ht2 ) ) ) )
(define (hash-table-copy ht)
(##sys#check-structure ht 'hash-table 'hash-table-copy)
View
9 tests/hash-table-tests.scm
@@ -204,3 +204,12 @@
[(fx= i stress-size)]
(assert (fx= i (hash-table-ref ht i))) ) )
+(print "HT - copy")
+(define l '((1 a) (2 b) (3 c)))
+(set! ht (alist->hash-table l))
+(define ht2 (hash-table-copy ht))
+(assert (= (hash-table-size ht2) (hash-table-size ht)))
+(print l " -- " (hash-table->alist ht2))
+(assert (equal? l (sort (hash-table->alist ht2)
+ (lambda (e1 e2) (< (car e1) (car e2))))))
+
Please sign in to comment.
Something went wrong with that request. Please try again.