[][src]Struct patricia_tree::set::PatriciaSet

pub struct PatriciaSet { /* fields omitted */ }

A set based on a patricia tree.

Implementations

impl PatriciaSet[src]

pub fn new() -> Self[src]

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]

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]

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]

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]

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]

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]

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]

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]

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"]);

pub fn iter(&self) -> Iter<'_>

Notable traits for Iter<'a>

impl<'a> Iterator for Iter<'a> type Item = Vec<u8>;
[src]

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()]);

pub fn iter_prefix<'a, 'b>(
    &'a self,
    prefix: &'b [u8]
) -> impl 'a + Iterator<Item = Vec<u8>> where
    'b: 'a, 
[src]

Gets an iterator over the contents having the given prefix 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_prefix(b"ba").collect::<Vec<_>>(), [Vec::from("bar"), "baz".into()]);

Trait Implementations

impl AsRef<Node<()>> for PatriciaSet[src]

impl Clone for PatriciaSet[src]

impl Debug for PatriciaSet[src]

impl Default for PatriciaSet[src]

impl<T: AsRef<[u8]>> Extend<T> for PatriciaSet[src]

impl From<Node<()>> for PatriciaSet[src]

impl From<PatriciaSet> for Node<()>[src]

impl<T: AsRef<[u8]>> FromIterator<T> for PatriciaSet[src]

impl IntoIterator for PatriciaSet[src]

type Item = Vec<u8>

The type of the elements being iterated over.

type IntoIter = IntoIter

Which kind of iterator are we turning this into?

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.