Changeset 20639 in project
 Timestamp:
 10/04/10 10:00:26 (11 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

release/4/rbtree/trunk/rbtree.scm
r20637 r20639 867 867 868 868 (define (wrap f) 869 (lambda (m1 m2 #!key ( fkeycompare #f))869 (lambda (m1 m2 #!key (k1 identity) (k2 identity)) 870 870 (let ((m1 (m1 'treemap)) 871 871 (m2 (m2 'treemap))) … … 874 874 (t1 (maproot m1)) 875 875 (t2 (maproot m2))) 876 (let ((f1 (f (or fkeycompare insdelkeycompare))))876 (let ((f1 (f k1 k2 insdelkeycompare))) 877 877 (matchlet (((n result) (f1 (start t1) (start t2) 0 (Zero)))) 878 878 (maketreemap n (linkall result) keycompare insdelkeycompare))))))) … … 892 892 893 893 (define (unionwith mergefn) 894 (define (union k eycompare)894 (define (union k1 k2 keycompare) 895 895 (lambda (t1 t2 n result) 896 896 (let recur ((t1 t1) (t2 t2) (n n) (result result)) … … 907 907 908 908 (((($ tree 'Tree _ _ xk x _) r1) (($ tree 'Tree _ _ yk y _) r2)) 909 (let ((c (keycompare xk yk))) 910 (cond ((negative? c) (recur r1 t2 (+ 1 n) (additem xk x result))) 911 ((zero? c) (recur r1 r2 (+ 1 n) (additem xk (mergefn x y) result))) 912 ((positive? c) (recur t1 r2 (+ 1 n) (additem yk y result)))))) 913 909 (let ((xk1 (k1 xk)) (yk1 (k2 yk))) 910 (let ((c (keycompare xk1 yk1))) 911 (cond ((negative? c) (recur r1 t2 (+ 1 n) (additem xk1 x result))) 912 ((zero? c) (recur r1 r2 (+ 1 n) (additem xk1 (mergefn x y) result))) 913 ((positive? c) (recur t1 r2 (+ 1 n) (additem yk1 y result))))))) 914 914 915 )))) 915 916 (wrap union)) … … 917 918 918 919 (define (unionwithi mergefn) 919 (define (union k eycompare)920 (define (union k1 k2 keycompare) 920 921 (lambda (t1 t2 n result) 921 922 (let recur ((t1 t1) (t2 t2) (n n) (result result)) … … 932 933 933 934 (((($ tree 'Tree _ _ xk x _) r1) (($ tree 'Tree_ _ yk y _) r2)) 934 (let ((c (keycompare xk yk))) 935 (cond ((negative? c) (recur r1 t2 (+ 1 n) (additem xk x result))) 936 ((zero? c) (recur r1 r2 (+ 1 n) (additem xk (mergefn xk x y) result))) 937 ((positive? c) (recur t1 r2 (+ 1 n) (additem yk y result)))))) 935 (let ((xk1 (k1 xk)) (yk1 (k2 yk))) 936 (let ((c (keycompare xk1 yk1))) 937 (cond ((negative? c) (recur r1 t2 (+ 1 n) (additem xk1 x result))) 938 ((zero? c) (recur r1 r2 (+ 1 n) (additem xk1 (mergefn xk1 x y) result))) 939 ((positive? c) (recur t1 r2 (+ 1 n) (additem yk1 y result))))))) 938 940 939 941 ))))
Note: See TracChangeset
for help on using the changeset viewer.