Fix rt-lookup lol
This commit is contained in:
parent
c9b6e44fc7
commit
0ee1393fd6
|
@ -60,8 +60,11 @@
|
||||||
(subnet-mask sub)))
|
(subnet-mask sub)))
|
||||||
|
|
||||||
(define (subnet->bl sub)
|
(define (subnet->bl sub)
|
||||||
(for/list ([i (in-range (subnet-mask sub))])
|
(ip->bl (subnet-ip sub) (subnet-mask sub)))
|
||||||
(= 1 (bitwise-and 1 (arithmetic-shift (subnet-ip sub) (- i 31))))))
|
|
||||||
|
(define (ip->bl ip [bits 32])
|
||||||
|
(for/list ([i (in-range bits)])
|
||||||
|
(= 1 (bitwise-and 1 (arithmetic-shift ip (- i 31))))))
|
||||||
|
|
||||||
(define (string->peer str)
|
(define (string->peer str)
|
||||||
(match-define (list ip type) (string-split str "-"))
|
(match-define (list ip type) (string-split str "-"))
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#:break (not (equal? b1 b2))
|
#:break (not (equal? b1 b2))
|
||||||
1))
|
1))
|
||||||
|
|
||||||
(define (rt-partial-iterate node key)
|
(define (rt-partial-iterate node key [visited '()])
|
||||||
(cond
|
(cond
|
||||||
[(empty? key) (list 'exact node)]
|
[(empty? key) (list 'exact node)]
|
||||||
[else
|
[else
|
||||||
|
@ -34,9 +34,9 @@
|
||||||
[next-common-len (and next-label (bl-common-len next-label key))])
|
[next-common-len (and next-label (bl-common-len next-label key))])
|
||||||
(cond
|
(cond
|
||||||
[(and next-edge (= next-common-len (length next-label)))
|
[(and next-edge (= next-common-len (length next-label)))
|
||||||
(rt-partial-iterate next-target (drop key next-common-len))]
|
(rt-partial-iterate next-target (drop key next-common-len) (cons node visited))]
|
||||||
[next-edge (list 'partial node next-edge next-common-len key)]
|
[next-edge (list 'partial node next-edge next-common-len key (cons node visited))]
|
||||||
[else (list 'no-match node key)]))]))
|
[else (list 'no-match node key (cons node visited))]))]))
|
||||||
|
|
||||||
(define (rt-update! node key updater failure-result)
|
(define (rt-update! node key updater failure-result)
|
||||||
(define (insert-node! node key)
|
(define (insert-node! node key)
|
||||||
|
@ -64,15 +64,21 @@
|
||||||
(let ([d (rt-node-data node)])
|
(let ([d (rt-node-data node)])
|
||||||
(updater
|
(updater
|
||||||
(if (eq? d empty-node-data) (failure-result) d))))]
|
(if (eq? d empty-node-data) (failure-result) d))))]
|
||||||
[(list 'partial node orig-edge prefix-len partial-key)
|
[(list 'partial node orig-edge prefix-len partial-key visited)
|
||||||
(split-node! node partial-key orig-edge prefix-len)]
|
(split-node! node partial-key orig-edge prefix-len)]
|
||||||
[(list 'no-match node partial-key)
|
[(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)
|
||||||
|
(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)
|
(match (rt-partial-iterate node key)
|
||||||
[(list 'exact node) (rt-node-data node)]
|
[(list 'exact node)
|
||||||
[_ #f]))
|
(let ([d (rt-node-data node)])
|
||||||
|
(if (eq? empty-node-data d) #f d))]
|
||||||
|
[(list sym . rst) (find-first-with-data (last rst))]))
|
||||||
|
|
||||||
; (define test (make-rt))
|
; (define test (make-rt))
|
||||||
; (define (test-insert! x)
|
; (define (test-insert! x)
|
||||||
|
|
Loading…
Reference in New Issue