diff --git a/prospect/treap.rkt b/prospect/treap.rkt index 70efa7d..7478f81 100644 --- a/prospect/treap.rkt +++ b/prospect/treap.rkt @@ -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