changes
This commit is contained in:
17
src/main.rs
17
src/main.rs
@@ -76,7 +76,7 @@ impl RoyaltyTree {
|
||||
RoyaltyTree { tree:Vec::new() }
|
||||
}
|
||||
fn weight_here_below(&self, index:usize) -> FiNum {
|
||||
if index<self.tree.len() { self.tree[index].weight } else { FiNum::zero() }
|
||||
if index<self.tree.len() { self.tree[index].weight} else { FiNum::zero() }
|
||||
}
|
||||
fn weight_below(&self, index:usize) -> FiNum {
|
||||
if index&1==0 {
|
||||
@@ -89,7 +89,10 @@ impl RoyaltyTree {
|
||||
if index&1==0 {
|
||||
self.weight_here_below(index)
|
||||
} else {
|
||||
self.weight_here_below(index)-self.weight_below(index)
|
||||
let w0=self.weight_here_below(index);
|
||||
let w1=self.weight_below(index);
|
||||
println!("Weight_here({})={}-{}",index,w0,w1);
|
||||
w0-w1
|
||||
}
|
||||
}
|
||||
fn expand_to(&mut self, index: usize) -> &mut Self {
|
||||
@@ -145,13 +148,21 @@ impl RoyaltyTree {
|
||||
fn insert(&mut self, weight: FiNum) {
|
||||
self.tree.push(Royalty::new());
|
||||
let mut index=self.tree.len()-1;
|
||||
if index&1==1 {
|
||||
let left_weight=self.tree[wt_left(index).unwrap()].weight;
|
||||
self.tree[index].weight=left_weight;
|
||||
}
|
||||
println!("Inserting at {}",index);
|
||||
let rval=index;
|
||||
let ff=self.forefather();
|
||||
while index!=ff {
|
||||
println!("Index {} Adding weight {}",index,weight);
|
||||
self.tree[index].weight+=weight;
|
||||
index=wt_parent(index);
|
||||
}
|
||||
println!("Index {} Adding weight {}",index,weight);
|
||||
self.tree[index].weight+=weight;
|
||||
println!("Index {} Final weight {}",index,self.tree[index].weight);
|
||||
}
|
||||
fn forefather(&self) -> usize {
|
||||
wt_forefather(self.tree.len()-1)
|
||||
@@ -481,7 +492,7 @@ fn tree_stuff() {
|
||||
|
||||
fn royalty_stuff() {
|
||||
let mut rt=RoyaltyTree::new();
|
||||
for _ in 0..3 {
|
||||
for _ in 0..2 {
|
||||
let index=rt.insert(FiNum::new_i32(10));
|
||||
rt.add_royalty(FiNum::new_i32(24))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user