[−][src]Struct xfast::Xfast
A bitwise trie to store integers.
The values in a X-fast trie are stored at the leaves. An internal node is added to the trie only if it has leaves in its subtree.
Each level of the trie is modelled as a hash map storing the trie nodes at that level.
The range of integers need to be specified while initializing a trie.
Examples
use xfast::Xfast; let mut test_trie: Xfast<&str> = Xfast::new(31); test_trie.insert_key(11, "eleven"); test_trie.insert_key(1, "one"); test_trie.insert_key(5, "five"); assert_eq!(test_trie.len(), 3); let predecessor_3 = test_trie.find_predecessor(3); if predecessor_3.is_some() { let predecessor_value = predecessor_3.unwrap().value.unwrap(); assert_eq!(predecessor_value, "one"); }
Methods
impl<T> Xfast<T>
[src]
pub fn new(range: usize) -> Self
[src]
Creates a new Xfast Trie to store a given range
of integers
Examples
use xfast::Xfast; let mut test_trie: Xfast<&str> = Xfast::new(31);
pub fn len(&self) -> usize
[src]
Returns the count of values stored in the trie
Examples
use xfast::Xfast; let mut test_trie: Xfast<&str> = Xfast::new(31); test_trie.insert_key(11, "eleven"); test_trie.insert_key(1, "one"); assert_eq!(test_trie.len(), 2);
pub fn find_successor(&self, key: usize) -> Option<&TrieNode<T>>
[src]
Returns the smallest node more than or eqaul to the node associated with key
. In case of no such node it returns None.
#Examples
Examples
use xfast::Xfast; let mut test_trie: Xfast<&str> = Xfast::new(31); test_trie.insert_key(11, "eleven"); test_trie.insert_key(1, "one"); test_trie.insert_key(5, "five"); assert_eq!(test_trie.len(), 3); if let Some(successor_3) = test_trie.find_successor(3) { let successor_value = successor_3.value.unwrap(); assert_eq!(successor_value, "five"); } let successor_14 = test_trie.find_successor(14); assert!(successor_14.is_none());
pub fn find_predecessor(&self, key: usize) -> Option<&TrieNode<T>>
[src]
Returns the largest node less that or eqaul to the node with key
. In case of no such node it returns None.
#Examples
Examples
use xfast::Xfast; let mut test_trie: Xfast<&str> = Xfast::new(31); test_trie.insert_key(11, "eleven"); test_trie.insert_key(1, "one"); test_trie.insert_key(5, "five"); assert_eq!(test_trie.len(), 3); if let Some(predecessor_3) = test_trie.find_predecessor(3) { let predecessor_value = predecessor_3.value.unwrap(); assert_eq!(predecessor_value, "one"); } let predecessor_0 = test_trie.find_predecessor(0); assert!(predecessor_0.is_none());
pub fn insert_key(&mut self, key: usize, value: T)
[src]
Insert key
and value
into the trie
Examples
use xfast::Xfast; let mut test_trie: Xfast<&str> = Xfast::new(31); test_trie.insert_key(11, "eleven");
pub fn delete_key(&mut self, key: usize) -> Option<NonNull<TrieNode<T>>>
[src]
Delete a key from the trie. If the node doesn't exist it returns None else retuns the deleted TrieNode
wrapped in a NonNull
struct.
Examples
use xfast::Xfast; let mut test_trie: Xfast<&str> = Xfast::new(31); test_trie.insert_key(11, "eleven"); test_trie.insert_key(1, "one"); test_trie.insert_key(5, "five"); assert_eq!(test_trie.len(), 3); test_trie.delete_key(5); assert_eq!(test_trie.len(), 2); assert!(test_trie.delete_key(2).is_none()); assert_eq!(test_trie.len(), 2);
pub fn find_key(&self, key: usize) -> Option<&TrieNode<T>>
[src]
Find a key in the trie
Examples
use xfast::Xfast; let mut test_trie: Xfast<&str> = Xfast::new(31); test_trie.insert_key(11, "eleven"); test_trie.insert_key(1, "one"); if let Some(node_1) = test_trie.find_key(1) { // all the leaf nodes values have non trivial values and assert is_some. // So unwrapping will not panic assert_eq!(node_1.value.unwrap(), "one"); }
ⓘImportant traits for XfastIter<'a, T>pub fn iter(&self) -> XfastIter<T>
[src]
Returns an iterator around all the key-TrieNode pairs stored in the trie.
Examples
use xfast::Xfast; let mut test_trie: Xfast<&str> = Xfast::new(31); test_trie.insert_key(11, "eleven"); test_trie.insert_key(1, "one"); test_trie.insert_key(19, "nineteen"); for (key, node) in test_trie.iter() { println!("key: {} value: {:?}", key, node); }
ⓘImportant traits for XfastIterMut<'a, T>pub fn iter_mut(&mut self) -> XfastIterMut<T>
[src]
Returns a mutable iterator around all the key-TrieNode pairs stored in the trie.
Examples
use xfast::Xfast; let mut test_trie: Xfast<&str> = Xfast::new(31); test_trie.insert_key(11, "eleven"); test_trie.insert_key(1, "one"); test_trie.insert_key(19, "nineteen"); for (key, node) in test_trie.iter_mut() { if key % 2 == 1 { node.value = Some("updated_odd"); } } if let Some(node_1) = test_trie.find_key(1) { assert_eq!(node_1.value.unwrap(), "updated_odd"); }
Trait Implementations
impl<'a, T> IntoIterator for &'a Xfast<T>
[src]
type Item = (&'a usize, &'a TrieNode<T>)
The type of the elements being iterated over.
type IntoIter = XfastIter<'a, T>
Which kind of iterator are we turning this into?
ⓘImportant traits for XfastIter<'a, T>fn into_iter(self) -> XfastIter<'a, T>
[src]
impl<T: Debug> Debug for Xfast<T>
[src]
Auto Trait Implementations
impl<T = String> !Send for Xfast<T>
impl<T = String> !Sync for Xfast<T>
impl<T> Unpin for Xfast<T>
impl<T> UnwindSafe for Xfast<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> RefUnwindSafe for Xfast<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,