changes
This commit is contained in:
25
src/main.rs
25
src/main.rs
@@ -110,11 +110,11 @@ impl RoyaltyTree {
|
|||||||
self.tree[index].lazy=FiNum::zero();
|
self.tree[index].lazy=FiNum::zero();
|
||||||
} else {
|
} else {
|
||||||
let lazy=self.tree[index].lazy;
|
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 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(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;
|
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.");
|
||||||
self.tree[index_left ].lazy+=d0;
|
self.tree[index_left ].lazy+=d0;
|
||||||
@@ -140,19 +140,20 @@ impl RoyaltyTree {
|
|||||||
}
|
}
|
||||||
fn add_weight(&mut self, index: usize, weight: FiNum) {
|
fn add_weight(&mut self, index: usize, weight: FiNum) {
|
||||||
println!("Add_weight at {}",index);
|
println!("Add_weight at {}",index);
|
||||||
if self.tree.len()>0 {
|
if self.tree.len()>0 {
|
||||||
let mut ff0=self.forefather();
|
let mut ff0=self.forefather();
|
||||||
self.expand_to(wt_forefather(index)*2);
|
let ff1=wt_forefather(index);
|
||||||
let ff=self.forefather();
|
let w=self.tree[ff0].weight;
|
||||||
while ff0!=ff {
|
self.expand_to(ff1*2);
|
||||||
let w=self.tree[ff0].weight;
|
while ff0<ff1 {
|
||||||
ff0=wt_parent(ff0);
|
ff0=wt_parent(ff0);
|
||||||
self.tree[ff0].weight=w;
|
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
|
self.get_royalty(index); // Just for the side effect of capturing everything to this point
|
||||||
let mut index=index;
|
let mut index=index;
|
||||||
|
let ff=self.forefather();
|
||||||
println!("Ascending from {} to {}",index,ff);
|
println!("Ascending from {} to {}",index,ff);
|
||||||
while index!=ff {
|
while index!=ff {
|
||||||
self.tree[index].weight+=weight;
|
self.tree[index].weight+=weight;
|
||||||
@@ -503,7 +504,7 @@ fn tree_stuff() {
|
|||||||
|
|
||||||
fn royalty_stuff() {
|
fn royalty_stuff() {
|
||||||
let mut rt=RoyaltyTree::new();
|
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_weight(index,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