aboutsummaryrefslogtreecommitdiffstats
path: root/mcgoron.weight-balanced-trees.internal.scm
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2025-01-16 23:28:26 -0500
committerGravatar Peter McGoron 2025-01-16 23:28:26 -0500
commit76907b11b323e515c839bd14c2b5c6cc51a1dc5b (patch)
tree7cc26af2539d65c494a8ec4f3dccd2a7db55ea4c /mcgoron.weight-balanced-trees.internal.scm
parentsplit and search (diff)
add a generating thunk for split
Diffstat (limited to 'mcgoron.weight-balanced-trees.internal.scm')
-rw-r--r--mcgoron.weight-balanced-trees.internal.scm10
1 files changed, 6 insertions, 4 deletions
diff --git a/mcgoron.weight-balanced-trees.internal.scm b/mcgoron.weight-balanced-trees.internal.scm
index c657178..99be0bc 100644
--- a/mcgoron.weight-balanced-trees.internal.scm
+++ b/mcgoron.weight-balanced-trees.internal.scm
@@ -18,6 +18,7 @@
(left get-left)
(right get-right))
+(: wb-tree-node? (* -> boolean : node-type))
(define (wb-tree-node? x)
(or (null? x) (non-null-wb-tree-node? x)))
@@ -239,16 +240,16 @@
;;; XXX: The comparator library does not export the struct type for
;;; the comparator.
-(: split (* node-type * --> node-type boolean node-type))
-(define (split cmp tree key)
+(: split (* node-type * (-> *) --> node-type * node-type))
+(define (split cmp tree key default)
(let split ((tree tree))
(if (null? tree)
- (values '() #f '())
+ (values '() (default) '())
(with-node (tree data ("<" left) (">" right))
(comparator-if<=> cmp key data
(let-values (((new-left bool new-right) (split left)))
(values new-left bool (join data new-right right)))
- (values left #t right)
+ (values left data right)
(let-values (((new-left bool new-right) (split right)))
(values (join data left new-left) bool new-right)))))))
@@ -265,3 +266,4 @@
data
(search right))))))))
+