-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(docs): simplify improved formula in dark market
- Loading branch information
1 parent
b752837
commit 622287c
Showing
5 changed files
with
178 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
fn compute_prefix_sum(arr: &[u16]) -> Vec<u16> { | ||
let mut sum = 0; | ||
arr.iter() | ||
.map(|a| { | ||
sum += a; | ||
sum | ||
}) | ||
.collect() | ||
} | ||
|
||
fn fill_orders(total_orders: u16, orders: &mut [u16], prefix_sum_arr: &[u16]) { | ||
for (i, order) in orders.iter_mut().enumerate() { | ||
*order = (total_orders as i64 - *prefix_sum_arr.get(i - 1).unwrap_or(&0) as i64) | ||
.max(0) | ||
.min(*order as i64) as u16; | ||
} | ||
} | ||
|
||
pub fn volume_match(sell_orders: &mut [u16], buy_orders: &mut [u16]) { | ||
let prefix_sum_sell_orders = compute_prefix_sum(sell_orders); | ||
|
||
let prefix_sum_buy_orders = compute_prefix_sum(buy_orders); | ||
|
||
let total_buy_orders = *prefix_sum_buy_orders.last().unwrap_or(&0); | ||
|
||
let total_sell_orders = *prefix_sum_sell_orders.last().unwrap_or(&0); | ||
|
||
fill_orders(total_sell_orders, buy_orders, &prefix_sum_buy_orders); | ||
fill_orders(total_buy_orders, sell_orders, &prefix_sum_sell_orders); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters