Skip to content

Implement method .is_empty() #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2017
Merged
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
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ impl<K, V, S> OrderMap<K, V, S>
/// Computes in **O(1)** time.
pub fn len(&self) -> usize { self.entries.len() }

/// Returns true if the map contains no elements.
///
/// Computes in **O(1)** time.
pub fn is_empty(&self) -> bool { self.len() == 0 }

// Return whether we need 32 or 64 bits to specify a bucket or entry index
#[cfg(not(feature = "test_low_transition_point"))]
fn size_class_is_64bit(&self) -> bool {
Expand Down Expand Up @@ -1466,10 +1471,12 @@ mod tests {
#[test]
fn it_works() {
let mut map = OrderMap::new();
assert_eq!(map.is_empty(), true);
map.insert(1, ());
map.insert(1, ());
assert_eq!(map.len(), 1);
assert!(map.get(&1).is_some());
assert_eq!(map.is_empty(), false);
}

#[test]
Expand All @@ -1478,6 +1485,7 @@ mod tests {
println!("{:?}", map);
assert_eq!(map.capacity(), 0);
assert_eq!(map.len(), 0);
assert_eq!(map.is_empty(), true);
}

#[test]
Expand Down