@@ -18,7 +18,6 @@ use core::fmt;
18
18
19
19
// FIXME(conventions): implement BitXor
20
20
// FIXME(contentions): implement union family of methods? (general design may be wrong here)
21
- // FIXME(conventions): implement len
22
21
23
22
#[ deriving( Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
24
23
/// A specialized `Set` implementation to use enum types.
@@ -92,6 +91,12 @@ impl<E:CLike> EnumSet<E> {
92
91
EnumSet { bits : 0 }
93
92
}
94
93
94
+ /// Returns the number of elements in the given `EnumSet`.
95
+ #[ unstable = "matches collection reform specification, waiting for dust to settle" ]
96
+ pub fn len ( & self ) -> uint {
97
+ self . bits . count_ones ( )
98
+ }
99
+
95
100
/// Returns true if the `EnumSet` is empty.
96
101
#[ unstable = "matches collection reform specification, waiting for dust to settle" ]
97
102
pub fn is_empty ( & self ) -> bool {
@@ -269,6 +274,20 @@ mod test {
269
274
assert_eq ! ( "{A, C}" , e. to_string( ) . as_slice( ) ) ;
270
275
}
271
276
277
+ #[ test]
278
+ fn test_len ( ) {
279
+ let mut e = EnumSet :: new ( ) ;
280
+ assert_eq ! ( e. len( ) , 0 ) ;
281
+ e. insert ( A ) ;
282
+ e. insert ( B ) ;
283
+ e. insert ( C ) ;
284
+ assert_eq ! ( e. len( ) , 3 ) ;
285
+ e. remove ( & A ) ;
286
+ assert_eq ! ( e. len( ) , 2 ) ;
287
+ e. clear ( ) ;
288
+ assert_eq ! ( e. len( ) , 0 ) ;
289
+ }
290
+
272
291
///////////////////////////////////////////////////////////////////////////
273
292
// intersect
274
293
0 commit comments