Struct patricia_tree::set::PatriciaSet [−][src]
pub struct PatriciaSet { /* fields omitted */ }
A set based on a patricia tree.
Methods
impl PatriciaSet
[src]
impl PatriciaSet
pub fn new() -> Self
[src]
pub fn new() -> Self
Makes a new empty PatriciaSet
instance.
Examples
use patricia_tree::PatriciaSet; let set = PatriciaSet::new(); assert!(set.is_empty());
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
Returns the number of elements in this set.
Examples
use patricia_tree::PatriciaSet; let mut set = PatriciaSet::new(); set.insert("foo"); set.insert("bar"); assert_eq!(set.len(), 2);
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
Returns true if this set contains no elements.
Examples
use patricia_tree::PatriciaSet; let mut set = PatriciaSet::new(); assert!(set.is_empty()); set.insert("foo"); assert!(!set.is_empty()); set.clear(); assert!(set.is_empty());
pub fn clear(&mut self)
[src]
pub fn clear(&mut self)
Clears this set, removing all values.
Examples
use patricia_tree::PatriciaSet; let mut set = PatriciaSet::new(); set.insert("foo"); set.clear(); assert!(set.is_empty());
pub fn contains<T: AsRef<[u8]>>(&self, value: T) -> bool
[src]
pub fn contains<T: AsRef<[u8]>>(&self, value: T) -> bool
Returns true
if this set contains a value.
Examples
use patricia_tree::PatriciaSet; let mut set = PatriciaSet::new(); set.insert("foo"); assert!(set.contains("foo")); assert!(!set.contains("bar"));
pub fn get_longest_common_prefix<'a, T: ?Sized>(
&self,
value: &'a T
) -> Option<&'a [u8]> where
T: AsRef<[u8]>,
[src]
pub fn get_longest_common_prefix<'a, T: ?Sized>(
&self,
value: &'a T
) -> Option<&'a [u8]> where
T: AsRef<[u8]>,
Finds the longest common prefix of value
and the elements in this set.
Examples
use patricia_tree::PatriciaSet; let mut set = PatriciaSet::new(); set.insert("foo"); set.insert("foobar"); assert_eq!(set.get_longest_common_prefix("fo"), None); assert_eq!(set.get_longest_common_prefix("foo"), Some("foo".as_bytes())); assert_eq!(set.get_longest_common_prefix("fooba"), Some("foo".as_bytes())); assert_eq!(set.get_longest_common_prefix("foobar"), Some("foobar".as_bytes())); assert_eq!(set.get_longest_common_prefix("foobarbaz"), Some("foobar".as_bytes()));
pub fn insert<T: AsRef<[u8]>>(&mut self, value: T) -> bool
[src]
pub fn insert<T: AsRef<[u8]>>(&mut self, value: T) -> bool
Adds a value to this set.
If the set did not have this value present, true
is returned.
If the set did have this value present, false
is returned, and the entry is not updated.
Examples
use patricia_tree::PatriciaSet; let mut set = PatriciaSet::new(); assert!(set.insert("foo")); assert!(!set.insert("foo")); assert_eq!(set.len(), 1);
pub fn remove<T: AsRef<[u8]>>(&mut self, value: T) -> bool
[src]
pub fn remove<T: AsRef<[u8]>>(&mut self, value: T) -> bool
Removes a value from the set. Returns true
is the value was present in this set.
Examples
use patricia_tree::PatriciaSet; let mut set = PatriciaSet::new(); set.insert("foo"); assert_eq!(set.remove("foo"), true); assert_eq!(set.remove("foo"), false);
pub fn split_by_prefix<T: AsRef<[u8]>>(&mut self, prefix: T) -> Self
[src]
pub fn split_by_prefix<T: AsRef<[u8]>>(&mut self, prefix: T) -> Self
Splits the set into two at the given prefix.
The returned set contains all the entries that prefixed by prefix
.
Examples
use patricia_tree::PatriciaSet; let mut a = PatriciaSet::new(); a.insert("rust"); a.insert("ruby"); a.insert("python"); a.insert("erlang"); let b = a.split_by_prefix("ru"); assert_eq!(a.iter().collect::<Vec<_>>(), [b"erlang", b"python"]); assert_eq!(b.iter().collect::<Vec<_>>(), [b"ruby", b"rust"]);
ⓘImportant traits for Iter<'a>pub fn iter(&self) -> Iter
[src]
pub fn iter(&self) -> Iter
Gets an iterator over the contents of this set, in sorted order.
Examples
use patricia_tree::PatriciaSet; let mut set = PatriciaSet::new(); set.insert("foo"); set.insert("bar"); set.insert("baz"); assert_eq!(set.iter().collect::<Vec<_>>(), [Vec::from("bar"), "baz".into(), "foo".into()]);
Trait Implementations
impl Default for PatriciaSet
[src]
impl Default for PatriciaSet
fn default() -> PatriciaSet
[src]
fn default() -> PatriciaSet
Returns the "default value" for a type. Read more
impl Clone for PatriciaSet
[src]
impl Clone for PatriciaSet
fn clone(&self) -> PatriciaSet
[src]
fn clone(&self) -> PatriciaSet
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Debug for PatriciaSet
[src]
impl Debug for PatriciaSet
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl IntoIterator for PatriciaSet
[src]
impl IntoIterator for PatriciaSet
type Item = Vec<u8>
The type of the elements being iterated over.
type IntoIter = IntoIter
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
fn into_iter(self) -> Self::IntoIter
Creates an iterator from a value. Read more
impl<T: AsRef<[u8]>> FromIterator<T> for PatriciaSet
[src]
impl<T: AsRef<[u8]>> FromIterator<T> for PatriciaSet
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = T>,
[src]
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = T>,
Creates a value from an iterator. Read more
impl<T: AsRef<[u8]>> Extend<T> for PatriciaSet
[src]
impl<T: AsRef<[u8]>> Extend<T> for PatriciaSet
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = T>,
[src]
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = T>,
Extends a collection with the contents of an iterator. Read more
impl From<Node<()>> for PatriciaSet
[src]
impl From<Node<()>> for PatriciaSet
impl From<PatriciaSet> for Node<()>
[src]
impl From<PatriciaSet> for Node<()>
fn from(f: PatriciaSet) -> Self
[src]
fn from(f: PatriciaSet) -> Self
Performs the conversion.
impl AsRef<Node<()>> for PatriciaSet
[src]
impl AsRef<Node<()>> for PatriciaSet
Auto Trait Implementations
impl Send for PatriciaSet
impl Send for PatriciaSet
impl !Sync for PatriciaSet
impl !Sync for PatriciaSet