#lang mzscheme
(require scheme/contract
(file "base.ss")
(file "list.ss"))
(define (make-hash-table/pairs . pairs)
(let ([table (make-hash-table)])
(alist-for-each
(lambda (key value)
(hash-table-put! table key value))
pairs)
table))
(define (hash-table-mapped? table key)
(with-handlers ([exn:unlib? (lambda (exn) #f)])
(hash-table-get table key (lambda () (raise-exn exn:unlib "Not found.")))
#t))
(define (hash-table-keys table)
(hash-table-map table (lambda (k v) k)))
(define (hash-table-values table)
(hash-table-map table (lambda (k v) v)))
(provide/contract
[make-hash-table/pairs (->* () () #:rest (listof pair?) hash-table?)]
[hash-table-mapped? (-> hash-table? any/c boolean?)]
[hash-table-keys (-> hash-table? (or/c pair? null?))]
[hash-table-values (-> hash-table? (or/c pair? null?))])