Skip to content

Commit b5c54df

Browse files
committed
collections::bitv: Add documentation and #[inline]'s
Add documentation to methods on BitvSet that were missing them. Also make sure #[inline] is on all methods that are (a) one-liners or (b) private methods whose only purpose is code deduplication.
1 parent a7f335a commit b5c54df

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/libcollections/bitv.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct MaskWords<'a> {
6868

6969
impl<'a> Iterator<(uint, uint)> for MaskWords<'a> {
7070
/// Returns (offset, word)
71+
#[inline]
7172
fn next<'a>(&'a mut self) -> Option<(uint, uint)> {
7273
let ret = self.next_word;
7374
match ret {
@@ -347,6 +348,7 @@ pub fn from_fn(len: uint, f: |index: uint| -> bool) -> Bitv {
347348
}
348349

349350
impl ops::Index<uint,bool> for Bitv {
351+
#[inline]
350352
fn index(&self, i: &uint) -> bool {
351353
self.get(*i)
352354
}
@@ -453,23 +455,27 @@ impl Default for BitvSet {
453455

454456
impl BitvSet {
455457
/// Creates a new bit vector set with initially no contents
458+
#[inline]
456459
pub fn new() -> BitvSet {
457460
BitvSet(Bitv::new(0, false))
458461
}
459462

460463
/// Creates a new bit vector set from the given bit vector
464+
#[inline]
461465
pub fn from_bitv(bitv: Bitv) -> BitvSet {
462466
BitvSet(bitv)
463467
}
464468

465469
/// Returns the capacity in bits for this bit vector. Inserting any
466470
/// element less than this amount will not trigger a resizing.
471+
#[inline]
467472
pub fn capacity(&self) -> uint {
468473
let &BitvSet(ref bitv) = self;
469474
bitv.storage.len() * uint::BITS
470475
}
471476

472477
/// Consumes this set to return the underlying bit vector
478+
#[inline]
473479
pub fn unwrap(self) -> Bitv {
474480
let BitvSet(bitv) = self;
475481
bitv
@@ -515,29 +521,37 @@ impl BitvSet {
515521
}
516522

517523
/// Union in-place with the specified other bit vector
524+
#[inline]
518525
pub fn union_with(&mut self, other: &BitvSet) {
519526
self.other_op(other, |w1, w2| w1 | w2);
520527
}
521528

522529
/// Intersect in-place with the specified other bit vector
530+
#[inline]
523531
pub fn intersect_with(&mut self, other: &BitvSet) {
524532
self.other_op(other, |w1, w2| w1 & w2);
525533
}
526534

527535
/// Difference in-place with the specified other bit vector
536+
#[inline]
528537
pub fn difference_with(&mut self, other: &BitvSet) {
529538
self.other_op(other, |w1, w2| w1 & !w2);
530539
}
531540

532541
/// Symmetric difference in-place with the specified other bit vector
542+
#[inline]
533543
pub fn symmetric_difference_with(&mut self, other: &BitvSet) {
534544
self.other_op(other, |w1, w2| w1 ^ w2);
535545
}
536546

547+
/// Iterator over each uint stored in the BitvSet
548+
#[inline]
537549
pub fn iter<'a>(&'a self) -> BitPositions<'a> {
538550
BitPositions {set: self, next_idx: 0}
539551
}
540552

553+
/// Iterator over each uint stored in the `self` setminus `other`
554+
#[inline]
541555
pub fn difference<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions<'a> {
542556
TwoBitPositions {
543557
set: self,
@@ -548,6 +562,8 @@ impl BitvSet {
548562
}
549563
}
550564

565+
/// Iterator over each uint stored in the symmetric difference of `self` and `other`
566+
#[inline]
551567
pub fn symmetric_difference<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions<'a> {
552568
TwoBitPositions {
553569
set: self,
@@ -558,6 +574,8 @@ impl BitvSet {
558574
}
559575
}
560576

577+
/// Iterator over each uint stored in `self` intersect `other`
578+
#[inline]
561579
pub fn intersection<'a>(&'a self, other: &'a BitvSet) -> Take<TwoBitPositions<'a>> {
562580
let min = cmp::min(self.capacity(), other.capacity());
563581
TwoBitPositions {
@@ -569,6 +587,8 @@ impl BitvSet {
569587
}.take(min)
570588
}
571589

590+
/// Iterator over each uint stored in `self` union `other`
591+
#[inline]
572592
pub fn union<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions<'a> {
573593
TwoBitPositions {
574594
set: self,
@@ -612,18 +632,21 @@ impl Collection for BitvSet {
612632
}
613633

614634
impl Mutable for BitvSet {
635+
#[inline]
615636
fn clear(&mut self) {
616637
let &BitvSet(ref mut bitv) = self;
617638
bitv.clear();
618639
}
619640
}
620641

621642
impl Set<uint> for BitvSet {
643+
#[inline]
622644
fn contains(&self, value: &uint) -> bool {
623645
let &BitvSet(ref bitv) = self;
624646
*value < bitv.nbits && bitv.get(*value)
625647
}
626648

649+
#[inline]
627650
fn is_disjoint(&self, other: &BitvSet) -> bool {
628651
self.intersection(other).count() > 0
629652
}
@@ -647,6 +670,7 @@ impl Set<uint> for BitvSet {
647670
return true;
648671
}
649672

673+
#[inline]
650674
fn is_superset(&self, other: &BitvSet) -> bool {
651675
other.is_subset(self)
652676
}
@@ -737,7 +761,6 @@ pub struct TwoBitPositions<'a> {
737761
}
738762

739763
impl<'a> Iterator<uint> for BitPositions<'a> {
740-
#[inline]
741764
fn next(&mut self) -> Option<uint> {
742765
while self.next_idx < self.set.capacity() {
743766
let idx = self.next_idx;
@@ -751,13 +774,13 @@ impl<'a> Iterator<uint> for BitPositions<'a> {
751774
return None;
752775
}
753776

777+
#[inline]
754778
fn size_hint(&self) -> (uint, Option<uint>) {
755779
(0, Some(self.set.capacity() - self.next_idx))
756780
}
757781
}
758782

759783
impl<'a> Iterator<uint> for TwoBitPositions<'a> {
760-
#[inline]
761784
fn next(&mut self) -> Option<uint> {
762785
while self.next_idx < self.set.capacity() ||
763786
self.next_idx < self.other.capacity() {
@@ -785,6 +808,7 @@ impl<'a> Iterator<uint> for TwoBitPositions<'a> {
785808
return None;
786809
}
787810

811+
#[inline]
788812
fn size_hint(&self) -> (uint, Option<uint>) {
789813
let cap = cmp::max(self.set.capacity(), self.other.capacity());
790814
(0, Some(cap - self.next_idx))

0 commit comments

Comments
 (0)