changes
This commit is contained in:
15
src/main.rs
15
src/main.rs
@@ -110,11 +110,11 @@ impl RoyaltyTree {
|
||||
self.tree[index].lazy=FiNum::zero();
|
||||
} else {
|
||||
let lazy=self.tree[index].lazy;
|
||||
let d1=lazy*self.weight_here(index)/self.weight_here_below(index);
|
||||
let d1=if lazy>0.into() { lazy*self.weight_here(index)/self.weight_here_below(index) } else { FiNum::zero() };
|
||||
let d02=lazy-d1;
|
||||
let index_left =wt_left (index).unwrap();
|
||||
let index_right=wt_right(index).unwrap();
|
||||
let d0=d02*self.weight_here_below(index_left)/self.weight_below(index);
|
||||
let d0=if d02>0.into() { d02*self.weight_here_below(index_left)/self.weight_below(index) } else { FiNum::zero() };
|
||||
let d2=d02-d0;
|
||||
assert!(lazy==d0+d1+d2,"Distributing amounts that don't add up.");
|
||||
self.tree[index_left ].lazy+=d0;
|
||||
@@ -142,17 +142,18 @@ impl RoyaltyTree {
|
||||
println!("Add_weight at {}",index);
|
||||
if self.tree.len()>0 {
|
||||
let mut ff0=self.forefather();
|
||||
self.expand_to(wt_forefather(index)*2);
|
||||
let ff=self.forefather();
|
||||
while ff0!=ff {
|
||||
let ff1=wt_forefather(index);
|
||||
let w=self.tree[ff0].weight;
|
||||
self.expand_to(ff1*2);
|
||||
while ff0<ff1 {
|
||||
ff0=wt_parent(ff0);
|
||||
self.tree[ff0].weight=w;
|
||||
}
|
||||
}
|
||||
let ff=self.forefather();
|
||||
else { self.expand_to(wt_forefather(index)*2); }
|
||||
self.get_royalty(index); // Just for the side effect of capturing everything to this point
|
||||
let mut index=index;
|
||||
let ff=self.forefather();
|
||||
println!("Ascending from {} to {}",index,ff);
|
||||
while index!=ff {
|
||||
self.tree[index].weight+=weight;
|
||||
@@ -503,7 +504,7 @@ fn tree_stuff() {
|
||||
|
||||
fn royalty_stuff() {
|
||||
let mut rt=RoyaltyTree::new();
|
||||
for index in 0..20 {
|
||||
for index in 0..10 {
|
||||
rt.add_weight(index,FiNum::new_i32(10));
|
||||
rt.add_royalty(FiNum::new_i32(24))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user