Skip to content

Commit

Permalink
Add several APIs to veb
Browse files Browse the repository at this point in the history
  • Loading branch information
ngtkana committed Mar 5, 2024
1 parent fe9bda1 commit c497849
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions libs/veb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,18 @@ impl<V> VebMap<V> {
self.veb.is_empty()
}

/// Returns `true` if the map contains the given key.
/// # Example
/// ```
/// # use veb::VebMap;
/// let veb = VebMap::from_iter(vec![(42, "foo")]);
/// assert_eq!(veb.contains_key(42), true);
/// assert_eq!(veb.contains_key(43), false);
/// ```
pub fn contains_key(&self, i: usize) -> bool {
self.veb.contains(i)
}

/// Returns the elements in the map in ascending order.
/// The elements are collected into a [`Vec`].
/// # Example
Expand All @@ -363,6 +375,18 @@ impl<V> VebMap<V> {
}
}

impl<V> std::ops::Index<usize> for VebMap<V> {
type Output = V;
fn index(&self, i: usize) -> &V {
self.get(i).unwrap()
}
}
impl<V> std::ops::IndexMut<usize> for VebMap<V> {
fn index_mut(&mut self, i: usize) -> &mut V {
self.get_mut(i).unwrap()
}
}

/// A van Emde Boas tree.
pub enum VebSet {
Internal {
Expand Down Expand Up @@ -686,14 +710,12 @@ impl VebSet {
/// ```
pub fn contains(&self, i: usize) -> bool {
match self {
#[allow(unused_variables)]
Self::Internal {
min,
max,
csize,
len,
summary,
chunks,
..
} => {
let j = i / csize;
let k = i % csize;
Expand Down

0 comments on commit c497849

Please sign in to comment.