lookup
This commit is contained in:
parent
fe7f5fcd6e
commit
133c18551a
|
@ -69,16 +69,18 @@
|
||||||
[(list 'no-match node partial-key visited)
|
[(list 'no-match node partial-key visited)
|
||||||
(insert-node! node partial-key)]))
|
(insert-node! node partial-key)]))
|
||||||
|
|
||||||
(define (rt-lookup node key)
|
(define (rt-lookup node key failure-result)
|
||||||
(define (find-first-with-data nodes)
|
(define (find-first-with-data nodes)
|
||||||
(for/first ([node nodes]
|
(or (for/first ([node (in-list nodes)]
|
||||||
#:when (not (eq? empty-node-data (rt-node-data node))))
|
#:when (not (eq? empty-node-data (rt-node-data node))))
|
||||||
(rt-node-data node)))
|
(rt-node-data node))
|
||||||
|
(failure-result)))
|
||||||
|
(find-first-with-data
|
||||||
(match (rt-partial-iterate node key)
|
(match (rt-partial-iterate node key)
|
||||||
[(list 'exact node)
|
[(list 'exact node)
|
||||||
(let ([d (rt-node-data node)])
|
(list node)]
|
||||||
(if (eq? empty-node-data d) #f d))]
|
[(list _ ... visited)
|
||||||
[(list sym . rst) (find-first-with-data (last rst))]))
|
visited])))
|
||||||
|
|
||||||
; (define test (make-rt))
|
; (define test (make-rt))
|
||||||
; (define (test-insert! x)
|
; (define (test-insert! x)
|
||||||
|
@ -103,4 +105,4 @@
|
||||||
(when edge1
|
(when edge1
|
||||||
(displayln (format "~a edge1 ~a" prefix (rt-edge-label edge1)))
|
(displayln (format "~a edge1 ~a" prefix (rt-edge-label edge1)))
|
||||||
(rt-dump (rt-edge-target edge1) (string-append prefix " "))))
|
(rt-dump (rt-edge-target edge1) (string-append prefix " "))))
|
||||||
(rt-dump test)
|
;(rt-dump test)
|
||||||
|
|
Loading…
Reference in New Issue