Start implementing symbol ldict.
This commit is contained in:
parent
0bcc49f99e
commit
33fadab5e7
3 changed files with 66 additions and 0 deletions
48
src/util-bst-ldict.scm
Normal file
48
src/util-bst-ldict.scm
Normal file
|
@ -0,0 +1,48 @@
|
|||
|
||||
(declare (unit util-bst-ldict))
|
||||
|
||||
(import duck)
|
||||
|
||||
(module*
|
||||
util-bst-ldict
|
||||
#:doc ("xxx")
|
||||
(
|
||||
)
|
||||
|
||||
(import scheme
|
||||
util-bst)
|
||||
|
||||
(define (symbol<? a b)
|
||||
(string<? (symbol->string a)
|
||||
(symbol->string b)))
|
||||
|
||||
(define (make-ldict)
|
||||
(make-bst 'symbol eq? symbol<?))
|
||||
|
||||
(define ldict? (bst? 'symbol))
|
||||
|
||||
(define ldict-empty? bst-empty?)
|
||||
(define ldict-contains? bst-contains?)
|
||||
(define ldict-ref bst-ref)
|
||||
(define ldict-remove bst-remove)
|
||||
(define ldict-set bst-set)
|
||||
(define ldict-keys bst-keys)
|
||||
|
||||
(define (ldict-map proc ld)
|
||||
(let ((i 0)
|
||||
(both? ((procedure-arity>=? 2) proc))
|
||||
(index? ((procedure-arity=>? 3) proc)))
|
||||
(bst-map-bst ld
|
||||
(lambda (k v)
|
||||
(let ((r (if both?
|
||||
(if index?
|
||||
(proc k v i)
|
||||
(proc k v))
|
||||
(proc v))))
|
||||
(set! i (add1 i))
|
||||
r)))))
|
||||
|
||||
(define (ldict-filter pred? ld)
|
||||
(bst-filter ld pred?))
|
||||
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue