@@ -70,7 +70,6 @@ use core::slice;
70
70
use core:: u32;
71
71
use std:: hash;
72
72
73
- use { Mutable , Set , MutableSet , MutableSeq } ;
74
73
use vec:: Vec ;
75
74
76
75
type MatchWords < ' a > = Chain < MaskWords < ' a > , Skip < Take < Enumerate < Repeat < u32 > > > > > ;
@@ -755,6 +754,20 @@ impl Bitv {
755
754
}
756
755
self . set ( insert_pos, elem) ;
757
756
}
757
+
758
+ /// Return the total number of bits in this vector
759
+ #[ inline]
760
+ pub fn len ( & self ) -> uint { self . nbits }
761
+
762
+ /// Returns true if there are no bits in this vector
763
+ #[ inline]
764
+ pub fn is_empty ( & self ) -> bool { self . len ( ) == 0 }
765
+
766
+ /// Clears all bits in this vector.
767
+ #[ inline]
768
+ pub fn clear ( & mut self ) {
769
+ for w in self . storage . iter_mut ( ) { * w = 0u32 ; }
770
+ }
758
771
}
759
772
760
773
/// Transforms a byte-vector into a `Bitv`. Each byte becomes eight bits,
@@ -804,18 +817,6 @@ impl Default for Bitv {
804
817
fn default ( ) -> Bitv { Bitv :: new ( ) }
805
818
}
806
819
807
- impl Collection for Bitv {
808
- #[ inline]
809
- fn len ( & self ) -> uint { self . nbits }
810
- }
811
-
812
- impl Mutable for Bitv {
813
- #[ inline]
814
- fn clear ( & mut self ) {
815
- for w in self . storage . iter_mut ( ) { * w = 0u32 ; }
816
- }
817
- }
818
-
819
820
impl FromIterator < bool > for Bitv {
820
821
fn from_iter < I : Iterator < bool > > ( iterator : I ) -> Bitv {
821
822
let mut ret = Bitv :: new ( ) ;
@@ -1466,61 +1467,45 @@ impl BitvSet {
1466
1467
pub fn symmetric_difference_with ( & mut self , other : & BitvSet ) {
1467
1468
self . other_op ( other, |w1, w2| w1 ^ w2) ;
1468
1469
}
1469
- }
1470
-
1471
- impl fmt:: Show for BitvSet {
1472
- fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
1473
- try!( write ! ( fmt, "{{" ) ) ;
1474
- let mut first = true ;
1475
- for n in self . iter ( ) {
1476
- if !first {
1477
- try!( write ! ( fmt, ", " ) ) ;
1478
- }
1479
- try!( write ! ( fmt, "{}" , n) ) ;
1480
- first = false ;
1481
- }
1482
- write ! ( fmt, "}}" )
1483
- }
1484
- }
1485
1470
1486
- impl < S : hash :: Writer > hash :: Hash < S > for BitvSet {
1487
- fn hash ( & self , state : & mut S ) {
1488
- for pos in self . iter ( ) {
1489
- pos . hash ( state ) ;
1490
- }
1471
+ /// Return the number of set bits in this set.
1472
+ # [ inline ]
1473
+ pub fn len ( & self ) -> uint {
1474
+ let & BitvSet ( ref bitv ) = self ;
1475
+ bitv . storage . iter ( ) . fold ( 0 , |acc , & n| acc + n . count_ones ( ) )
1491
1476
}
1492
- }
1493
1477
1494
- impl Collection for BitvSet {
1478
+ /// Returns whether there are no bits set in this set
1495
1479
#[ inline]
1496
- fn len ( & self ) -> uint {
1480
+ pub fn is_empty ( & self ) -> bool {
1497
1481
let & BitvSet ( ref bitv) = self ;
1498
- bitv. storage . iter ( ) . fold ( 0 , |acc , & n| acc + n . count_ones ( ) )
1482
+ bitv. storage . iter ( ) . all ( | & n| n == 0 )
1499
1483
}
1500
- }
1501
1484
1502
- impl Mutable for BitvSet {
1485
+ /// Clears all bits in this set
1503
1486
#[ inline]
1504
- fn clear ( & mut self ) {
1487
+ pub fn clear ( & mut self ) {
1505
1488
let & BitvSet ( ref mut bitv) = self ;
1506
1489
bitv. clear ( ) ;
1507
1490
}
1508
- }
1509
1491
1510
- impl Set < uint > for BitvSet {
1492
+ /// Returns `true` if this set contains the specified integer.
1511
1493
#[ inline]
1512
- fn contains ( & self , value : & uint ) -> bool {
1494
+ pub fn contains ( & self , value : & uint ) -> bool {
1513
1495
let & BitvSet ( ref bitv) = self ;
1514
1496
* value < bitv. nbits && bitv. get ( * value)
1515
1497
}
1516
1498
1499
+ /// Returns `true` if the set has no elements in common with `other`.
1500
+ /// This is equivalent to checking for an empty intersection.
1517
1501
#[ inline]
1518
- fn is_disjoint ( & self , other : & BitvSet ) -> bool {
1502
+ pub fn is_disjoint ( & self , other : & BitvSet ) -> bool {
1519
1503
self . intersection ( other) . next ( ) . is_none ( )
1520
1504
}
1521
1505
1506
+ /// Returns `true` if the set is a subset of another.
1522
1507
#[ inline]
1523
- fn is_subset ( & self , other : & BitvSet ) -> bool {
1508
+ pub fn is_subset ( & self , other : & BitvSet ) -> bool {
1524
1509
let & BitvSet ( ref self_bitv) = self ;
1525
1510
let & BitvSet ( ref other_bitv) = other;
1526
1511
@@ -1531,14 +1516,15 @@ impl Set<uint> for BitvSet {
1531
1516
self_bitv. mask_words ( other_bitv. storage . len ( ) ) . all ( |( _, w) | w == 0 )
1532
1517
}
1533
1518
1519
+ /// Returns `true` if the set is a superset of another.
1534
1520
#[ inline]
1535
- fn is_superset ( & self , other : & BitvSet ) -> bool {
1521
+ pub fn is_superset ( & self , other : & BitvSet ) -> bool {
1536
1522
other. is_subset ( self )
1537
1523
}
1538
- }
1539
1524
1540
- impl MutableSet < uint > for BitvSet {
1541
- fn insert ( & mut self , value : uint ) -> bool {
1525
+ /// Adds a value to the set. Returns `true` if the value was not already
1526
+ /// present in the set.
1527
+ pub fn insert ( & mut self , value : uint ) -> bool {
1542
1528
if self . contains ( & value) {
1543
1529
return false ;
1544
1530
}
@@ -1554,7 +1540,9 @@ impl MutableSet<uint> for BitvSet {
1554
1540
return true ;
1555
1541
}
1556
1542
1557
- fn remove ( & mut self , value : & uint ) -> bool {
1543
+ /// Removes a value from the set. Returns `true` if the value was
1544
+ /// present in the set.
1545
+ pub fn remove ( & mut self , value : & uint ) -> bool {
1558
1546
if !self . contains ( value) {
1559
1547
return false ;
1560
1548
}
@@ -1564,6 +1552,29 @@ impl MutableSet<uint> for BitvSet {
1564
1552
}
1565
1553
}
1566
1554
1555
+ impl fmt:: Show for BitvSet {
1556
+ fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
1557
+ try!( write ! ( fmt, "{{" ) ) ;
1558
+ let mut first = true ;
1559
+ for n in self . iter ( ) {
1560
+ if !first {
1561
+ try!( write ! ( fmt, ", " ) ) ;
1562
+ }
1563
+ try!( write ! ( fmt, "{}" , n) ) ;
1564
+ first = false ;
1565
+ }
1566
+ write ! ( fmt, "}}" )
1567
+ }
1568
+ }
1569
+
1570
+ impl < S : hash:: Writer > hash:: Hash < S > for BitvSet {
1571
+ fn hash ( & self , state : & mut S ) {
1572
+ for pos in self . iter ( ) {
1573
+ pos. hash ( state) ;
1574
+ }
1575
+ }
1576
+ }
1577
+
1567
1578
/// An iterator for `BitvSet`.
1568
1579
pub struct BitPositions < ' a > {
1569
1580
set : & ' a BitvSet ,
@@ -1643,7 +1654,6 @@ mod tests {
1643
1654
use std:: rand:: Rng ;
1644
1655
use test:: Bencher ;
1645
1656
1646
- use { Set , Mutable , MutableSet , MutableSeq } ;
1647
1657
use bitv:: { Bitv , BitvSet , from_fn, from_bytes} ;
1648
1658
use bitv;
1649
1659
use vec:: Vec ;
0 commit comments