Skip to main content

PrefixOpsExt

Trait PrefixOpsExt 

Source
pub trait PrefixOpsExt: PrefixOps {
    // Provided methods
    fn supersets_prefix(&self, idx: BaseIndex) -> bool { ... }
    fn lookup(&self, idx: BaseIndex) -> Option<&Self::T> { ... }
    fn with_prefix(self, idx: BaseIndex, value: Self::T) -> Self
       where Self: Sized { ... }
    fn matching_prefixes(&self, octet: u8) -> NodePrefixIter<'_, Self::T>
       where Self: Sized { ... }
}
Expand description

Extension methods relating to prefixes.

Provided Methods§

Source

fn supersets_prefix(&self, idx: BaseIndex) -> bool

Report whether this node’s prefix set covers the prefix with the given index. It does not need to match exactly, idx just needs to be contained in this node’s prefix set.

§Examples
let idx = BaseIndex::from_prefix(0, 2);
let node = DefaultNode::EMPTY.with_prefix(idx, 32);
assert!(node.supersets_prefix(idx)); // exact match
// parent is not contained
assert!(!node.supersets_prefix(idx.parent().unwrap()));
// child indexes are contained
let (child1, child2) = idx.children().unwrap();
assert!(node.supersets_prefix(child1));
assert!(node.supersets_prefix(child2));
Source

fn lookup(&self, idx: BaseIndex) -> Option<&Self::T>

Lookup a value by BaseIndex.

This is sugar over PrefixReadOps::lookup_index to only return the matched value.

Source

fn with_prefix(self, idx: BaseIndex, value: Self::T) -> Self
where Self: Sized,

Return this node with the given prefix added.

Sugar for easily constructing nodes directly.

§Examples
let idx = BaseIndex::from_prefix(1, 1);
let node = DefaultNode::EMPTY.with_prefix(idx, 12);
assert_eq!(node.get_prefix_exact(idx).copied(), Some(12));
Source

fn matching_prefixes(&self, octet: u8) -> NodePrefixIter<'_, Self::T>
where Self: Sized,

Iterate prefixes in this node matching octet.

The prefixes are returned in reverse order (most specific to least specific).

§Examples
let zero_pfx = BaseIndex::from_prefix(0, 0);
let second_half_pfx = BaseIndex::from_prefix(128, 1);

let node = ts_bart::DefaultNode::EMPTY
    .with_prefix(zero_pfx, 123)
    .with_prefix(second_half_pfx, 456);

assert_eq!(vec![(zero_pfx, &123)], node.matching_prefixes(1).collect::<Vec<_>>());
assert_eq!(vec![(second_half_pfx, &456), (zero_pfx, &123)], node.matching_prefixes(200).collect::<Vec<_>>());

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T> PrefixOpsExt for T
where T: PrefixOps + ?Sized,