This commit is contained in:
Milo 2020-01-31 22:22:00 -05:00
parent fe7f5fcd6e
commit 133c18551a
1 changed files with 12 additions and 10 deletions

View File

@ -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]
(or (for/first ([node (in-list nodes)]
#: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)
[(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))]))
(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)