Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub use address::addr::*;
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
)]
#[cfg_attr(feature = "bytecheck", archive_attr(derive(rkyv::CheckBytes)))]
pub struct IpLookupTable<A, T: Clone + Copy + Default> {
pub struct IpLookupTable<A, T> {
inner: TreeBitmap<T>,
_addrtype: PhantomData<A>,
}
Expand Down Expand Up @@ -424,23 +424,23 @@ where
/// Iterator over prefixes and associated values. The prefixes are returned in
/// "tree"-order.
#[doc(hidden)]
pub struct Iter<'a, A, T: 'a + Clone + Copy + Default> {
pub struct Iter<'a, A, T: 'a> {
inner: tree_bitmap::Iter<'a, T>,
_addrtype: PhantomData<A>,
}

/// Mutable iterator over prefixes and associated values. The prefixes are
/// returned in "tree"-order.
#[doc(hidden)]
pub struct IterMut<'a, A, T: 'a + Clone + Copy + Default> {
pub struct IterMut<'a, A, T: 'a> {
inner: tree_bitmap::IterMut<'a, T>,
_addrtype: PhantomData<A>,
}

/// Converts ```IpLookupTable``` into an iterator. The prefixes are returned in
/// "tree"-order.
#[doc(hidden)]
pub struct IntoIter<A, T: Clone + Copy + Default> {
pub struct IntoIter<A, T> {
inner: tree_bitmap::IntoIter<T>,
_addrtype: PhantomData<A>,
}
2 changes: 1 addition & 1 deletion src/tree_bitmap/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub fn choose_bucket(len: u32) -> u32 {
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
)]
#[cfg_attr(feature = "bytecheck", archive_attr(derive(rkyv::CheckBytes)))]
pub struct Allocator<T: Sized + Clone + Copy + Default> {
pub struct Allocator<T: Sized> {
pub(crate) buckets: [BucketVec<T>; 9],
}

Expand Down
14 changes: 7 additions & 7 deletions src/tree_bitmap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use self::node::{MatchResult, Node};
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
)]
#[cfg_attr(feature = "bytecheck", archive_attr(derive(rkyv::CheckBytes)))]
pub struct TreeBitmap<T: Sized + Clone + Copy + Default> {
pub struct TreeBitmap<T: Sized> {
trienodes: Allocator<Node>,
results: Allocator<T>,
len: usize,
Expand Down Expand Up @@ -391,13 +391,13 @@ struct PathElem {
pos: usize,
}

pub struct Iter<'a, T: 'a + Clone + Copy + Default> {
pub struct Iter<'a, T: 'a> {
inner: &'a TreeBitmap<T>,
path: Vec<PathElem>,
nibbles: Vec<u8>,
}

pub struct IterMut<'a, T: 'a + Clone + Copy + Default> {
pub struct IterMut<'a, T: 'a> {
inner: &'a mut TreeBitmap<T>,
path: Vec<PathElem>,
nibbles: Vec<u8>,
Expand All @@ -413,7 +413,7 @@ static PREFIX_OF_BIT: [u8; 32] = [// 0 1 2 3 4 5
// 24 25 26 27 28 29 30 31
0b1000, 0b1001, 0b1010, 0b1011, 0b1100, 0b1101, 0b1110, 0b1111];

fn next<T: Sized + Clone + Copy + Default>(
fn next<T: Sized>(
trie: &TreeBitmap<T>,
path: &mut Vec<PathElem>,
nibbles: &mut Vec<u8>,
Expand Down Expand Up @@ -488,7 +488,7 @@ impl<'a, T: 'a + Clone + Copy + Default> Iterator for IterMut<'a, T> {
}
}

pub struct IntoIter<T: Clone + Copy + Default> {
pub struct IntoIter<T> {
inner: TreeBitmap<T>,
path: Vec<PathElem>,
nibbles: Vec<u8>,
Expand Down Expand Up @@ -526,7 +526,7 @@ impl<T: Clone + Copy + Default> IntoIterator for TreeBitmap<T> {
}
}

pub struct MatchesMut<'a, T: 'a + Clone + Copy + Default> {
pub struct MatchesMut<'a, T: 'a> {
inner: &'a mut TreeBitmap<T>,
path: std::vec::IntoIter<(u32, AllocatorHandle, u32)>,
}
Expand All @@ -546,7 +546,7 @@ impl<'a, T: 'a + Clone + Copy + Default> Iterator for MatchesMut<'a, T> {
}
}

impl<T: Clone + Copy + Default> TrieAccess for TreeBitmap<T> {
impl<T> TrieAccess for TreeBitmap<T> {
fn get_node(&self, hdl: &AllocatorHandle, index: u32) -> Node {
*self.trienodes.get(&hdl, index)
}
Expand Down
38 changes: 21 additions & 17 deletions src/tree_bitmap/rkyv_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,26 @@ mod tests {

let ip_2 = Ipv6Addr::new(0x2001, 0xdb8, 0xcafe, 0xf00, 0xf00, 0xf00, 0, 1);
assert_eq!(table.longest_match(ip_2), Some((less_specific, 32, &123)));

let rkyv_bytes = rkyv::to_bytes::<_, 1024>(&table).unwrap();
let rkyv_table =
rkyv::check_archived_root::<IpLookupTable<Ipv6Addr, i32>>(&rkyv_bytes).unwrap();

assert!(!rkyv_table.is_empty());
assert_eq!(rkyv_table.len(), 2);

assert_eq!(rkyv_table.exact_match(ip_1, 48), Some(&321));
assert_eq!(
rkyv_table.longest_match(ip_1),
Some((more_specific, 48, &321))
);
assert_eq!(
rkyv_table.longest_match(ip_2),
Some((less_specific, 32, &123))
);
rkyv::to_bytes::<_, 1024>(&table).unwrap();

#[cfg(feature = "bytecheck")]
{
let rkyv_bytes = rkyv::to_bytes::<_, 1024>(&table).unwrap();
let rkyv_table =
rkyv::check_archived_root::<IpLookupTable<Ipv6Addr, i32>>(&rkyv_bytes).unwrap();

assert!(!rkyv_table.is_empty());
assert_eq!(rkyv_table.len(), 2);

assert_eq!(rkyv_table.exact_match(ip_1, 48), Some(&321));
assert_eq!(
rkyv_table.longest_match(ip_1),
Some((more_specific, 48, &321))
);
assert_eq!(
rkyv_table.longest_match(ip_2),
Some((less_specific, 32, &123))
);
}
}
}