diff --git a/collects/racket/private/hash.rkt b/collects/racket/private/hash.rkt index 9fbad522c2..dbaf0ba16c 100644 --- a/collects/racket/private/hash.rkt +++ b/collects/racket/private/hash.rkt @@ -1,10 +1,13 @@ (module hash "pre-base.rkt" (define (hash-domain table) - (for/list ([i (in-hash-keys table)]) i)) + (hash-map table (λ (k v) k))) (define (hash-range table) - (for/list ([i (in-hash-values table)]) i)) + (hash-map table (λ (k v) v))) + + (define (hash->list table) + (hash-map table cons)) (provide hash-domain - hash-range) - ) \ No newline at end of file + hash-range + hash->list)) \ No newline at end of file diff --git a/collects/scribblings/reference/hashes.scrbl b/collects/scribblings/reference/hashes.scrbl index b7a8a2398e..6342ababa9 100644 --- a/collects/scribblings/reference/hashes.scrbl +++ b/collects/scribblings/reference/hashes.scrbl @@ -314,6 +314,12 @@ Returns a list of the keys of @scheme[hash] in an unspecified order. (listof any/c)]{ Returns a list of the values of @scheme[hash] in an unspecified order. +@see-also-concurrency-caveat[]} + +@defproc[(hash->list [hash hash?]) + (listof (cons/c any/c any/c))]{ +Returns a list of the key--value pairs of @scheme[hash] in an unspecified order. + @see-also-concurrency-caveat[]} @defproc[(hash-for-each [hash hash?] diff --git a/collects/tests/racket/basic.rktl b/collects/tests/racket/basic.rktl index c97afd5977..831c0daba6 100644 --- a/collects/tests/racket/basic.rktl +++ b/collects/tests/racket/basic.rktl @@ -2365,6 +2365,7 @@ (test (list 1 2 3) hash-domain #hasheq((1 . 'a)(2 . 'b)(3 . 'c))) (test (list 'a 'b 'c) hash-range #hasheq((1 . 'a)(2 . 'b)(3 . 'c))) +(test (list (cons 1 'a) (cons 2 'b) (cons 3 'c)) hash->list #hasheq((1 . 'a)(2 . 'b)(3 . 'c))) (arity-test make-immutable-hash 1 1) (arity-test make-immutable-hasheq 1 1) diff --git a/collects/tests/unstable/hash.rkt b/collects/tests/unstable/hash.rkt index 1501aaec56..507399d67b 100644 --- a/collects/tests/unstable/hash.rkt +++ b/collects/tests/unstable/hash.rkt @@ -4,10 +4,6 @@ (run-tests (test-suite "hash.ss" - (test-suite "hash-equal?" - (test (check-true (hash-equal? #hash()))) - (test (check-false (hash-equal? #hasheq()))) - (test (check-false (hash-equal? #hasheqv())))) (test-suite "hash-ref/check" (test-ok (check-equal? (hash-ref/check #hash([1 . one] [2 . two]) 1) 'one)) @@ -31,14 +27,6 @@ (check-equal? (hash-ref/failure #hash([1 . one] [2 . two]) 3 f) 8) (check-equal? x 8))) - (test-suite "hash-has-key?" - (test-ok (check-equal? (hash-has-key? #hash([1 . one] [2 . two]) 1) #t)) - (test-ok (check-equal? (hash-has-key? #hash([1 . one] [2 . two]) 3) #f))) - (test-suite "hash-domain" - (test-ok (check-equal? (hash-domain #hash([1 . one] [2 . two])) '(1 2)))) - (test-suite "hash-range" - (test-ok (check-equal? (hash-range #hash([1 . one] [2 . two])) - '(one two)))) (test-suite "hash-union" (test-ok (hash-union #hash([1 . one] [2 . two]) #hash([3 . three] [4 . four])) diff --git a/collects/unstable/scribblings/hash.scrbl b/collects/unstable/scribblings/hash.scrbl index 624bcb1e75..921fd0ee91 100644 --- a/collects/unstable/scribblings/hash.scrbl +++ b/collects/unstable/scribblings/hash.scrbl @@ -67,57 +67,6 @@ applying @scheme[f] (in tail position) if @scheme[h] has no entry for } -@section{Hash Table Accessors} - -@defproc[(hash-equal? [h hash?]) boolean?]{ - -Reports whether @scheme[h] maps keys according to @scheme[equal?]. - -@defexamples[ -#:eval (eval/require 'unstable/hash) -(hash-equal? #hash()) -(hash-equal? #hasheq()) -(hash-equal? #hasheqv()) -] - -} - -@defproc[(hash-has-key? [h hash?] [k any/c]) boolean?]{ - -Reports whether @scheme[h] has an entry for @scheme[k]. This function is -re-exported from @schememodname[scheme/base]. In versions of Racket before -@scheme[hash-has-key?] was implemented, this module provides its own definition. - -@defexamples[ -#:eval (eval/require 'unstable/hash) -(hash-has-key? (make-immutable-hash '([1 . one] [2 . two] [3 . three])) 2) -(hash-has-key? (make-immutable-hash '([1 . one] [2 . two] [3 . three])) 4) -] - -} - -@defproc[(hash-domain [h hash?]) list?]{ - -Produces the domain of a hash table as a list of keys. - -@defexamples[ -#:eval (eval/require 'unstable/hash) -(hash-domain (make-immutable-hash '([1 . one] [2 . two] [3 . three]))) -] - -} - -@defproc[(hash-range [h hash?]) list?]{ - -Produces the range of a hash table as a list of values. - -@defexamples[ -#:eval (eval/require 'unstable/hash) -(hash-range (make-immutable-hash '([1 . one] [2 . two] [3 . three]))) -] - -} - @section{Hash Table Combinations} @defproc[(hash-union [h0 (and/c hash? hash-can-functional-set?)]