[−][src]Struct ip_network_table_deps_treebitmap::IpLookupTable
A fast, compressed IP lookup table.
Methods
impl<A, T> IpLookupTable<A, T> where
A: Address,
[src]
A: Address,
pub fn new() -> Self
[src]
Initialize an empty lookup table with no preallocation.
pub fn with_capacity(n: usize) -> Self
[src]
Initialize an empty lookup table with pre-allocated buffers.
pub fn mem_usage(&self) -> (usize, usize)
[src]
Return the bytes used by nodes and results.
pub fn len(&self) -> usize
[src]
Return number of items inside table.
pub fn is_empty(&self) -> bool
[src]
Return true
if no item is inside table.
pub fn insert(&mut self, ip: A, masklen: u32, value: T) -> Option<T>
[src]
Insert a value for the prefix designated by ip and masklen. If prefix existed previously, the old value is returned.
Panics
Panics if prefix has bits set to the right of mask.
Examples
use treebitmap::IpLookupTable; use std::net::Ipv6Addr; let mut table = IpLookupTable::new(); let prefix = Ipv6Addr::new(0x2001, 0xdb8, 0xdead, 0xbeef, 0, 0, 0, 0); let masklen = 32; assert_eq!(table.insert(prefix, masklen, "foo"), None); // Insert duplicate assert_eq!(table.insert(prefix, masklen, "bar"), Some("foo"));
pub fn remove(&mut self, ip: A, masklen: u32) -> Option<T>
[src]
Remove an entry from the lookup table. If the prefix existed previously, the value is returned.
Examples
use treebitmap::IpLookupTable; use std::net::Ipv6Addr; let mut table = IpLookupTable::new(); let prefix = Ipv6Addr::new(0x2001, 0xdb8, 0xdead, 0xbeef, 0, 0, 0, 0); let masklen = 32; table.insert(prefix, masklen, "foo"); assert_eq!(table.remove(prefix, masklen), Some("foo")); // Remove non-existant assert_eq!(table.remove(prefix, masklen), None);
pub fn exact_match(&self, ip: A, masklen: u32) -> Option<&T>
[src]
Perform exact match lookup of ip
/masklen
and return the
value.
Panics
Panics if prefix has bits set to the right of mask.
Examples
use treebitmap::IpLookupTable; use std::net::Ipv6Addr; let mut table = IpLookupTable::new(); let prefix = Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0); let masklen = 32; table.insert(prefix, masklen, "foo"); assert_eq!(table.exact_match(prefix, masklen), Some(&"foo")); // differing mask assert_eq!(table.exact_match(prefix, 48), None);
pub fn exact_match_mut(&mut self, ip: A, masklen: u32) -> Option<&mut T>
[src]
Perform exact match lookup of ip
/masklen
and return the
value as mutable.
Examples
use treebitmap::IpLookupTable; use std::net::Ipv6Addr; let mut table = IpLookupTable::new(); let prefix = Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0); let masklen = 32; table.insert(prefix, masklen, "foo"); assert_eq!(table.exact_match(prefix, masklen), Some(&"foo")); // Mutate value if let Some(value) = table.exact_match_mut(prefix, masklen) { *value = &"bar"; } // Get new value assert_eq!(table.exact_match(prefix, masklen), Some(&"bar"));
pub fn longest_match(&self, ip: A) -> Option<(A, u32, &T)>
[src]
Perform longest match lookup of ip
and return the best matching
prefix, designated by ip, masklen, along with its value.
Example
use treebitmap::IpLookupTable; use std::net::Ipv6Addr; let mut table = IpLookupTable::new(); let less_specific = Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0); let more_specific = Ipv6Addr::new(0x2001, 0xdb8, 0xdead, 0, 0, 0, 0, 0); table.insert(less_specific, 32, "foo"); table.insert(more_specific, 48, "bar"); let lookupip = Ipv6Addr::new(0x2001, 0xdb8, 0xdead, 0xbeef, 0xcafe, 0xbabe, 0, 1); let result = table.longest_match(lookupip); assert_eq!(result, Some((more_specific, 48, &"bar"))); let lookupip = Ipv6Addr::new(0x2001, 0xdb8, 0xcafe, 0xf00, 0xf00, 0xf00, 0, 1); let result = table.longest_match(lookupip); assert_eq!(result, Some((less_specific, 32, &"foo")));
pub fn longest_match_mut(&mut self, ip: A) -> Option<(A, u32, &mut T)>
[src]
Perform longest match lookup of ip
and return the best matching
prefix, designated by ip, masklen, along with its value as mutable.
Example
use treebitmap::IpLookupTable; use std::net::Ipv6Addr; let mut table = IpLookupTable::new(); let less_specific = Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0); let more_specific = Ipv6Addr::new(0x2001, 0xdb8, 0xdead, 0, 0, 0, 0, 0); table.insert(less_specific, 32, "foo"); table.insert(more_specific, 48, "bar"); let lookupip = Ipv6Addr::new(0x2001, 0xdb8, 0xdead, 0xbeef, 0xcafe, 0xbabe, 0, 1); if let Some((_, _, value)) = table.longest_match_mut(lookupip) { assert_eq!(value, &"bar"); *value = &"foo"; } let result = table.longest_match(lookupip); assert_eq!(result, Some((more_specific, 48, &"foo")));
pub fn matches(&self, ip: A) -> impl Iterator<Item = (A, u32, &T)>
[src]
Perform match lookup of ip
and return the all matching
prefixes, designated by ip, masklen, along with its value.
Example
use treebitmap::IpLookupTable; use std::net::Ipv6Addr; let mut table = IpLookupTable::new(); let less_specific = Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0); let more_specific = Ipv6Addr::new(0x2001, 0xdb8, 0xdead, 0, 0, 0, 0, 0); table.insert(less_specific, 32, "foo"); table.insert(more_specific, 48, "bar"); let lookupip = Ipv6Addr::new(0x2001, 0xdb8, 0xdead, 0xbeef, 0xcafe, 0xbabe, 0, 1); let matches = table.matches(lookupip); assert_eq!(matches.count(), 2); let lookupip = Ipv6Addr::new(0x2001, 0xdb8, 0xcafe, 0xf00, 0xf00, 0xf00, 0, 1); let matches = table.matches(lookupip); assert_eq!(matches.count(), 1);
pub fn matches_mut(&mut self, ip: A) -> impl Iterator<Item = (A, u32, &mut T)>
[src]
Perform match lookup of ip
and return the all matching
prefixes, designated by ip, masklen, along with its mutable value.
pub fn iter(&self) -> Iter<A, T>
[src]
Returns iterator over prefixes and values.
Examples
use treebitmap::IpLookupTable; use std::net::Ipv6Addr; let mut table = IpLookupTable::new(); let less_specific = Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0); let more_specific = Ipv6Addr::new(0x2001, 0xdb8, 0xdead, 0, 0, 0, 0, 0); table.insert(less_specific, 32, "foo"); table.insert(more_specific, 48, "bar"); let mut iter = table.iter(); assert_eq!(iter.next(), Some((less_specific, 32, &"foo"))); assert_eq!(iter.next(), Some((more_specific, 48, &"bar"))); assert_eq!(iter.next(), None);
pub fn iter_mut(&mut self) -> IterMut<A, T>
[src]
Mutable version of iter().
Examples
use treebitmap::IpLookupTable; use std::net::Ipv6Addr; let x: Ipv6Addr = "2001:db8:100::".parse().unwrap(); let y: Ipv6Addr = "2001:db8:100::".parse().unwrap(); let z: Ipv6Addr = "2001:db8:102::".parse().unwrap(); let mut table = IpLookupTable::new(); table.insert(x, 48, 1); table.insert(y, 56, 2); table.insert(z, 56, 3); for (_ip, _mask, val) in table.iter_mut() { *val += 10; } assert_eq!(table.exact_match(x, 48), Some(&11)); assert_eq!(table.exact_match(y, 56), Some(&12)); assert_eq!(table.exact_match(z, 56), Some(&13));
Trait Implementations
impl<A, T> Default for IpLookupTable<A, T> where
A: Address,
[src]
A: Address,
impl<A, T> IntoIterator for IpLookupTable<A, T> where
A: Address,
[src]
A: Address,
Auto Trait Implementations
impl<A, T> RefUnwindSafe for IpLookupTable<A, T> where
A: RefUnwindSafe,
T: RefUnwindSafe,
A: RefUnwindSafe,
T: RefUnwindSafe,
impl<A, T> Send for IpLookupTable<A, T> where
A: Send,
T: Send,
A: Send,
T: Send,
impl<A, T> Sync for IpLookupTable<A, T> where
A: Sync,
T: Sync,
A: Sync,
T: Sync,
impl<A, T> Unpin for IpLookupTable<A, T> where
A: Unpin,
A: Unpin,
impl<A, T> UnwindSafe for IpLookupTable<A, T> where
A: UnwindSafe,
T: RefUnwindSafe,
A: UnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
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> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
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?
fn into_iter(self) -> I
[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>,