Skip to content

Commit

Permalink
#7 clear()
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Apr 17, 2023
1 parent af29764 commit 605a354
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ impl<K: Copy + PartialEq, V: Clone + Copy, const N: usize> Map<K, V, N> {
}
None
}

/// Remove all pairs from it, but keep the space intact for future use.
#[inline]
pub fn clear(&mut self) {
self.next = 0;
}
}

#[cfg(test)]
Expand Down Expand Up @@ -298,3 +304,12 @@ fn large_map_in_heap() -> Result<()> {
assert_eq!(0, m.len());
Ok(())
}

#[test]
fn clears_it_up() -> Result<()> {
let mut m: Map<&str, i32, 10> = Map::new();
m.insert("one", 42);
m.clear();
assert_eq!(0, m.len());
Ok(())
}

0 comments on commit 605a354

Please sign in to comment.