removed unstable/dict (no uses)

This commit is contained in:
Ryan Culpepper 2011-12-17 21:32:00 -07:00
parent 4f9da1fd1c
commit 53fc18008c
5 changed files with 0 additions and 181 deletions

View File

@ -1,32 +0,0 @@
#lang racket
(require rackunit rackunit/text-ui unstable/dict "helpers.rkt")
(define (dict=? a b)
(and (subdict? a b)
(subdict? b a)))
(define (subdict? a b)
(for/and ([(k v) (in-dict a)])
(and (dict-has-key? b k)
(equal? (dict-ref b k) v))))
(define (check/dict a b) (check dict=? a b))
(run-tests
(test-suite "dict.rkt"
(test-suite "Accessors"
(test-suite "dict-empty?"
(test (check-true (dict-empty? '())))
(test (check-false (dict-empty? '([1 . a] [2 . b]))))))
(test-suite "Combination"
(test-suite "dict-union"
(test-ok (dict-union '([1 . one] [2 . two]) '([3 . three] [4 . four]))
'([4 . four] [3 . three] [1 . one] [2 . two])))
(test-suite "dict-union!"
(test-ok (define d (make-hash))
(dict-union! d '([1 . one] [2 . two]))
(dict-union! d '([3 . three] [4 . four]))
(check-equal?
(hash-copy #hash([1 . one] [2 . two] [3 . three] [4 . four]))
d))))))

View File

@ -1,64 +0,0 @@
#lang racket/base
(require racket/dict
racket/contract/base)
(define (dict-empty? dict)
(not (dict-iterate-first dict)))
;; Eli: This encourages ignoring the actual representation, and the fact
;; that `dict-count' can in some cases be an O(N) operation. (And to
;; make things worse, it's not even mentioned in the docs.)
;; Ryan: Fixed complexity.
(define ((dict-duplicate-error name) key value1 value2)
(error name "duplicate values for key ~e: ~e and ~e" key value1 value2))
;; Eli: If this is useful, then at least make it worth using instead of
;; writing your own code. For example, inspect the arguments and choose
;; an efficient order for the loops, or use a temporary hash table for a
;; union of two alists, etc. Alternatively, just write a function for
;; merging two hash tables (and call it `hash-union', of course).
;; Ryan: I prefer the names dict-add-all and dict-add-all!---no connotations
;; of symmetry, and it makes it clear that the first argument determines the
;; representation (and key constraints, etc).
(define (dict-union
#:combine [combine #f]
#:combine/key [combine/key
(if combine
(lambda (k x y) (combine x y))
(dict-duplicate-error 'dict-union))]
one . rest)
(for*/fold ([one one]) ([two (in-list rest)] [(k v) (in-dict two)])
(dict-set one k (if (dict-has-key? one k)
(combine/key k (dict-ref one k) v)
v))))
(define (dict-union!
#:combine [combine #f]
#:combine/key [combine/key
(if combine
(lambda (k x y) (combine x y))
(dict-duplicate-error 'dict-union))]
one . rest)
(for* ([two (in-list rest)] [(k v) (in-dict two)])
(dict-set! one k (if (dict-has-key? one k)
(combine/key k (dict-ref one k) v)
v))))
(provide/contract
[dict-empty? (-> dict? boolean?)]
[dict-union (->* [(and/c dict? dict-can-functional-set?)]
[#:combine
(-> any/c any/c any/c)
#:combine/key
(-> any/c any/c any/c any/c)]
#:rest (listof dict?)
(and/c dict? dict-can-functional-set?))]
[dict-union! (->* [(and/c dict? dict-mutable?)]
[#:combine
(-> any/c any/c any/c)
#:combine/key
(-> any/c any/c any/c any/c)]
#:rest (listof dict?)
void?)])

View File

@ -1,83 +0,0 @@
#lang scribble/manual
@(require scribble/eval "utils.rkt" (for-label racket unstable/dict))
@(define the-eval (make-base-eval))
@(the-eval '(require racket/dict unstable/dict))
@title{Dictionaries}
@defmodule[unstable/dict]
@unstable[@author+email["Carl Eastlund" "cce@racket-lang.org"]]
This module provides tools for manipulating dictionary values.
@defproc[(dict-empty? [d dict?]) boolean?]{
Reports whether @racket[d] is empty (has no keys).
@defexamples[
#:eval the-eval
(dict-empty? '())
(dict-empty? '([1 . one] [2 . two]))
]
}
@defproc[(dict-union [d0 (and/c dict? dict-can-functional-set?)]
[d dict?] ...
[#:combine combine
(-> any/c any/c any/c)
(lambda _ (error 'dict-union ...))]
[#:combine/key combine/key
(-> any/c any/c any/c any/c)
(lambda (k a b) (combine a b))])
(and/c dict? dict-can-functional-set?)]{
Computes the union of @racket[d0] with each dictionary @racket[d] by functional
update, adding each element of each @racket[d] to @racket[d0] in turn. For each
key @racket[k] and value @racket[v], if a mapping from @racket[k] to some value
@racket[v0] already exists, it is replaced with a mapping from @racket[k] to
@racket[(combine/key k v0 v)].
@defexamples[
#:eval the-eval
(dict-union '([1 . one]) '([2 . two]) '([3 . three]))
(dict-union '([1 . (one uno)] [2 . (two dos)])
'([1 . (ein une)] [2 . (zwei deux)])
#:combine/key (lambda (k v1 v2) (append v1 v2)))
]
}
@defproc[(dict-union! [d0 (and/c dict? dict-mutable?)]
[d dict?] ...
[#:combine combine
(-> any/c any/c any/c)
(lambda _ (error 'dict-union! ...))]
[#:combine/key combine/key
(-> any/c any/c any/c any/c)
(lambda (k a b) (combine a b))])
void?]{
Computes the union of @racket[d0] with each dictionary @racket[d] by mutable
update, adding each element of each @racket[d] to @racket[d0] in turn. For each
key @racket[k] and value @racket[v], if a mapping from @racket[k] to some value
@racket[v0] already exists, it is replaced with a mapping from @racket[k] to
@racket[(combine/key k v0 v)].
@defexamples[
#:eval the-eval
(define d (make-hash))
d
(dict-union! d '([1 . (one uno)] [2 . (two dos)]))
d
(dict-union! d
'([1 . (ein une)] [2 . (zwei deux)])
#:combine/key (lambda (k v1 v2) (append v1 v2)))
d
]
}
@(close-eval the-eval)

View File

@ -78,7 +78,6 @@ Keep documentation and tests up to date.
@include-section["prop-contract.scrbl"]
@include-section["debug.scrbl"]
@include-section["define.scrbl"]
@include-section["dict.scrbl"]
@include-section["exn.scrbl"]
@include-section["file.scrbl"]
@include-section["find.scrbl"]

View File

@ -20,7 +20,6 @@
(check-docs (quote unstable/find))
(check-docs (quote unstable/file))
(check-docs (quote unstable/exn))
(check-docs (quote unstable/dict))
(check-docs (quote unstable/debug))
(check-docs (quote unstable/contract))
(check-docs (quote unstable/class-iop))