changes
This commit is contained in:
20
src/main.rs
20
src/main.rs
@@ -91,7 +91,7 @@ impl Royalty {
|
||||
}
|
||||
|
||||
impl RoyaltyTree {
|
||||
fn insert(&mut self, weight: FiNum) -> usize {
|
||||
fn insert(&mut self, weight: FiNum, royalty:FiNum) -> usize {
|
||||
let last=self.tree.len();
|
||||
let mut nweight=weight;
|
||||
if let Some(left )=wt_left (last) { if left <self.tree.len() { nweight+=self.tree[left ].weight } }
|
||||
@@ -103,8 +103,22 @@ impl RoyaltyTree {
|
||||
pivot=wt_parent(pivot);
|
||||
if pivot<self.tree.len() { self.tree[pivot].weight+=weight }
|
||||
}
|
||||
self.tree[forefather].acc+=royalty;
|
||||
last
|
||||
}
|
||||
fn capture(&mut self, index:usize, weight: FiNum) -> FiNum {
|
||||
let ff=wt_forefather(index);
|
||||
let mut index=index;
|
||||
let mut rval=FiNum::zero();
|
||||
loop {
|
||||
let cap=self.tree[index].acc*weight/self.tree[index].weight;
|
||||
self.tree[index].weight-=weight;
|
||||
self.tree[index].acc-=cap;
|
||||
rval+=cap;
|
||||
if index!=ff { index=wt_parent(index); } else { break; }
|
||||
}
|
||||
rval
|
||||
}
|
||||
fn dump(&self) {
|
||||
for index in 0..self.tree.len() {
|
||||
println!("Index {} Weight {}",index,self.tree[index].weight);
|
||||
@@ -257,7 +271,7 @@ impl Market {
|
||||
let bids=self.orders.get_mut(&ap).unwrap();
|
||||
let sell_qty_remain=sell_qty_initial*buy_qty/buy_qty_initial;
|
||||
if sell_qty_remain>0.into() {
|
||||
let rt_loc=self.royalties.entry(sell_type).or_insert(RoyaltyTree::new()).insert(sell_qty_remain);
|
||||
let rt_loc=self.royalties.entry(sell_type).or_insert(RoyaltyTree::new()).insert(sell_qty_remain,FiNum::zero());
|
||||
let neworder=Rc::new(RefCell::new(
|
||||
Order { owner:owner, sell_qty:sell_qty_remain, sell_remain:sell_qty_remain, buy_qty:buy_qty, rt_loc: rt_loc } ));
|
||||
bids.insert(neworder);
|
||||
@@ -429,7 +443,7 @@ fn tree_stuff() {
|
||||
fn royalty_stuff() {
|
||||
let mut rt=RoyaltyTree::new();
|
||||
for _ in 0..20 {
|
||||
rt.insert(FiNum::new_i32(10));
|
||||
rt.insert(FiNum::new_i32(10),FiNum::zero());
|
||||
}
|
||||
for index in 0..rt.tree.len() {
|
||||
println!("Index: {} Royalty: {}",index,rt.tree[index].weight);
|
||||
|
||||
Reference in New Issue
Block a user