Implement missing list->bst.
This commit is contained in:
parent
6999664aa1
commit
6d7639e56d
1 changed files with 13 additions and 0 deletions
|
@ -32,11 +32,14 @@
|
||||||
bst-map-list
|
bst-map-list
|
||||||
bst-map-dict
|
bst-map-dict
|
||||||
|
|
||||||
|
list->bst
|
||||||
|
|
||||||
util-bst-tests!
|
util-bst-tests!
|
||||||
)
|
)
|
||||||
|
|
||||||
(import scheme
|
(import scheme
|
||||||
(chicken condition)
|
(chicken condition)
|
||||||
|
(chicken sort)
|
||||||
util-tag
|
util-tag
|
||||||
testing)
|
testing)
|
||||||
|
|
||||||
|
@ -334,6 +337,16 @@
|
||||||
(loop (cddr n))))
|
(loop (cddr n))))
|
||||||
#f))))
|
#f))))
|
||||||
|
|
||||||
|
(define/doc (list->bst lst subtag EQ? <?)
|
||||||
|
("Converts list of pairs into BST dictionary.")
|
||||||
|
(kvv->bst
|
||||||
|
(cons TAG-KVV
|
||||||
|
(cons (list->vector
|
||||||
|
(sort lst (lambda (akv bkv)
|
||||||
|
(<? (car akv) (car bkv)))))
|
||||||
|
(cons subtag
|
||||||
|
(cons EQ? <?))))))
|
||||||
|
|
||||||
;; 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