Merge branch 'main' of https://www.gnaut.com/team/lzf1
This commit is contained in:
@@ -12,4 +12,5 @@ debug=2
|
|||||||
rand="0.8.5"
|
rand="0.8.5"
|
||||||
hashbrown="0.14"
|
hashbrown="0.14"
|
||||||
finum={ path="../finum" }
|
finum={ path="../finum" }
|
||||||
|
hashbrown="0.14.5"
|
||||||
|
|
||||||
|
|||||||
60
src/main.rs
60
src/main.rs
@@ -251,27 +251,37 @@ impl RoyaltyTree {
|
|||||||
if self.tree.len()==0 { return None }
|
if self.tree.len()==0 { return None }
|
||||||
let mut f=self.forefather();
|
let mut f=self.forefather();
|
||||||
while self.count_here_below(f)>0 {
|
while self.count_here_below(f)>0 {
|
||||||
|
if f&1==0 { return Some(f); }
|
||||||
let c0=self.count_here(f);
|
let c0=self.count_here(f);
|
||||||
let c1=if f&1==0 { 0 } else { self.count_here_below(wt_left(f).unwrap()) };
|
let c1=if f&1==0 { self.count_here(f) } else { self.count_here_below(wt_left(f).unwrap()) };
|
||||||
let c2=if f&1==0 { 0 } else { self.count_here_below(wt_right(f).unwrap()) };
|
let c2=if f&1==0 { self.count_here(f) } else { self.count_here_below(wt_right(f).unwrap()) };
|
||||||
let c=c0+c1+c2;
|
let c=c0+c1+c2;
|
||||||
let r=rng.gen_range(0..c);
|
let r=rng.gen_range(0..c);
|
||||||
if r<c0 { return Some(f) }
|
if r<c0 { println!("returning {}",f); return Some(f) }
|
||||||
else if r<c1 { f=wt_left(f).unwrap() }
|
else if r<c0+c1 { f=wt_left(f).unwrap() }
|
||||||
else { f=wt_right(f).unwrap() }
|
else { f=wt_right(f).unwrap() }
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
fn capture_partial(&mut self, id: usize, weight: FiNum) -> FiNum {
|
fn capture_partial(&mut self, id: usize, weight: FiNum) -> FiNum {
|
||||||
FiNum::zero()
|
FiNum::zero()
|
||||||
}
|
}
|
||||||
fn sub_weight(&mut self, index: usize, weight: FiNum) {
|
fn sub_weight(&mut self, index: usize, mut weight: FiNum) {
|
||||||
self.get_royalty(index);
|
self.get_royalty(index);
|
||||||
let redist=self.tree[index].acc;
|
let delta_count;
|
||||||
self.tree[index].acc=FiNum::zero();
|
let wh=self.weight_here(index);
|
||||||
|
let redist=if weight>=wh { delta_count=if wh>FiNum::zero() { 1 } else { 0 }; weight=wh; self.tree[index].acc }
|
||||||
|
else { delta_count=0; self.tree[index].acc*weight/wh };
|
||||||
|
self.tree[index].acc-=redist;
|
||||||
let mut index=index;
|
let mut index=index;
|
||||||
let ff=self.forefather();
|
let ff=self.forefather();
|
||||||
while index!=ff { self.tree[index].weight-=weight; index=wt_parent(index); }
|
if delta_count>0 { println!("YES ITS > 0"); }
|
||||||
|
while index!=ff {
|
||||||
|
self.tree[index].weight-=weight;
|
||||||
|
self.tree[index].count-=delta_count;
|
||||||
|
if index==ff { break; }
|
||||||
|
index=wt_parent(index);
|
||||||
|
}
|
||||||
self.add_royalty(redist);
|
self.add_royalty(redist);
|
||||||
}
|
}
|
||||||
fn set_location(&mut self, id: usize, index: usize) {
|
fn set_location(&mut self, id: usize, index: usize) {
|
||||||
@@ -286,7 +296,7 @@ impl RoyaltyTree {
|
|||||||
self.expand_to(ff1*2);
|
self.expand_to(ff1*2);
|
||||||
while ff0<ff1 {
|
while ff0<ff1 {
|
||||||
ff0=wt_parent(ff0);
|
ff0=wt_parent(ff0);
|
||||||
println!("Setting self.tree[{}].weight to {}",ff0,self.tree[ff0].weight);
|
println!("Setting self.tree[{}].weight to {} and count to {}",ff0,w,c);
|
||||||
self.tree[ff0].weight=w;
|
self.tree[ff0].weight=w;
|
||||||
self.tree[ff0].count=c;
|
self.tree[ff0].count=c;
|
||||||
}
|
}
|
||||||
@@ -294,19 +304,14 @@ impl RoyaltyTree {
|
|||||||
else { self.expand_to(wt_forefather(index)*2); }
|
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 delta_count=if self.weight_here(index)==FiNum::zero() { 1 } else { 0 };
|
||||||
let ff=self.forefather();
|
let ff=self.forefather();
|
||||||
while index!=ff {
|
loop {
|
||||||
println!("self.tree[{}].weight={}",index,self.tree[index].weight);
|
|
||||||
if self.weight_here(index)==FiNum::zero() && weight>FiNum::zero() {
|
|
||||||
self.tree[index].count+=1;
|
|
||||||
}
|
|
||||||
self.tree[index].weight+=weight;
|
self.tree[index].weight+=weight;
|
||||||
|
self.tree[index].count+=delta_count;
|
||||||
|
if index==ff { break; }
|
||||||
index=wt_parent(index);
|
index=wt_parent(index);
|
||||||
}
|
}
|
||||||
if self.weight_here(index)==FiNum::zero() && weight>FiNum::zero() {
|
|
||||||
self.tree[index].count+=1;
|
|
||||||
}
|
|
||||||
self.tree[index].weight+=weight;
|
|
||||||
}
|
}
|
||||||
fn forefather(&self) -> usize {
|
fn forefather(&self) -> usize {
|
||||||
wt_forefather(self.tree.len()-1)
|
wt_forefather(self.tree.len()-1)
|
||||||
@@ -805,16 +810,19 @@ fn royalty_stuff() {
|
|||||||
rt.dump();
|
rt.dump();
|
||||||
rt.add_weight(5,FiNum::new_i32(1));
|
rt.add_weight(5,FiNum::new_i32(1));
|
||||||
rt.dump();
|
rt.dump();
|
||||||
return;
|
// return;
|
||||||
for i in 1..1000000 {
|
for i in 1..10000 {
|
||||||
rt.dump();
|
// rt.dump();
|
||||||
|
let node=rng.gen_range(0..10);
|
||||||
match rng.gen_range(0..10) {
|
match rng.gen_range(0..10) {
|
||||||
0 => rt.add_weight(rng.gen_range(0..8),FiNum::new_i32(rng.gen_range(0..101))),
|
0 => { println!("Add at {}",node); rt.add_weight(node,FiNum::new_i32(rng.gen_range(0..101))) },
|
||||||
1 => rt.add_royalty(FiNum::new_i32(rng.gen_range(0..10))),
|
1 => { println!("Sub at {}",node); rt.sub_weight(node,FiNum::new_i32(rng.gen_range(0..101))) },
|
||||||
2 => println!("Random Order ID: {:?}",rt.random_order_id(&mut rng)),
|
2 => rt.add_royalty(FiNum::new_i32(rng.gen_range(0..10))),
|
||||||
|
3 => println!("Random Order ID: {:?}",rt.random_order_id(&mut rng)),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
rt.dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user