Skip to content

Commit ce4f1ec

Browse files
authored
Merge pull request rust-lang#22 from overvenus/is_empty
Implement method .is_empty()
2 parents 8e8ef03 + d7ca465 commit ce4f1ec

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,11 @@ impl<K, V, S> OrderMap<K, V, S>
373373
/// Computes in **O(1)** time.
374374
pub fn len(&self) -> usize { self.entries.len() }
375375

376+
/// Returns true if the map contains no elements.
377+
///
378+
/// Computes in **O(1)** time.
379+
pub fn is_empty(&self) -> bool { self.len() == 0 }
380+
376381
// Return whether we need 32 or 64 bits to specify a bucket or entry index
377382
#[cfg(not(feature = "test_low_transition_point"))]
378383
fn size_class_is_64bit(&self) -> bool {
@@ -1466,10 +1471,12 @@ mod tests {
14661471
#[test]
14671472
fn it_works() {
14681473
let mut map = OrderMap::new();
1474+
assert_eq!(map.is_empty(), true);
14691475
map.insert(1, ());
14701476
map.insert(1, ());
14711477
assert_eq!(map.len(), 1);
14721478
assert!(map.get(&1).is_some());
1479+
assert_eq!(map.is_empty(), false);
14731480
}
14741481

14751482
#[test]
@@ -1478,6 +1485,7 @@ mod tests {
14781485
println!("{:?}", map);
14791486
assert_eq!(map.capacity(), 0);
14801487
assert_eq!(map.len(), 0);
1488+
assert_eq!(map.is_empty(), true);
14811489
}
14821490

14831491
#[test]

0 commit comments

Comments
 (0)