use crate::config::POOL_SIZE;
use crate::nodes::chunk::Chunk;
use crate::nodes::rrb::Node;
use crate::util::Pool;
pub struct RRBPool<A> {
pub(crate) node_pool: Pool<Chunk<Node<A>>>,
pub(crate) value_pool: Pool<Chunk<A>>,
pub(crate) size_pool: Pool<Chunk<usize>>,
}
impl<A> RRBPool<A> {
pub fn new(size: usize) -> Self {
Self::with_sizes(size, size, size)
}
pub fn with_sizes(
node_pool_size: usize,
leaf_pool_size: usize,
size_table_pool_size: usize,
) -> Self {
Self {
node_pool: Pool::new(node_pool_size),
value_pool: Pool::new(leaf_pool_size),
size_pool: Pool::new(size_table_pool_size),
}
}
pub fn fill(&self) {
self.node_pool.fill();
self.value_pool.fill();
self.size_pool.fill();
}
pub fn node_pool_size(&self) -> usize {
self.node_pool.get_pool_size()
}
pub fn leaf_pool_size(&self) -> usize {
self.value_pool.get_pool_size()
}
pub fn size_table_pool_size(&self) -> usize {
self.size_pool.get_pool_size()
}
}
impl<A> Default for RRBPool<A> {
fn default() -> Self {
Self::new(POOL_SIZE)
}
}
impl<A> Clone for RRBPool<A> {
fn clone(&self) -> Self {
Self {
node_pool: self.node_pool.clone(),
value_pool: self.value_pool.clone(),
size_pool: self.size_pool.clone(),
}
}
}