25
25
//!
26
26
//! // Store the primes as a BitvSet
27
27
//! let primes = {
28
+ //! // Assume all numbers are prime to begin, and then we
29
+ //! // cross off non-primes progressively
28
30
//! let mut bv = Bitv::with_capacity(max_prime, true);
29
31
//!
30
32
//! // Neither 0 nor 1 are prime
33
35
//!
34
36
//! for i in range(2, max_prime) {
35
37
//! // if i is a prime
36
- //! if bv.get(i) {
37
- //! // mark all multiples of i as non-prime (any multiples below i * i
38
+ //! if bv[i] {
39
+ //! // Mark all multiples of i as non-prime (any multiples below i * i
38
40
//! // will have been marked as non-prime previously)
39
41
//! for j in iter::range_step(i * i, max_prime, i) { bv.set(j, false) }
40
42
//! }
@@ -252,6 +254,9 @@ impl Bitv {
252
254
/// let bv: Bitv = [false, true].iter().map(|n| *n).collect();
253
255
/// assert_eq!(bv.get(0), false);
254
256
/// assert_eq!(bv.get(1), true);
257
+ ///
258
+ /// // Can also use array indexing
259
+ /// assert_eq!(bv[1], true);
255
260
/// ```
256
261
#[ inline]
257
262
pub fn get ( & self , i : uint ) -> bool {
@@ -275,7 +280,7 @@ impl Bitv {
275
280
///
276
281
/// let mut bv = Bitv::with_capacity(5, false);
277
282
/// bv.set(3, true);
278
- /// assert_eq!(bv.get(3) , true);
283
+ /// assert_eq!(bv[3] , true);
279
284
/// ```
280
285
#[ inline]
281
286
pub fn set ( & mut self , i : uint , x : bool ) {
@@ -478,7 +483,7 @@ impl Bitv {
478
483
/// Organise the bits into bytes, such that the first bit in the
479
484
/// `Bitv` becomes the high-order bit of the first byte. If the
480
485
/// size of the `Bitv` is not a multiple of 8 then trailing bits
481
- /// will be filled-in with false/0 .
486
+ /// will be filled-in with ` false` .
482
487
///
483
488
/// # Example
484
489
///
@@ -716,9 +721,9 @@ impl Bitv {
716
721
/// # Example
717
722
///
718
723
/// ```
719
- /// use std::collections::bitv::from_bytes ;
724
+ /// use std::collections::bitv;
720
725
///
721
- /// let bv = from_bytes([0b10100000, 0b00010010]);
726
+ /// let bv = bitv:: from_bytes([0b10100000, 0b00010010]);
722
727
/// assert!(bv.eq_vec([true, false, true, false,
723
728
/// false, false, false, false,
724
729
/// false, false, false, true,
@@ -898,7 +903,7 @@ impl<'a> RandomAccessIterator<bool> for Bits<'a> {
898
903
///
899
904
/// ```
900
905
/// use std::collections::{BitvSet, Bitv};
901
- /// use std::collections::bitv::from_bytes ;
906
+ /// use std::collections::bitv;
902
907
///
903
908
/// // It's a regular set
904
909
/// let mut s = BitvSet::new();
@@ -913,7 +918,7 @@ impl<'a> RandomAccessIterator<bool> for Bits<'a> {
913
918
/// }
914
919
///
915
920
/// // Can initialize from a `Bitv`
916
- /// let other = BitvSet::from_bitv(from_bytes([0b11010000]));
921
+ /// let other = BitvSet::from_bitv(bitv:: from_bytes([0b11010000]));
917
922
///
918
923
/// s.union_with(&other);
919
924
///
@@ -1048,7 +1053,7 @@ impl BitvSet {
1048
1053
/// s.insert(0);
1049
1054
///
1050
1055
/// let bv = s.get_ref();
1051
- /// assert_eq!(bv.get(0) , true);
1056
+ /// assert_eq!(bv[0] , true);
1052
1057
/// ```
1053
1058
#[ inline]
1054
1059
pub fn get_ref < ' a > ( & ' a self ) -> & ' a Bitv {
@@ -1131,9 +1136,9 @@ impl BitvSet {
1131
1136
///
1132
1137
/// ```
1133
1138
/// use std::collections::BitvSet;
1134
- /// use std::collections::bitv::from_bytes ;
1139
+ /// use std::collections::bitv;
1135
1140
///
1136
- /// let s = BitvSet::from_bitv(from_bytes([0b01001010]));
1141
+ /// let s = BitvSet::from_bitv(bitv:: from_bytes([0b01001010]));
1137
1142
///
1138
1143
/// // Print 1, 4, 6 in arbitrary order
1139
1144
/// for x in s.iter() {
@@ -1152,10 +1157,10 @@ impl BitvSet {
1152
1157
///
1153
1158
/// ```
1154
1159
/// use std::collections::BitvSet;
1155
- /// use std::collections::bitv::from_bytes ;
1160
+ /// use std::collections::bitv;
1156
1161
///
1157
- /// let a = BitvSet::from_bitv(from_bytes([0b01101000]));
1158
- /// let b = BitvSet::from_bitv(from_bytes([0b10100000]));
1162
+ /// let a = BitvSet::from_bitv(bitv:: from_bytes([0b01101000]));
1163
+ /// let b = BitvSet::from_bitv(bitv:: from_bytes([0b10100000]));
1159
1164
///
1160
1165
/// // Print 0, 1, 2, 4 in arbitrary order
1161
1166
/// for x in a.union(&b) {
@@ -1180,10 +1185,10 @@ impl BitvSet {
1180
1185
///
1181
1186
/// ```
1182
1187
/// use std::collections::BitvSet;
1183
- /// use std::collections::bitv::from_bytes ;
1188
+ /// use std::collections::bitv;
1184
1189
///
1185
- /// let a = BitvSet::from_bitv(from_bytes([0b01101000]));
1186
- /// let b = BitvSet::from_bitv(from_bytes([0b10100000]));
1190
+ /// let a = BitvSet::from_bitv(bitv:: from_bytes([0b01101000]));
1191
+ /// let b = BitvSet::from_bitv(bitv:: from_bytes([0b10100000]));
1187
1192
///
1188
1193
/// // Print 2
1189
1194
/// for x in a.intersection(&b) {
@@ -1209,10 +1214,10 @@ impl BitvSet {
1209
1214
///
1210
1215
/// ```
1211
1216
/// use std::collections::BitvSet;
1212
- /// use std::collections::bitv::from_bytes ;
1217
+ /// use std::collections::bitv;
1213
1218
///
1214
- /// let a = BitvSet::from_bitv(from_bytes([0b01101000]));
1215
- /// let b = BitvSet::from_bitv(from_bytes([0b10100000]));
1219
+ /// let a = BitvSet::from_bitv(bitv:: from_bytes([0b01101000]));
1220
+ /// let b = BitvSet::from_bitv(bitv:: from_bytes([0b10100000]));
1216
1221
///
1217
1222
/// // Print 2, 4 in arbitrary order
1218
1223
/// for x in a.difference(&b) {
@@ -1245,10 +1250,10 @@ impl BitvSet {
1245
1250
///
1246
1251
/// ```
1247
1252
/// use std::collections::BitvSet;
1248
- /// use std::collections::bitv::from_bytes ;
1253
+ /// use std::collections::bitv;
1249
1254
///
1250
- /// let a = BitvSet::from_bitv(from_bytes([0b01101000]));
1251
- /// let b = BitvSet::from_bitv(from_bytes([0b10100000]));
1255
+ /// let a = BitvSet::from_bitv(bitv:: from_bytes([0b01101000]));
1256
+ /// let b = BitvSet::from_bitv(bitv:: from_bytes([0b10100000]));
1252
1257
///
1253
1258
/// // Print 0, 1, 4 in arbitrary order
1254
1259
/// for x in a.symmetric_difference(&b) {
@@ -1272,13 +1277,13 @@ impl BitvSet {
1272
1277
///
1273
1278
/// ```
1274
1279
/// use std::collections::BitvSet;
1275
- /// use std::collections::bitv::from_bytes ;
1280
+ /// use std::collections::bitv;
1276
1281
///
1277
- /// let mut a = BitvSet::from_bitv(from_bytes([0b01101000]));
1278
- /// let b = BitvSet::from_bitv(from_bytes([0b10100000]));
1282
+ /// let mut a = BitvSet::from_bitv(bitv:: from_bytes([0b01101000]));
1283
+ /// let b = BitvSet::from_bitv(bitv:: from_bytes([0b10100000]));
1279
1284
///
1280
1285
/// a.union_with(&b);
1281
- /// assert_eq!(a.unwrap(), from_bytes([0b11101000]));
1286
+ /// assert_eq!(a.unwrap(), bitv:: from_bytes([0b11101000]));
1282
1287
/// ```
1283
1288
#[ inline]
1284
1289
pub fn union_with ( & mut self , other : & BitvSet ) {
@@ -1291,13 +1296,13 @@ impl BitvSet {
1291
1296
///
1292
1297
/// ```
1293
1298
/// use std::collections::BitvSet;
1294
- /// use std::collections::bitv::from_bytes ;
1299
+ /// use std::collections::bitv;
1295
1300
///
1296
- /// let mut a = BitvSet::from_bitv(from_bytes([0b01101000]));
1297
- /// let b = BitvSet::from_bitv(from_bytes([0b10100000]));
1301
+ /// let mut a = BitvSet::from_bitv(bitv:: from_bytes([0b01101000]));
1302
+ /// let b = BitvSet::from_bitv(bitv:: from_bytes([0b10100000]));
1298
1303
///
1299
1304
/// a.intersect_with(&b);
1300
- /// assert_eq!(a.unwrap(), from_bytes([0b00100000]));
1305
+ /// assert_eq!(a.unwrap(), bitv:: from_bytes([0b00100000]));
1301
1306
/// ```
1302
1307
#[ inline]
1303
1308
pub fn intersect_with ( & mut self , other : & BitvSet ) {
@@ -1310,13 +1315,13 @@ impl BitvSet {
1310
1315
///
1311
1316
/// ```
1312
1317
/// use std::collections::BitvSet;
1313
- /// use std::collections::bitv::from_bytes ;
1318
+ /// use std::collections::bitv;
1314
1319
///
1315
- /// let mut a = BitvSet::from_bitv(from_bytes([0b01101000]));
1316
- /// let b = BitvSet::from_bitv(from_bytes([0b10100000]));
1320
+ /// let mut a = BitvSet::from_bitv(bitv:: from_bytes([0b01101000]));
1321
+ /// let b = BitvSet::from_bitv(bitv:: from_bytes([0b10100000]));
1317
1322
///
1318
1323
/// a.difference_with(&b);
1319
- /// assert_eq!(a.unwrap(), from_bytes([0b01001000]));
1324
+ /// assert_eq!(a.unwrap(), bitv:: from_bytes([0b01001000]));
1320
1325
/// ```
1321
1326
#[ inline]
1322
1327
pub fn difference_with ( & mut self , other : & BitvSet ) {
@@ -1329,13 +1334,13 @@ impl BitvSet {
1329
1334
///
1330
1335
/// ```
1331
1336
/// use std::collections::BitvSet;
1332
- /// use std::collections::bitv::from_bytes ;
1337
+ /// use std::collections::bitv;
1333
1338
///
1334
- /// let mut a = BitvSet::from_bitv(from_bytes([0b01101000]));
1335
- /// let b = BitvSet::from_bitv(from_bytes([0b10100000]));
1339
+ /// let mut a = BitvSet::from_bitv(bitv:: from_bytes([0b01101000]));
1340
+ /// let b = BitvSet::from_bitv(bitv:: from_bytes([0b10100000]));
1336
1341
///
1337
1342
/// a.symmetric_difference_with(&b);
1338
- /// assert_eq!(a.unwrap(), from_bytes([0b11001000]));
1343
+ /// assert_eq!(a.unwrap(), bitv:: from_bytes([0b11001000]));
1339
1344
/// ```
1340
1345
#[ inline]
1341
1346
pub fn symmetric_difference_with ( & mut self , other : & BitvSet ) {
0 commit comments