pub struct PrefixSet<T> { /* private fields */ }
Expand description
A set implemented as a PrefixMap
where the value is ()
.
Implementations§
Source§impl<T: Eq + Clone> PrefixSet<T>
impl<T: Eq + Clone> PrefixSet<T>
Sourcepub fn new() -> PrefixSet<T>
pub fn new() -> PrefixSet<T>
Creates an empty PrefixSet
.
§Examples
use prefix_tree::PrefixSet;
let mut set: PrefixSet<u8> = PrefixSet::new();
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the set, removing all key-value pairs.
§Examples
use prefix_tree::PrefixSet;
let mut set: PrefixSet<u8> = PrefixSet::new();
set.insert("foo");
set.clear();
assert!(set.is_empty());
Sourcepub fn contains<Q>(&self, key: Q) -> bool
pub fn contains<Q>(&self, key: Q) -> bool
Returns true
if the set contains a value.
§Examples
use prefix_tree::PrefixSet;
let mut set: PrefixSet<u8> = PrefixSet::new();
set.insert("1");
assert_eq!(set.contains("1"), true);
assert_eq!(set.contains("2"), false);
Sourcepub fn insert<Q>(&mut self, key: Q) -> bool
pub fn insert<Q>(&mut self, key: Q) -> bool
Adds a value to the set.
§Examples
use prefix_tree::PrefixSet;
let mut set: PrefixSet<u8> = PrefixSet::new();
assert_eq!(set.insert("1"), true);
assert_eq!(set.insert("1"), false);
assert_eq!(set.contains("1"), true);
Sourcepub fn remove<Q>(&mut self, key: Q) -> bool
pub fn remove<Q>(&mut self, key: Q) -> bool
Removes a value from the set. Returns whether the value was present in the set.
§Examples
use prefix_tree::PrefixSet;
let mut set: PrefixSet<u8> = PrefixSet::new();
set.insert("1");
assert_eq!(set.remove("1"), true);
assert_eq!(set.remove("1"), false);
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the set contains no elements.
§Examples
use prefix_tree::PrefixSet;
let mut set: PrefixSet<u8> = PrefixSet::new();
assert_eq!(set.is_empty(), true);
set.insert("foo");
assert_eq!(set.is_empty(), false);
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the set.
§Examples
use prefix_tree::PrefixSet;
let mut set: PrefixSet<u8> = PrefixSet::new();
assert_eq!(set.len(), 0);
set.insert("foo");
assert_eq!(set.len(), 1);
Sourcepub fn iter(&self) -> Iter<'_, T>
pub fn iter(&self) -> Iter<'_, T>
Gets an iterator that visits the values in PrefixSet
.
§Examples
use prefix_tree::PrefixSet;
let mut set: PrefixSet<u8> = PrefixSet::new();
set.insert("1");
set.insert("2");
let mut iter = set.iter();
assert_eq!(iter.next(), Some(vec![b'1']));
assert_eq!(iter.next(), Some(vec![b'2']));
Trait Implementations§
impl<T: Eq + Clone> Eq for PrefixSet<T>
Auto Trait Implementations§
impl<T> Freeze for PrefixSet<T>
impl<T> RefUnwindSafe for PrefixSet<T>where
T: RefUnwindSafe,
impl<T> Send for PrefixSet<T>where
T: Send,
impl<T> Sync for PrefixSet<T>where
T: Sync,
impl<T> Unpin for PrefixSet<T>where
T: Unpin,
impl<T> UnwindSafe for PrefixSet<T>where
T: UnwindSafe,
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