Skip to content
Draft
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
17 changes: 5 additions & 12 deletions src/btreemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,14 +698,7 @@ where
}

/// Removes all elements from the map.
#[deprecated(since = "0.6.3", note = "please use `clear_new` instead")]
pub fn clear(self) -> Self {
let mem = self.allocator.into_memory();
Self::new(mem)
}

/// Removes all elements from the map.
pub fn clear_new(&mut self) {
pub fn clear(&mut self) {
self.root_addr = NULL;
self.length = 0;
self.allocator.clear();
Expand Down Expand Up @@ -3221,7 +3214,7 @@ mod test {
}

#[test]
fn test_clear_new_bounded_type() {
fn test_clear_bounded_type() {
let mem = make_memory();
let mut btree: BTreeMap<Blob<4>, Blob<4>, _> = BTreeMap::new(mem.clone());

Expand All @@ -3234,7 +3227,7 @@ mod test {
assert_ne!(btree.allocator.num_allocated_chunks(), 0);
assert_ne!(btree.root_addr, NULL);

btree.clear_new();
btree.clear();

let header_actual = BTreeMap::<Blob<4>, Blob<4>, _>::read_header(&mem);

Expand All @@ -3246,7 +3239,7 @@ mod test {
}

#[test]
fn test_clear_new_unbounded_type() {
fn test_clear_unbounded_type() {
let mem = make_memory();
let mut btree: BTreeMap<String, String, _> = BTreeMap::new(mem.clone());
btree.insert("asd".into(), "bce".into());
Expand All @@ -3255,7 +3248,7 @@ mod test {
assert_ne!(btree.allocator.num_allocated_chunks(), 0);
assert_ne!(btree.root_addr, NULL);

btree.clear_new();
btree.clear();

let header_actual = BTreeMap::<String, String, _>::read_header(&mem);

Expand Down
2 changes: 1 addition & 1 deletion src/btreeset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ where
/// assert!(set.is_empty());
/// ```
pub fn clear(&mut self) {
self.map.clear_new();
self.map.clear();
}

/// Returns the first key in the set. This key
Expand Down
3 changes: 1 addition & 2 deletions tests/api_conformance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ fn api_conformance_btreemap() {
assert_eq!(stable.is_empty(), std.is_empty());

// Clear.
// Note: stable uses clear_new(); std uses clear().
stable.clear_new();
stable.clear();
std.clear();
assert_eq!(stable.len(), std.len() as u64);
assert_eq!(stable.is_empty(), std.is_empty());
Expand Down