Skip to content

Commit

Permalink
Merge pull request rust-lang#22 from overvenus/is_empty
Browse files Browse the repository at this point in the history
Implement method .is_empty()
  • Loading branch information
bluss authored Mar 23, 2017
2 parents 8e8ef03 + d7ca465 commit ce4f1ec
Showing 1 changed file with 8 additions and 0 deletions.
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

0 comments on commit ce4f1ec

Please sign in to comment.