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