@@ -143,14 +143,20 @@ pub impl BigBitv {
143
143
}
144
144
145
145
#[ inline( always) ]
146
+ #[ cfg( stage0) ]
146
147
fn each_storage ( & mut self , op : & fn ( v : & mut uint ) -> bool ) {
147
148
for uint:: range( 0 , self . storage. len( ) ) |i| {
148
149
let mut w = self . storage [ i] ;
149
150
let b = op ( & mut w) ;
150
151
self . storage [ i] = w;
151
152
if !b { break ; }
152
153
}
153
- }
154
+ }
155
+ #[ inline( always) ]
156
+ #[ cfg( not( stage0) ) ]
157
+ fn each_storage ( & mut self , op : & fn ( v : & mut uint ) -> bool ) -> bool {
158
+ uint:: range ( 0 , self . storage . len ( ) , |i| op ( & mut self . storage [ i] ) )
159
+ }
154
160
155
161
#[ inline( always) ]
156
162
fn invert ( & mut self ) { for self . each_storage |w| { * w = !* w } }
@@ -193,6 +199,7 @@ pub impl BigBitv {
193
199
}
194
200
195
201
#[ inline( always) ]
202
+ #[ cfg( stage0) ]
196
203
fn equals ( & self , b : & BigBitv , nbits : uint ) -> bool {
197
204
let len = b. storage . len ( ) ;
198
205
for uint:: iterate( 0 , len) |i| {
@@ -203,6 +210,19 @@ pub impl BigBitv {
203
210
}
204
211
}
205
212
213
+ #[ inline( always) ]
214
+ #[ cfg( not( stage0) ) ]
215
+ fn equals ( & self , b : & BigBitv , nbits : uint ) -> bool {
216
+ let len = b. storage . len ( ) ;
217
+ for uint:: iterate( 0 , len) |i| {
218
+ let mask = big_mask ( nbits, i) ;
219
+ if mask & self . storage [ i] != mask & b. storage [ i] {
220
+ return false ;
221
+ }
222
+ }
223
+ return true ;
224
+ }
225
+
206
226
}
207
227
208
228
enum BitvVariant { Big ( ~BigBitv ) , Small ( ~SmallBitv ) }
@@ -387,13 +407,24 @@ pub impl Bitv {
387
407
}
388
408
389
409
#[inline(always)]
410
+ #[cfg(stage0)]
390
411
fn each(&self, f: &fn(bool) -> bool) {
391
412
let mut i = 0;
392
413
while i < self.nbits {
393
414
if !f(self.get(i)) { break; }
394
415
i += 1;
395
416
}
396
417
}
418
+ #[inline(always)]
419
+ #[cfg(not(stage0))]
420
+ fn each(&self, f: &fn(bool) -> bool) -> bool {
421
+ let mut i = 0;
422
+ while i < self.nbits {
423
+ if !f(self.get(i)) { return false; }
424
+ i += 1;
425
+ }
426
+ return true;
427
+ }
397
428
398
429
/// Returns true if all bits are 0
399
430
fn is_false(&self) -> bool {
@@ -488,13 +519,18 @@ pub impl Bitv {
488
519
true
489
520
}
490
521
522
+ #[cfg(stage0)]
491
523
fn ones(&self, f: &fn(uint) -> bool) {
492
524
for uint::range(0, self.nbits) |i| {
493
525
if self.get(i) {
494
526
if !f(i) { break }
495
527
}
496
528
}
497
529
}
530
+ #[cfg(not(stage0))]
531
+ fn ones(&self, f: &fn(uint) -> bool) -> bool {
532
+ uint::range(0, self.nbits, |i| !self.get(i) || f(i))
533
+ }
498
534
499
535
}
500
536
@@ -661,18 +697,21 @@ pub impl BitvSet {
661
697
}
662
698
}
663
699
700
+ #[cfg(not(stage0))]
664
701
impl BaseIter<uint> for BitvSet {
665
702
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
666
703
667
- fn each(&self, blk: &fn(v: &uint) -> bool) {
704
+ fn each(&self, blk: &fn(v: &uint) -> bool) -> bool {
668
705
for self.bitv.storage.eachi |i, &w| {
669
706
if !iterate_bits(i * uint::bits, w, |b| blk(&b)) {
670
- return;
707
+ return false ;
671
708
}
672
709
}
710
+ return true;
673
711
}
674
712
}
675
713
714
+ #[cfg(not(stage0))]
676
715
impl cmp::Eq for BitvSet {
677
716
fn eq(&self, other: &BitvSet) -> bool {
678
717
if self.size != other.size {
@@ -706,6 +745,7 @@ impl Mutable for BitvSet {
706
745
}
707
746
}
708
747
748
+ #[cfg(not(stage0))]
709
749
impl Set<uint> for BitvSet {
710
750
fn contains(&self, value: &uint) -> bool {
711
751
*value < self.bitv.storage.len() * uint::bits && self.bitv.get(*value)
@@ -773,64 +813,55 @@ impl Set<uint> for BitvSet {
773
813
other.is_subset(self)
774
814
}
775
815
776
- fn difference(&self, other: &BitvSet, f: &fn(&uint) -> bool) {
816
+ fn difference(&self, other: &BitvSet, f: &fn(&uint) -> bool) -> bool {
777
817
for self.each_common(other) |i, w1, w2| {
778
818
if !iterate_bits(i, w1 & !w2, |b| f(&b)) {
779
- return;
819
+ return false ;
780
820
}
781
821
}
782
822
/* everything we have that they don't also shows up */
783
823
self.each_outlier(other, |mine, i, w|
784
824
!mine || iterate_bits(i, w, |b| f(&b))
785
- );
825
+ )
786
826
}
787
827
788
828
fn symmetric_difference(&self, other: &BitvSet,
789
- f: &fn(&uint) -> bool) {
829
+ f: &fn(&uint) -> bool) -> bool {
790
830
for self.each_common(other) |i, w1, w2| {
791
831
if !iterate_bits(i, w1 ^ w2, |b| f(&b)) {
792
- return;
832
+ return false ;
793
833
}
794
834
}
795
- self.each_outlier(other, |_, i, w|
796
- iterate_bits(i, w, |b| f(&b))
797
- );
835
+ self.each_outlier(other, |_, i, w| iterate_bits(i, w, |b| f(&b)))
798
836
}
799
837
800
- fn intersection(&self, other: &BitvSet, f: &fn(&uint) -> bool) {
801
- for self.each_common(other) |i, w1, w2| {
802
- if !iterate_bits(i, w1 & w2, |b| f(&b)) {
803
- return;
804
- }
805
- }
838
+ fn intersection(&self, other: &BitvSet, f: &fn(&uint) -> bool) -> bool {
839
+ self.each_common(other, |i, w1, w2| iterate_bits(i, w1 & w2, |b| f(&b)))
806
840
}
807
841
808
- fn union(&self, other: &BitvSet, f: &fn(&uint) -> bool) {
842
+ fn union(&self, other: &BitvSet, f: &fn(&uint) -> bool) -> bool {
809
843
for self.each_common(other) |i, w1, w2| {
810
844
if !iterate_bits(i, w1 | w2, |b| f(&b)) {
811
- return;
845
+ return false ;
812
846
}
813
847
}
814
- self.each_outlier(other, |_, i, w|
815
- iterate_bits(i, w, |b| f(&b))
816
- );
848
+ self.each_outlier(other, |_, i, w| iterate_bits(i, w, |b| f(&b)))
817
849
}
818
850
}
819
851
852
+ #[cfg(not(stage0))]
820
853
priv impl BitvSet {
821
854
/// Visits each of the words that the two bit vectors (self and other)
822
855
/// both have in common. The three yielded arguments are (bit location,
823
856
/// w1, w2) where the bit location is the number of bits offset so far,
824
857
/// and w1/w2 are the words coming from the two vectors self, other.
825
858
fn each_common(&self, other: &BitvSet,
826
- f: &fn(uint, uint, uint) -> bool) {
859
+ f: &fn(uint, uint, uint) -> bool) -> bool {
827
860
let min = uint::min(self.bitv.storage.len(),
828
861
other.bitv.storage.len());
829
- for self.bitv.storage.slice(0, min).eachi |i, &w| {
830
- if !f(i * uint::bits, w, other.bitv.storage[i]) {
831
- return;
832
- }
833
- }
862
+ self.bitv.storage.slice(0, min).eachi(|i, &w| {
863
+ f(i * uint::bits, w, other.bitv.storage[i])
864
+ })
834
865
}
835
866
836
867
/// Visits each word in self or other that extends beyond the other. This
@@ -841,22 +872,23 @@ priv impl BitvSet {
841
872
/// is true if the word comes from 'self', and false if it comes from
842
873
/// 'other'.
843
874
fn each_outlier(&self, other: &BitvSet,
844
- f: &fn(bool, uint, uint) -> bool) {
875
+ f: &fn(bool, uint, uint) -> bool) -> bool {
845
876
let len1 = self.bitv.storage.len();
846
877
let len2 = other.bitv.storage.len();
847
878
let min = uint::min(len1, len2);
848
879
849
880
/* only one of these loops will execute and that's the point */
850
881
for self.bitv.storage.slice(min, len1).eachi |i, &w| {
851
882
if !f(true, (i + min) * uint::bits, w) {
852
- return;
883
+ return false ;
853
884
}
854
885
}
855
886
for other.bitv.storage.slice(min, len2).eachi |i, &w| {
856
887
if !f(false, (i + min) * uint::bits, w) {
857
- return;
888
+ return false ;
858
889
}
859
890
}
891
+ return true;
860
892
}
861
893
}
862
894
0 commit comments