alist-to-treap

This commit is contained in:
Tony Garnock-Jones 2016-03-10 18:24:40 +00:00
parent ed2b5fed0e
commit 8cf886461e
1 changed files with 5 additions and 0 deletions

View File

@ -19,6 +19,7 @@
treap-keys
treap-values
treap-fold
alist-to-treap
treap-to-alist
treap-has-key?
@ -196,6 +197,10 @@
[(L) acc]
[(N k v _ left right) (walk left (f (walk right acc) k v))])))
(define (alist-to-treap order pairs)
(for/fold [(t (treap-empty order))] [(p (in-list pairs))]
(treap-insert t (car p) (cdr p))))
(define (treap-to-alist t)
(let walk ((n (treap-root t)) (acc '()))
(match n