Start reimplementing missing ldict through bst.

This commit is contained in:
Dominik Pantůček 2023-07-07 11:26:53 +02:00
parent 33fadab5e7
commit f5e7dfe055
3 changed files with 22 additions and 0 deletions

View file

@ -45,4 +45,7 @@
(define (ldict-filter pred? ld)
(bst-filter ld pred?))
(define (ldict-reduce init proc ld)
(bst-reduce ld proc init))
)

View file

@ -36,6 +36,7 @@
bst-update
bst-filter
bst-reduce
util-bst-tests!
)
@ -385,6 +386,15 @@ accept two arguments.")
(cons (apply vector (bst-filter-pairs bst pred?))
(cddr bst)))))
(define/doc (bst-reduce bst proc init)
("Like generic reduce, the proc gets accumulator, key and value
arguments.")
(let ((acc init))
(bst-iter-kv bst
(lambda (kv)
(set! acc (proc acc (car kv) (cdr kv)))))
acc))
;; Module self-tests
(define (util-bst-tests!)
(run-tests