--- chicken-2.0-orig/extras.scm 2005-07-12 05:48:49.000000000 -0500 +++ chicken-2.0.alejo/extras.scm 2005-07-28 12:15:42.000000000 -0500 @@ -1396,9 +1396,18 @@ ;;; Utility definitions: -(define hashtab-default-size 301) +(define hashtab-default-size 307) (define hashtab-threshold 0.5) -(define hashtab-primes-table '(301 613 997 1597 2011 2521 3001)) + +; Predefined sizes for the hash tables: +; +; Start in 307; each element is the smallest prime that is at least twice as +; bigger as the previous element in the list. The last number is an +; exception: it is the largest fixnum we can repressent. + +(define hashtab-primes-table '(307 617 1237 2477 4957 9923 19853 39709 79423 158849 317701 635413 1270849 2541701 5083423 10166857 20333759 40667527 81335063 162670129 325340273 650680571 1073741823)) + +(define hashtab-max-size 1073741823) (define (hash-table? x) (##sys#structure? x 'hash-table)) @@ -1508,6 +1517,12 @@ (##sys#check-structure ht 'hash-table 'hash-table-ref) (not (eq? unique (ref ht key unique))) ) ) ) +(define (hash-new-len tab req) + (if (or (fx>= (##sys#slot tab 0) req) + (eq? (##sys#slot tab 1) '())) + (##sys#slot tab 0) + (hash-new-len (##sys#slot tab 1) req))) + (define hash-table-update! ;; This one was suggested by Sven Hartrumpf. (let ([eq0 eq?] @@ -1521,16 +1536,12 @@ (test (##sys#slot ht 3)) (k (hashf key len)) (c (fx+ (##sys#slot ht 2) 1)) ) - (if (fx>= c (inexact->exact (floor (* len hashtab-threshold)))) - (let* ((newlen - (cond ((memq len hashtab-primes-table) - => (lambda (n) - (let ((next (##sys#slot n 1))) - (if (eq? next '()) - (fx+ len 101) ; arbitrary - (##sys#slot next 0) ) ) ) ) - (else (fx+ len 101)) ) ) - (vec2 (make-vector newlen '())) ) + (if (and (fx>= c (inexact->exact (floor (* len hashtab-threshold)))) + (fx< len hashtab-max-size)) + (let ((vec2 (make-vector + (hash-new-len hashtab-primes-table + (min hashtab-max-size (* len 2))) + '()))) (hashtab-rehash vec vec2 hashf) (##sys#setslot ht 1 vec2) (restart) )