1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at http://mozilla.org/MPL/2.0/.
45use crate::config::POOL_SIZE;
6use crate::nodes::chunk::Chunk;
7use crate::nodes::rrb::Node;
8use crate::util::Pool;
910/// A memory pool for `Vector`.
11pub struct RRBPool<A> {
12pub(crate) node_pool: Pool<Chunk<Node<A>>>,
13pub(crate) value_pool: Pool<Chunk<A>>,
14pub(crate) size_pool: Pool<Chunk<usize>>,
15}
1617impl<A> RRBPool<A> {
18/// Create a new memory pool with the given size.
19pub fn new(size: usize) -> Self {
20Self::with_sizes(size, size, size)
21 }
2223/// Create a new memory pool with the given sizes for each subpool.
24pub fn with_sizes(
25 node_pool_size: usize,
26 leaf_pool_size: usize,
27 size_table_pool_size: usize,
28 ) -> Self {
29Self {
30 node_pool: Pool::new(node_pool_size),
31 value_pool: Pool::new(leaf_pool_size),
32 size_pool: Pool::new(size_table_pool_size),
33 }
34 }
3536/// Fill the memory pool with preallocated chunks.
37pub fn fill(&self) {
38self.node_pool.fill();
39self.value_pool.fill();
40self.size_pool.fill();
41 }
4243/// Get the size of the node subpool.
44pub fn node_pool_size(&self) -> usize {
45self.node_pool.get_pool_size()
46 }
4748/// Get the size of the leaf node subpool.
49pub fn leaf_pool_size(&self) -> usize {
50self.value_pool.get_pool_size()
51 }
5253/// Get the size of the size table subpool.
54pub fn size_table_pool_size(&self) -> usize {
55self.size_pool.get_pool_size()
56 }
57}
5859impl<A> Default for RRBPool<A> {
60/// Construct a pool with a reasonable default pool size.
61fn default() -> Self {
62Self::new(POOL_SIZE)
63 }
64}
6566impl<A> Clone for RRBPool<A> {
67fn clone(&self) -> Self {
68Self {
69 node_pool: self.node_pool.clone(),
70 value_pool: self.value_pool.clone(),
71 size_pool: self.size_pool.clone(),
72 }
73 }
74}