pub struct FrontierScratch { /* private fields */ }Expand description
Reusable double-buffer for BFS / multi-hop frontier expansion.
Reduces per-level Vec allocation churn: instead of allocating fresh
Vec<u64> buffers for current and next at every hop, a single
FrontierScratch is allocated once and reused across all hops in a query.
§Semantics
FrontierScratch has no visited-set semantics. It does not deduplicate
frontier entries. Callers that require reachability dedup must implement
that separately. This is intentional — see spec §4.5.
§Usage
let mut frontier = FrontierScratch::new(256);
// populate initial frontier:
frontier.current_mut().extend(src_slots);
// expand hop:
for &slot in frontier.current() {
frontier.next_mut().extend(neighbors(slot));
}
frontier.advance(); // swap: next → current, clear next
// read expanded frontier:
for &slot in frontier.current() { ... }Implementations§
Source§impl FrontierScratch
impl FrontierScratch
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Allocate a FrontierScratch pre-reserving capacity slots in each
buffer.
Sourcepub fn advance(&mut self)
pub fn advance(&mut self)
Swap current ↔ next and clear next.
Call this after populating next_mut() to advance to the next BFS level.
Sourcepub fn current_mut(&mut self) -> &mut Vec<u64>
pub fn current_mut(&mut self) -> &mut Vec<u64>
Mutable reference to the current frontier (for initial population).
Sourcepub fn next_mut(&mut self) -> &mut Vec<u64>
pub fn next_mut(&mut self) -> &mut Vec<u64>
Mutable reference to the next frontier (populated during expansion).
Sourcepub fn bytes_allocated(&self) -> usize
pub fn bytes_allocated(&self) -> usize
Byte footprint of live data in both buffers (for memory-limit checks).
Uses len() rather than capacity() so that pre-allocated but unused
capacity does not trigger the memory limit before any edges are traversed.
Auto Trait Implementations§
impl Freeze for FrontierScratch
impl RefUnwindSafe for FrontierScratch
impl Send for FrontierScratch
impl Sync for FrontierScratch
impl Unpin for FrontierScratch
impl UnsafeUnpin for FrontierScratch
impl UnwindSafe for FrontierScratch
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more