pub struct FilterPool { /* private fields */ }Expand description
A memory pool for efficient filter construction.
Uses bump allocation to minimize allocations when building complex filter trees.
The pool can be reused by calling reset() after each filter is built.
§Performance
- Filter construction in the pool: O(1) allocation per filter tree
- Materialization to owned filter: O(n) where n is the number of nodes
- Pool reset: O(1) (just resets the bump pointer)
§Thread Safety
FilterPool is not thread-safe. Each thread should have its own pool.
Implementations§
Source§impl FilterPool
impl FilterPool
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new filter pool with default capacity.
The pool starts with a small initial allocation and grows as needed.
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new filter pool with the specified initial capacity in bytes.
Use this when you know approximately how much memory your filters will need.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the pool, freeing all allocated memory for reuse.
This is very fast (O(1)) as it just resets the bump pointer. Call this between filter constructions to reuse memory.
Sourcepub fn allocated_bytes(&self) -> usize
pub fn allocated_bytes(&self) -> usize
Get the amount of memory currently allocated in the pool.
Sourcepub fn build<F>(&self, f: F) -> Filter
pub fn build<F>(&self, f: F) -> Filter
Build a filter using the pool’s arena for temporary allocations.
The closure receives a FilterBuilder that provides efficient methods
for constructing nested filters. The resulting filter is materialized
into an owned Filter that can be used after the pool is reset.
§Examples
use prax_query::pool::FilterPool;
use prax_query::Filter;
let mut pool = FilterPool::new();
let filter = pool.build(|b| {
b.and(vec![
b.eq("active", true),
b.gt("score", 100),
])
});