This commit is contained in:
2024-06-10 18:39:12 -04:00
parent ec09d0aefa
commit c52c67ef54

View File

@@ -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))
}