Use the new BST dictionary for indexing members.

This commit is contained in:
Dominik Pantůček 2023-05-18 14:53:22 +02:00
parent 209ef27a90
commit bebb8af611
4 changed files with 71 additions and 40 deletions

View file

@ -55,6 +55,11 @@
bdict-filter-pairs
bdict-filter-keys
bdict-filter-values
list->bdict
bdict-map-list
bdict-map-dict
bdict-tests!
)
@ -307,6 +312,32 @@
a)))
d))
;; Converts list of pairs into BST dictionary
(define (list->bdict l)
(vector->bdict
(apply vector l)))
;; Returns arbitrary list created by mapping all elements
(define (bdict-map-list d p)
(reverse
(bdict-reduce
'()
(lambda (a k v)
(cons (p k v) a))
d)))
;; Returns new dictionary with all values processed (keys are left
;; intact)
(define (bdict-map-dict d p)
(set-bdict-root
d
(let loop ((n (bdict-root d)))
(if n
(cons (cons (caar n) (p (caar n) (cdar n)))
(cons (loop (cadr n))
(loop (cddr n))))
#f))))
;; Performs module self-tests
(define (bdict-tests!)
(run-tests