From 133c18551a26af8f53bdbaa34e836adcd7cc9c46 Mon Sep 17 00:00:00 2001 From: Milo Date: Fri, 31 Jan 2020 22:22:00 -0500 Subject: [PATCH] lookup --- radix-tree.rkt | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/radix-tree.rkt b/radix-tree.rkt index e23ea40..679fdcb 100644 --- a/radix-tree.rkt +++ b/radix-tree.rkt @@ -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)