Enum swh_graph::collections::AdaptiveNodeSet
source · pub enum AdaptiveNodeSet {
Sparse {
max_items: usize,
data: HashSet<NodeId>,
},
Dense {
data: BitVec,
},
}
Expand description
Implementation of NodeSet
that dynamically changes the underlying representation
based on its content
The current implementation is initialized with a HashSet
, but switches to
[BitVec
] once the data becomes dense.
This has the advantage of allocating little memory if there won’t be many elements,
but avoiding the overhead of HashSet
when there are.
let mut node_set = AdaptiveNodeSet::new(100);
assert_eq!(format!("{:?}", node_set), "Sparse { max_items: 100, data: {} }");
node_set.insert(10);
assert_eq!(format!("{:?}", node_set), "Sparse { max_items: 100, data: {10} }");
for i in 20..30 {
node_set.insert(i);
}
assert_eq!(format!("{:?}", node_set), "Dense { data: BitVec { data: [1072694272, 0], len: 100 } }");
Variants§
Implementations§
Trait Implementations§
source§impl Debug for AdaptiveNodeSet
impl Debug for AdaptiveNodeSet
source§impl NodeSet for AdaptiveNodeSet
impl NodeSet for AdaptiveNodeSet
Auto Trait Implementations§
impl RefUnwindSafe for AdaptiveNodeSet
impl Send for AdaptiveNodeSet
impl Sync for AdaptiveNodeSet
impl Unpin for AdaptiveNodeSet
impl UnwindSafe for AdaptiveNodeSet
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
Mutably borrows from an owned value. Read more
§impl<T, U> CastableInto<U> for Twhere
U: CastableFrom<T>,
impl<T, U> CastableInto<U> for Twhere U: CastableFrom<T>,
§impl<T> DowncastableFrom<T> for T
impl<T> DowncastableFrom<T> for T
§fn downcast_from(value: T) -> T
fn downcast_from(value: T) -> T
Truncate the current UnsignedInt to a possibly smaller size
§impl<T, U> DowncastableInto<U> for Twhere
U: DowncastableFrom<T>,
impl<T, U> DowncastableInto<U> for Twhere U: DowncastableFrom<T>,
§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere T: ?Sized,
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> UpcastableFrom<T> for T
impl<T> UpcastableFrom<T> for T
§fn upcast_from(value: T) -> T
fn upcast_from(value: T) -> T
Extend the current UnsignedInt to a possibly bigger size.