changes
This commit is contained in:
19
src/main.rs
19
src/main.rs
@@ -115,7 +115,7 @@ impl RoyaltyTree {
|
|||||||
let d1=lazy*self.weight_here(index)/self.weight_here_below(index);
|
let d1=lazy*self.weight_here(index)/self.weight_here_below(index);
|
||||||
let d02=lazy-d1;
|
let d02=lazy-d1;
|
||||||
let index_left =wt_left (index).unwrap();
|
let index_left =wt_left (index).unwrap();
|
||||||
let index_right=wt_right(index).unwrap();
|
let index_right=wt_right_edge(index,self.tree.len()).unwrap();
|
||||||
let d0=d02*self.weight_here_below(index_left)/self.weight_below(index);
|
let d0=d02*self.weight_here_below(index_left)/self.weight_below(index);
|
||||||
let d2=d02-d0;
|
let d2=d02-d0;
|
||||||
assert!(lazy==d0+d1+d2,"Distributing amounts that don't add up.");
|
assert!(lazy==d0+d1+d2,"Distributing amounts that don't add up.");
|
||||||
@@ -459,8 +459,19 @@ fn wt_left(index:usize) -> Option<usize> {
|
|||||||
if level>0 { Some(index-(1<<(wt_level(index)-1))) } else { None }
|
if level>0 { Some(index-(1<<(wt_level(index)-1))) } else { None }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wt_first_left(index: usize, edge: usize) -> Option<usize> { // Includes edge
|
fn wt_right_edge(index: usize, edge: usize) -> Option<usize> { // Less than edge
|
||||||
|
if index&1==0 { None }
|
||||||
|
else {
|
||||||
|
let mut r=wt_right(index).unwrap();
|
||||||
|
if r<edge { Some(r) }
|
||||||
|
else {
|
||||||
|
while r&1==1 {
|
||||||
|
if r<edge { return Some(r); }
|
||||||
|
else { r=wt_left(r).unwrap(); }
|
||||||
|
}
|
||||||
|
if r<edge { Some(r) } else { None }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wt_right(index:usize) -> Option<usize> {
|
fn wt_right(index:usize) -> Option<usize> {
|
||||||
@@ -498,7 +509,7 @@ fn tree_stuff() {
|
|||||||
|
|
||||||
fn royalty_stuff() {
|
fn royalty_stuff() {
|
||||||
let mut rt=RoyaltyTree::new();
|
let mut rt=RoyaltyTree::new();
|
||||||
for _ in 0..6 {
|
for _ in 0..20 {
|
||||||
let index=rt.insert(FiNum::new_i32(10));
|
let index=rt.insert(FiNum::new_i32(10));
|
||||||
rt.add_royalty(FiNum::new_i32(24))
|
rt.add_royalty(FiNum::new_i32(24))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user