Skip to content

Commit 4a79493

Browse files
committed
minor improvements
1 parent 34c734c commit 4a79493

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/bitmap.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ where
3434
}
3535
}
3636

37+
/// Returns the index of the entry attributed to the given leaf id using leafvec optimization.
38+
/// Will be the same as `bitmap_index` when the id is not set.
39+
/// Apparently it's slightly slower than `bitmap_index`.
40+
#[inline(always)] // Particularly effective to inline
41+
pub(crate) fn leafvec_index(&self, id: T) -> u32 {
42+
(self.bits << (63u8 - id.into())).count_ones() - 1
43+
}
44+
3745
/// Returns true if the bitmap contains the given ID.
3846
#[inline(always)]
3947
pub(crate) fn contains(&self, id: T) -> bool {
@@ -53,15 +61,6 @@ where
5361
}
5462
}
5563

56-
impl Bitmap<StrideId> {
57-
/// Returns the index of leaf attributed to the given `LeafId` using leafvec optimization
58-
// Actually slower than `bitmap_index`
59-
#[inline(always)] // Particularly effective to inline
60-
pub(crate) fn leafvec_index(&self, id: StrideId) -> u32 {
61-
(self.bits << (63u8 - id.0)).count_ones() - 1
62-
}
63-
}
64-
6564
/// A unique identifier for a prefix in the poptrie.
6665
///
6766
/// The ID is a mapping of the last segment of the prefix, i.e. the last "stride", including the valid length.

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const STRIDE: u8 = 6;
5757
/// assert_eq!(trie.lookup(u32::from_be_bytes([10, 1, 2, 3])), Some(&"10.0.0.0/8"));
5858
/// assert_eq!(trie.lookup(u32::from_be_bytes([8, 8, 8, 8])), None);
5959
/// ```
60+
#[derive(Debug, Clone)]
6061
pub struct Poptrie<K, V>
6162
where
6263
K: Key,

tests/api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,13 @@ fn insert_order_does_not_affect_lpm() {
309309
reverse.insert(0b000001_000001_000000_000000_000000_00u32, 12, 12);
310310
reverse.insert(0b000001_000000_000000_000000_000000_00u32, 6, 6);
311311

312-
let probes = [
312+
let lookups = [
313313
0b000001_000001_000001_111111_000000_00u32,
314314
0b000001_000001_000010_000000_000000_00u32,
315315
0b000001_000010_000000_000000_000000_00u32,
316316
0b000010_000000_000000_000000_000000_00u32,
317317
];
318-
for addr in probes {
318+
for addr in lookups {
319319
assert_eq!(forward.lookup(addr), reverse.lookup(addr),);
320320
}
321321
}

0 commit comments

Comments
 (0)