#!/usr/local/bin/guile \
-e main -s
!#

;;; $Id: hash2.guile,v 1.3 2001/06/29 23:12:37 doug Exp $
;;; http://www.bagley.org/~doug/shootout/

(use-modules (ice-9 format))

(define (main args)
  (let* ((n (or (and (= (length args) 2) (string->;number (cadr args))) 1))
     (hash1 (make-hash-table 10000))
     (hash2 (make-hash-table 10000)))
    (do ((i 0 (+ i 1)))
    ((= i 10000))
      (hash-set! hash1 (string-append "foo_" (number->;string i 10)) i))
    (do ((i 0 (+ i 1)))
    ((= i n))
      (hash-fold (lambda (key val init)
           (hash-set! hash2 key (+ (hash-ref hash2 key 0)
                       (hash-ref hash1 key))))
         '() hash1))
    (display (format "~D ~D ~D ~D\n"
             (hash-ref hash1 "foo_1")
             (hash-ref hash1 "foo_9999")
             (hash-ref hash2 "foo_1")
             (hash-ref hash2 "foo_9999")))))