utils: Add ht-values:list->set.
This commit is contained in:
parent
ac7ce12a9d
commit
64ca8f4bf1
2 changed files with 11 additions and 2 deletions
|
@ -115,4 +115,6 @@
|
||||||
(let-values ([(e1 l1) (collect-by-key '((1 2) (1 3)) '(a b))]
|
(let-values ([(e1 l1) (collect-by-key '((1 2) (1 3)) '(a b))]
|
||||||
[(e2 l2) (collect-by-key '((1 2) (1 2)) '(a b))])
|
[(e2 l2) (collect-by-key '((1 2) (1 2)) '(a b))])
|
||||||
(check-equal? e1 '((1 2) (1 3))) (check-equal? l1 '((a) (b)))
|
(check-equal? e1 '((1 2) (1 3))) (check-equal? l1 '((a) (b)))
|
||||||
(check-equal? e2 '((1 2))) (check-equal? l2 '((b a)))))
|
(check-equal? e2 '((1 2))) (check-equal? l2 '((b a))))
|
||||||
|
(check-equal? (ht-values:list->set #hash((a . (1 1))))
|
||||||
|
(hash 'a (set 1))))
|
||||||
|
|
|
@ -25,7 +25,9 @@
|
||||||
#:e-func (-> any/c any/c))
|
#:e-func (-> any/c any/c))
|
||||||
graph?)]
|
graph?)]
|
||||||
[pretty-print-set (-> generic-set? string?)]
|
[pretty-print-set (-> generic-set? string?)]
|
||||||
[collect-by-key (-> (listof any/c) (listof any/c) (values (listof any/c) (listof any/c)))])
|
[collect-by-key (-> (listof any/c) (listof any/c) (values (listof any/c) (listof any/c)))]
|
||||||
|
|
||||||
|
[ht-values:list->set (-> (hash/c any/c (listof any/c)) (hash/c any/c (set/c any/c)))])
|
||||||
;; Contracts
|
;; Contracts
|
||||||
(contract-out [variable-mapping? contract?]
|
(contract-out [variable-mapping? contract?]
|
||||||
[string-variable-mapping? contract?]
|
[string-variable-mapping? contract?]
|
||||||
|
@ -277,3 +279,8 @@
|
||||||
#:result (values (hash-keys ht) (hash-values ht)))
|
#:result (values (hash-keys ht) (hash-values ht)))
|
||||||
([e edges] [l labels])
|
([e edges] [l labels])
|
||||||
(hash-update ht e (λ (ls) (cons l ls)) empty)))
|
(hash-update ht e (λ (ls) (cons l ls)) empty)))
|
||||||
|
|
||||||
|
;;; Converts the values of a hash table from lists to sets.
|
||||||
|
(define (ht-values:list->set ht)
|
||||||
|
(for/hash ([(k v) (in-hash ht)])
|
||||||
|
(values k (list->set v))))
|
||||||
|
|
Loading…
Reference in a new issue