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
18 changes: 18 additions & 0 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ where
last: CopyCell<Option<&'arena MapNode<'arena, K, V>>>,
}

impl<'arena, K, V> Default for Map<'arena, K, V>
where
K: 'arena,
V: 'arena + Copy,
{
fn default() -> Self {
Self::new()
}
}

impl<'arena, K, V> Map<'arena, K, V>
where
K: 'arena,
Expand Down Expand Up @@ -146,6 +156,14 @@ where
}
}

/// Returns the value corresponding to the key.
#[inline]
pub fn get_key(&self, key: K) -> Option<&K> {
let hash = Self::hash_key(&key);

self.find_slot(key, hash).get().map(|node| &node.key)
}

/// Returns the value corresponding to the key.
#[inline]
pub fn get(&self, key: K) -> Option<V> {
Expand Down
15 changes: 15 additions & 0 deletions src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ pub struct Set<'arena, I: 'arena> {
map: Map<'arena, I, ()>,
}

impl<'arena, I> Default for Set<'arena, I>
where
I: 'arena,
{
fn default() -> Self {
Self::new()
}
}

impl<'arena, I> Set<'arena, I>
where
I: 'arena,
Expand Down Expand Up @@ -55,6 +64,12 @@ where
self.map.insert(arena, item, ());
}

/// Gets a reference to the existing value in the set, if it exists
#[inline]
pub fn get(&self, key: I) -> Option<&I> {
self.map.get_key(key)
}

/// Returns `true` if the set contains a value.
#[inline]
pub fn contains(&self, item: I) -> bool {
Expand Down