#lang scheme/base
(require "base.ss")
(define make-hash/alist
(cut make-hash/internal make-hash <>))
(define make-hasheq/alist
(cut make-hash/internal make-hasheq <>))
(define make-weak-hash/alist
(cut make-hash/internal make-weak-hash <>))
(define make-weak-hasheq/alist
(cut make-hash/internal make-weak-hasheq <>))
(define (make-hash/internal make-hash alist)
(let ([hash (make-hash)])
(for-each (lambda (item)
(hash-set! hash (car item) (cdr item)))
alist)
hash))
(define (hash-set? hash key)
(and (hash-ref hash key #f) #t))
(define (hash-keys hash)
(hash-map hash (lambda (k v) k)))
(define (hash-values hash)
(hash-map hash (lambda (k v) v)))
(provide/contract
[make-hash/alist (-> (listof pair?) (and/c hash? (not/c hash-eq?) (not/c hash-weak?)))]
[make-hasheq/alist (-> (listof pair?) (and/c hash? hash-eq? (not/c hash-weak?)))]
[make-weak-hash/alist (-> (listof pair?) (and/c hash? (not/c hash-eq?) hash-weak?))]
[make-weak-hasheq/alist (-> (listof pair?) (and/c hash? hash-eq? hash-weak?))]
[hash-set? (-> hash? any/c boolean?)]
[hash-keys (-> hash? (or/c pair? null?))]
[hash-values (-> hash? (or/c pair? null?))])