pub struct WitnessHandle { /* private fields */ }Expand description
Handle to a witness (cheap to clone)
This is the primary type for passing witnesses around. It uses an Arc
internally so cloning is O(1) and witnesses can be shared across threads.
§Examples
use ruvector_mincut::instance::witness::WitnessHandle;
use roaring::RoaringBitmap;
let mut membership = RoaringBitmap::new();
membership.insert(1);
membership.insert(2);
membership.insert(3);
let witness = WitnessHandle::new(1, membership, 4);
assert!(witness.contains(1));
assert!(witness.contains(2));
assert!(!witness.contains(5));
assert_eq!(witness.boundary_size(), 4);Implementations§
Source§impl WitnessHandle
impl WitnessHandle
Sourcepub fn new(
seed: VertexId,
membership: RoaringBitmap,
boundary_size: u64,
) -> Self
pub fn new( seed: VertexId, membership: RoaringBitmap, boundary_size: u64, ) -> Self
Create a new witness handle
§Arguments
seed- The seed vertex defining this cut (must be in membership)membership- Bitmap of vertices in the cut set Uboundary_size- The size of the boundary |δ(U)|
§Panics
Panics if the seed vertex is not in the membership set (debug builds only)
§Examples
use ruvector_mincut::instance::witness::WitnessHandle;
use roaring::RoaringBitmap;
let mut membership = RoaringBitmap::new();
membership.insert(0);
membership.insert(1);
let witness = WitnessHandle::new(0, membership, 5);
assert_eq!(witness.seed(), 0);Sourcepub fn contains(&self, v: VertexId) -> bool
pub fn contains(&self, v: VertexId) -> bool
Check if vertex is in the cut set U
§Time Complexity
O(1) via bitmap lookup
§Examples
use ruvector_mincut::instance::witness::WitnessHandle;
use roaring::RoaringBitmap;
let mut membership = RoaringBitmap::new();
membership.insert(5);
membership.insert(10);
let witness = WitnessHandle::new(5, membership, 3);
assert!(witness.contains(5));
assert!(witness.contains(10));
assert!(!witness.contains(15));Sourcepub fn boundary_size(&self) -> u64
pub fn boundary_size(&self) -> u64
Get boundary size |δ(U)|
Returns the pre-computed boundary size for O(1) access.
§Examples
use ruvector_mincut::instance::witness::WitnessHandle;
use roaring::RoaringBitmap;
let witness = WitnessHandle::new(1, RoaringBitmap::from_iter([1, 2, 3]), 7);
assert_eq!(witness.boundary_size(), 7);Sourcepub fn seed(&self) -> VertexId
pub fn seed(&self) -> VertexId
Get the seed vertex
§Examples
use ruvector_mincut::instance::witness::WitnessHandle;
use roaring::RoaringBitmap;
let witness = WitnessHandle::new(42, RoaringBitmap::from_iter([42u32]), 1);
assert_eq!(witness.seed(), 42);Sourcepub fn hash(&self) -> u64
pub fn hash(&self) -> u64
Get the witness hash
Used for fast equality checks without comparing full membership sets.
Sourcepub fn materialize_partition(&self) -> (HashSet<VertexId>, HashSet<VertexId>)
pub fn materialize_partition(&self) -> (HashSet<VertexId>, HashSet<VertexId>)
Materialize full partition (U, V \ U)
This is an expensive operation (O(|V|)) that converts the implicit representation into explicit sets. Use sparingly, primarily for debugging or verification.
§Returns
A tuple (U, V_minus_U) where:
Uis the set of vertices in the cutV_minus_Uis the complement set
§Note
This method assumes vertices are numbered 0..max_vertex. For sparse graphs, V \ U may contain vertex IDs that don’t exist in the graph.
§Examples
use ruvector_mincut::instance::witness::WitnessHandle;
use roaring::RoaringBitmap;
use std::collections::HashSet;
let mut membership = RoaringBitmap::new();
membership.insert(1);
membership.insert(2);
let witness = WitnessHandle::new(1, membership, 3);
let (u, _v_minus_u) = witness.materialize_partition();
assert!(u.contains(&1));
assert!(u.contains(&2));
assert!(!u.contains(&3));Sourcepub fn cardinality(&self) -> u64
pub fn cardinality(&self) -> u64
Get the cardinality of the cut set U
§Examples
use ruvector_mincut::instance::witness::WitnessHandle;
use roaring::RoaringBitmap;
let witness = WitnessHandle::new(1, RoaringBitmap::from_iter([1u32, 2u32, 3u32]), 5);
assert_eq!(witness.cardinality(), 3);Trait Implementations§
Source§impl Clone for WitnessHandle
impl Clone for WitnessHandle
Source§fn clone(&self) -> WitnessHandle
fn clone(&self) -> WitnessHandle
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WitnessHandle
impl Debug for WitnessHandle
Source§impl PartialEq for WitnessHandle
impl PartialEq for WitnessHandle
Source§impl Witness for WitnessHandle
impl Witness for WitnessHandle
Source§fn boundary_size(&self) -> u64
fn boundary_size(&self) -> u64
Source§fn materialize_partition(&self) -> (HashSet<VertexId>, HashSet<VertexId>)
fn materialize_partition(&self) -> (HashSet<VertexId>, HashSet<VertexId>)
Source§fn cardinality(&self) -> u64
fn cardinality(&self) -> u64
impl Eq for WitnessHandle
Auto Trait Implementations§
impl Freeze for WitnessHandle
impl RefUnwindSafe for WitnessHandle
impl Send for WitnessHandle
impl Sync for WitnessHandle
impl Unpin for WitnessHandle
impl UnwindSafe for WitnessHandle
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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