use pricelevel::Id;
use std::cell::RefCell;
#[derive(Debug)]
pub struct MatchingPool {
filled_orders_pool: RefCell<Vec<Vec<Id>>>,
price_vec_pool: RefCell<Vec<Vec<u128>>>,
}
impl MatchingPool {
pub fn new() -> Self {
MatchingPool {
filled_orders_pool: RefCell::new(Vec::with_capacity(4)),
price_vec_pool: RefCell::new(Vec::with_capacity(4)),
}
}
pub fn get_filled_orders_vec(&self) -> Vec<Id> {
self.filled_orders_pool
.borrow_mut()
.pop()
.unwrap_or_else(|| Vec::with_capacity(16))
}
pub fn return_filled_orders_vec(&self, mut vec: Vec<Id>) {
vec.clear();
self.filled_orders_pool.borrow_mut().push(vec);
}
pub fn get_price_vec(&self) -> Vec<u128> {
self.price_vec_pool
.borrow_mut()
.pop()
.unwrap_or_else(|| Vec::with_capacity(32))
}
pub fn return_price_vec(&self, mut vec: Vec<u128>) {
vec.clear();
self.price_vec_pool.borrow_mut().push(vec);
}
}
impl Default for MatchingPool {
fn default() -> Self {
Self::new()
}
}