Implement the whole ldict constructor.
This commit is contained in:
parent
979615ddfd
commit
a0e0c33d56
1 changed files with 21 additions and 6 deletions
|
@ -25,14 +25,29 @@
|
||||||
util-bst
|
util-bst
|
||||||
util-proc)
|
util-proc)
|
||||||
|
|
||||||
(define (symbol<? a b)
|
(define (ldict<? a b)
|
||||||
(string<? (symbol->string a)
|
(if (number? a)
|
||||||
(symbol->string b)))
|
(< a b)
|
||||||
|
(string<? (symbol->string a)
|
||||||
|
(symbol->string b))))
|
||||||
|
|
||||||
(define (make-ldict)
|
(define (make-ldict . equality?/pairs)
|
||||||
(make-bst 'symbol eq? symbol<?))
|
(let ((equality? (if (or (null? equality?/pairs)
|
||||||
|
(not (procedure? (car equality?/pairs))))
|
||||||
|
eq?
|
||||||
|
(car equality?/pairs)))
|
||||||
|
(pairs (if (or (null? equality?/pairs)
|
||||||
|
(procedure? (car equality?/pairs)))
|
||||||
|
'()
|
||||||
|
(car equality?/pairs))))
|
||||||
|
(let loop ((ld (make-bst 'ldict equality? ldict<?))
|
||||||
|
(pairs pairs))
|
||||||
|
(if (null? pairs)
|
||||||
|
ld
|
||||||
|
(loop (ldict-set ld (caar pairs) (cdar pairs))
|
||||||
|
(cdr pairs))))))
|
||||||
|
|
||||||
(define ldict? (bst? 'symbol))
|
(define ldict? (bst? 'ldict))
|
||||||
|
|
||||||
(define ldict-empty? bst-empty?)
|
(define ldict-empty? bst-empty?)
|
||||||
(define ldict-contains? bst-contains?)
|
(define ldict-contains? bst-contains?)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue