Start reimplementing missing ldict through bst.
This commit is contained in:
parent
33fadab5e7
commit
f5e7dfe055
3 changed files with 22 additions and 0 deletions
|
@ -562,6 +562,15 @@ Functional update with optional default value (defaults to #f).
|
||||||
Returns a BST with only KV pairs matching the predicate which must
|
Returns a BST with only KV pairs matching the predicate which must
|
||||||
accept two arguments.
|
accept two arguments.
|
||||||
|
|
||||||
|
### bst-reduce [procedure]
|
||||||
|
|
||||||
|
(bst-reduce bst
|
||||||
|
proc
|
||||||
|
init)
|
||||||
|
|
||||||
|
Like generic reduce, the proc gets accumulator, key and value
|
||||||
|
arguments.
|
||||||
|
|
||||||
## util-bst-bdict [module]
|
## util-bst-bdict [module]
|
||||||
|
|
||||||
(import util-bst-bdict)
|
(import util-bst-bdict)
|
||||||
|
|
|
@ -45,4 +45,7 @@
|
||||||
(define (ldict-filter pred? ld)
|
(define (ldict-filter pred? ld)
|
||||||
(bst-filter ld pred?))
|
(bst-filter ld pred?))
|
||||||
|
|
||||||
|
(define (ldict-reduce init proc ld)
|
||||||
|
(bst-reduce ld proc init))
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
bst-update
|
bst-update
|
||||||
|
|
||||||
bst-filter
|
bst-filter
|
||||||
|
bst-reduce
|
||||||
|
|
||||||
util-bst-tests!
|
util-bst-tests!
|
||||||
)
|
)
|
||||||
|
@ -385,6 +386,15 @@ accept two arguments.")
|
||||||
(cons (apply vector (bst-filter-pairs bst pred?))
|
(cons (apply vector (bst-filter-pairs bst pred?))
|
||||||
(cddr bst)))))
|
(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
|
;; Module self-tests
|
||||||
(define (util-bst-tests!)
|
(define (util-bst-tests!)
|
||||||
(run-tests
|
(run-tests
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue