Add preliminary bdict reimplementation.
This commit is contained in:
parent
6d7639e56d
commit
3a3af066af
3 changed files with 50 additions and 3 deletions
|
@ -55,7 +55,7 @@ HACKERBASE-OBJS=hackerbase.o testing.o listing.o cal-month.o \
|
||||||
table-processor.o table-border.o table-style.o sgr-state.o \
|
table-processor.o table-border.o table-style.o sgr-state.o \
|
||||||
util-utf8.o sgr-cell.o template-list-expander.o \
|
util-utf8.o sgr-cell.o template-list-expander.o \
|
||||||
box-drawing.o util-list.o export-web-static.o util-dir.o \
|
box-drawing.o util-list.o export-web-static.o util-dir.o \
|
||||||
dokuwiki.o racket-kwargs.o duck.o util-bst.o
|
dokuwiki.o racket-kwargs.o duck.o util-bst.o util-bst-dict.o
|
||||||
|
|
||||||
GENDOC-SOURCES=gendoc.scm duck-extract.import.scm \
|
GENDOC-SOURCES=gendoc.scm duck-extract.import.scm \
|
||||||
util-time.import.scm util-csv.import.scm util-git.import.scm \
|
util-time.import.scm util-csv.import.scm util-git.import.scm \
|
||||||
|
@ -522,3 +522,8 @@ UTIL-BST-SOURCES=util-bst.scm util-tag.import.scm testing.import.scm
|
||||||
|
|
||||||
util-bst.o: util-bst.import.scm
|
util-bst.o: util-bst.import.scm
|
||||||
util-bst.import.scm: $(UTIL-BST-SOURCES)
|
util-bst.import.scm: $(UTIL-BST-SOURCES)
|
||||||
|
|
||||||
|
UTIL-BST-DICT-SOURCES=util-bst-dict.scm util-bst.import.scm
|
||||||
|
|
||||||
|
util-bst-dict.o: util-bst-dict.import.scm
|
||||||
|
util-bst-dict.import.scm: $(UTIL-BST-DICT-SOURCES)
|
||||||
|
|
42
src/util-bst-dict.scm
Normal file
42
src/util-bst-dict.scm
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
|
||||||
|
(declare (unit util-bst-dict))
|
||||||
|
|
||||||
|
(import duck)
|
||||||
|
|
||||||
|
(module*
|
||||||
|
util-bst-dict
|
||||||
|
#:doc ("...")
|
||||||
|
(
|
||||||
|
list->bdict
|
||||||
|
bdict-find-value
|
||||||
|
bdict-ref
|
||||||
|
bdict-filter-alues
|
||||||
|
bdict-keys
|
||||||
|
bdict-map-list
|
||||||
|
bdict-map-dict
|
||||||
|
)
|
||||||
|
|
||||||
|
(import scheme
|
||||||
|
util-bst)
|
||||||
|
|
||||||
|
(define (list->bdict lst)
|
||||||
|
(list->bst lst 'fixnum eq? <))
|
||||||
|
|
||||||
|
(define (bdict-find-value d p?)
|
||||||
|
(let ((kv (bst-find-pair d p?)))
|
||||||
|
(if kv
|
||||||
|
(cdr kv)
|
||||||
|
#f)))
|
||||||
|
|
||||||
|
(define bdict-ref bst-ref)
|
||||||
|
|
||||||
|
(define (bdict-filter-values d p?)
|
||||||
|
(map cdr (bst-filter-pairs d p?)))
|
||||||
|
|
||||||
|
(define bdict-keys bst-keys)
|
||||||
|
|
||||||
|
(define bdict-map-list bst-map-list)
|
||||||
|
|
||||||
|
(define bdict-map-dict bst-map-bst)
|
||||||
|
|
||||||
|
)
|
|
@ -30,7 +30,7 @@
|
||||||
bst-filter-pairs
|
bst-filter-pairs
|
||||||
|
|
||||||
bst-map-list
|
bst-map-list
|
||||||
bst-map-dict
|
bst-map-bst
|
||||||
|
|
||||||
list->bst
|
list->bst
|
||||||
|
|
||||||
|
@ -327,7 +327,7 @@
|
||||||
(proc (car kv) (cdr kv))))))
|
(proc (car kv) (cdr kv))))))
|
||||||
(reverse res)))
|
(reverse res)))
|
||||||
|
|
||||||
(define/doc (bst-map-dict bst proc)
|
(define/doc (bst-map-bst bst proc)
|
||||||
("Returns a new dictionary with all values processed (keys are left intact).")
|
("Returns a new dictionary with all values processed (keys are left intact).")
|
||||||
(set-bst-root bst
|
(set-bst-root bst
|
||||||
(let loop ((n (bst-root bst)))
|
(let loop ((n (bst-root bst)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue