Export treap-order; add treap->empty and treap-fold.

This commit is contained in:
Tony Garnock-Jones 2015-06-19 20:08:16 -04:00
parent 76eaa2fa39
commit 29bbe7678b
1 changed files with 11 additions and 0 deletions

View File

@ -8,14 +8,17 @@
;; Further, we explicitly canonicalize N instances, so eq? works to compare treaps by value.
(provide treap?
treap-order
treap-size
treap-empty
treap-empty?
treap->empty
treap-insert
treap-delete
treap-get
treap-keys
treap-values
treap-fold
treap-to-alist
treap-has-key?
@ -63,6 +66,8 @@
(define (treap-empty? t) (zero? (treap-size t)))
(define (treap->empty t) (treap-empty (treap-order t)))
(define (default-priority key)
;; Loosely based on a restriction of murmur32 v3
(define c1 #xcc9e2d51)
@ -185,6 +190,12 @@
[(L) acc]
[(N k _ _ left right) (walk left (cons k (walk right acc)))])))
(define (treap-fold t f seed)
(let walk ((n (treap-root t)) (acc seed))
(match n
[(L) acc]
[(N k v _ left right) (walk left (f (walk right acc) k v))])))
(define (treap-to-alist t)
(let walk ((n (treap-root t)) (acc '()))
(match n