Permalink
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>
(cherry picked from commit 735a630)

Conflicts:

	srfi-69.scm (aesthetic difference)
	tests/hash-table-tests.scm (some other tests are not backported)
  • Loading branch information...
1 parent c38a0a0 commit bb492953343cc346482c197ee0d964134826fc5d @ckeen ckeen committed with Jul 16, 2012
Showing with 28 additions and 17 deletions.
  1. +18 −17 srfi-69.scm
  2. +10 −0 tests/hash-table-tests.scm
View
@@ -625,23 +625,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)
@@ -144,3 +144,13 @@
(do ([i 0 (fx+ i 1)])
[(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))))))
+

0 comments on commit bb49295

Please sign in to comment.