From c0f2b15d899203f97905482072637e7dce49ec2e Mon Sep 17 00:00:00 2001 From: erana Date: Sat, 21 Jan 2012 15:29:30 +0900 Subject: [PATCH] xanadu - btree --- scsh/xanadu/b-tree.scm | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/scsh/xanadu/b-tree.scm b/scsh/xanadu/b-tree.scm index 06d10fd..50a99ca 100644 --- a/scsh/xanadu/b-tree.scm +++ b/scsh/xanadu/b-tree.scm @@ -81,13 +81,17 @@ (make-vector n-ary (make-b-tree-node #f #f))))) (define (vector-median v) + (display "median:");;(display v) (let ((len (ceiling (/ (vector-length v) 2)))) - (let ((retl (make-vector len)) - (retr (if (odd? len) (make-vector (- len 1)) (make-vector len)))) + (let ((retl (make-vector len (make-b-tree-node #f #f))) + (retr (if (odd? len) + (make-vector (+ len 1) (make-b-tree-node #f #f)) + (make-vector len (make-b-tree-node #f #f))))) (do ((i 0 (+ i 1))) - ((= i len) (list retl retr)) + ((= i len) (display "returned")(list retl retr)) + (display i) (vector-set! retl i (vector-ref v i)) - (vector-set! retr (- len (- i 1)) (vector-ref v (- len (- i 1)))) + (vector-set! retr (- len (+ i 1)) (vector-ref v (- len (+ i 1)))) )))) @@ -136,14 +140,14 @@ (not (((vector-ref lefttree i) 'get-data))) (string=? (((vector-ref lefttree i) 'get-data)) "")) (display 'FOO1) - (let ((lr (vector-median lefttree))) + (let ((lr (vector-median ((lefttree 'get-left)))));;FIXME right also descend (let ((new-node (make-b-tree-node (car lr) (cadr lr))));;FIXME lenght mustbe n-ary ((new-node 'set-data!) str) (vector-set! lefttree i new-node) ))) ((and (string? str (((vector-ref lefttree (+ i 1)) 'get-data)))) - (let ((lr (vector-median lefttree))) + (let ((lr (vector-median ((lefttree 'get-left))))) (let ((new-node (make-b-tree-node (car lr) (cadr lr)))) ((new-node 'set-data!) str) (vector-set! lefttree i new-node)