2525//!
2626//! // Store the primes as a BitvSet
2727//! let primes = {
28+ //! // Assume all numbers are prime to begin, and then we
29+ //! // cross off non-primes progressively
2830//! let mut bv = Bitv::with_capacity(max_prime, true);
2931//!
3032//! // Neither 0 nor 1 are prime
3335//!
3436//! for i in range(2, max_prime) {
3537//! // 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
3840//! // will have been marked as non-prime previously)
3941//! for j in iter::range_step(i * i, max_prime, i) { bv.set(j, false) }
4042//! }
@@ -252,6 +254,9 @@ impl Bitv {
252254 /// let bv: Bitv = [false, true].iter().map(|n| *n).collect();
253255 /// assert_eq!(bv.get(0), false);
254256 /// assert_eq!(bv.get(1), true);
257+ ///
258+ /// // Can also use array indexing
259+ /// assert_eq!(bv[1], true);
255260 /// ```
256261 #[ inline]
257262 pub fn get ( & self , i : uint ) -> bool {
@@ -275,7 +280,7 @@ impl Bitv {
275280 ///
276281 /// let mut bv = Bitv::with_capacity(5, false);
277282 /// bv.set(3, true);
278- /// assert_eq!(bv.get(3) , true);
283+ /// assert_eq!(bv[3] , true);
279284 /// ```
280285 #[ inline]
281286 pub fn set ( & mut self , i : uint , x : bool ) {
@@ -478,7 +483,7 @@ impl Bitv {
478483 /// Organise the bits into bytes, such that the first bit in the
479484 /// `Bitv` becomes the high-order bit of the first byte. If the
480485 /// 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` .
482487 ///
483488 /// # Example
484489 ///
@@ -716,9 +721,9 @@ impl Bitv {
716721/// # Example
717722///
718723/// ```
719- /// use std::collections::bitv::from_bytes ;
724+ /// use std::collections::bitv;
720725///
721- /// let bv = from_bytes([0b10100000, 0b00010010]);
726+ /// let bv = bitv:: from_bytes([0b10100000, 0b00010010]);
722727/// assert!(bv.eq_vec([true, false, true, false,
723728/// false, false, false, false,
724729/// false, false, false, true,
@@ -898,7 +903,7 @@ impl<'a> RandomAccessIterator<bool> for Bits<'a> {
898903///
899904/// ```
900905/// use std::collections::{BitvSet, Bitv};
901- /// use std::collections::bitv::from_bytes ;
906+ /// use std::collections::bitv;
902907///
903908/// // It's a regular set
904909/// let mut s = BitvSet::new();
@@ -913,7 +918,7 @@ impl<'a> RandomAccessIterator<bool> for Bits<'a> {
913918/// }
914919///
915920/// // Can initialize from a `Bitv`
916- /// let other = BitvSet::from_bitv(from_bytes([0b11010000]));
921+ /// let other = BitvSet::from_bitv(bitv:: from_bytes([0b11010000]));
917922///
918923/// s.union_with(&other);
919924///
@@ -1048,7 +1053,7 @@ impl BitvSet {
10481053 /// s.insert(0);
10491054 ///
10501055 /// let bv = s.get_ref();
1051- /// assert_eq!(bv.get(0) , true);
1056+ /// assert_eq!(bv[0] , true);
10521057 /// ```
10531058 #[ inline]
10541059 pub fn get_ref < ' a > ( & ' a self ) -> & ' a Bitv {
@@ -1131,9 +1136,9 @@ impl BitvSet {
11311136 ///
11321137 /// ```
11331138 /// use std::collections::BitvSet;
1134- /// use std::collections::bitv::from_bytes ;
1139+ /// use std::collections::bitv;
11351140 ///
1136- /// let s = BitvSet::from_bitv(from_bytes([0b01001010]));
1141+ /// let s = BitvSet::from_bitv(bitv:: from_bytes([0b01001010]));
11371142 ///
11381143 /// // Print 1, 4, 6 in arbitrary order
11391144 /// for x in s.iter() {
@@ -1152,10 +1157,10 @@ impl BitvSet {
11521157 ///
11531158 /// ```
11541159 /// use std::collections::BitvSet;
1155- /// use std::collections::bitv::from_bytes ;
1160+ /// use std::collections::bitv;
11561161 ///
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]));
11591164 ///
11601165 /// // Print 0, 1, 2, 4 in arbitrary order
11611166 /// for x in a.union(&b) {
@@ -1180,10 +1185,10 @@ impl BitvSet {
11801185 ///
11811186 /// ```
11821187 /// use std::collections::BitvSet;
1183- /// use std::collections::bitv::from_bytes ;
1188+ /// use std::collections::bitv;
11841189 ///
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]));
11871192 ///
11881193 /// // Print 2
11891194 /// for x in a.intersection(&b) {
@@ -1209,10 +1214,10 @@ impl BitvSet {
12091214 ///
12101215 /// ```
12111216 /// use std::collections::BitvSet;
1212- /// use std::collections::bitv::from_bytes ;
1217+ /// use std::collections::bitv;
12131218 ///
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]));
12161221 ///
12171222 /// // Print 2, 4 in arbitrary order
12181223 /// for x in a.difference(&b) {
@@ -1245,10 +1250,10 @@ impl BitvSet {
12451250 ///
12461251 /// ```
12471252 /// use std::collections::BitvSet;
1248- /// use std::collections::bitv::from_bytes ;
1253+ /// use std::collections::bitv;
12491254 ///
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]));
12521257 ///
12531258 /// // Print 0, 1, 4 in arbitrary order
12541259 /// for x in a.symmetric_difference(&b) {
@@ -1272,13 +1277,13 @@ impl BitvSet {
12721277 ///
12731278 /// ```
12741279 /// use std::collections::BitvSet;
1275- /// use std::collections::bitv::from_bytes ;
1280+ /// use std::collections::bitv;
12761281 ///
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]));
12791284 ///
12801285 /// a.union_with(&b);
1281- /// assert_eq!(a.unwrap(), from_bytes([0b11101000]));
1286+ /// assert_eq!(a.unwrap(), bitv:: from_bytes([0b11101000]));
12821287 /// ```
12831288 #[ inline]
12841289 pub fn union_with ( & mut self , other : & BitvSet ) {
@@ -1291,13 +1296,13 @@ impl BitvSet {
12911296 ///
12921297 /// ```
12931298 /// use std::collections::BitvSet;
1294- /// use std::collections::bitv::from_bytes ;
1299+ /// use std::collections::bitv;
12951300 ///
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]));
12981303 ///
12991304 /// a.intersect_with(&b);
1300- /// assert_eq!(a.unwrap(), from_bytes([0b00100000]));
1305+ /// assert_eq!(a.unwrap(), bitv:: from_bytes([0b00100000]));
13011306 /// ```
13021307 #[ inline]
13031308 pub fn intersect_with ( & mut self , other : & BitvSet ) {
@@ -1310,13 +1315,13 @@ impl BitvSet {
13101315 ///
13111316 /// ```
13121317 /// use std::collections::BitvSet;
1313- /// use std::collections::bitv::from_bytes ;
1318+ /// use std::collections::bitv;
13141319 ///
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]));
13171322 ///
13181323 /// a.difference_with(&b);
1319- /// assert_eq!(a.unwrap(), from_bytes([0b01001000]));
1324+ /// assert_eq!(a.unwrap(), bitv:: from_bytes([0b01001000]));
13201325 /// ```
13211326 #[ inline]
13221327 pub fn difference_with ( & mut self , other : & BitvSet ) {
@@ -1329,13 +1334,13 @@ impl BitvSet {
13291334 ///
13301335 /// ```
13311336 /// use std::collections::BitvSet;
1332- /// use std::collections::bitv::from_bytes ;
1337+ /// use std::collections::bitv;
13331338 ///
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]));
13361341 ///
13371342 /// a.symmetric_difference_with(&b);
1338- /// assert_eq!(a.unwrap(), from_bytes([0b11001000]));
1343+ /// assert_eq!(a.unwrap(), bitv:: from_bytes([0b11001000]));
13391344 /// ```
13401345 #[ inline]
13411346 pub fn symmetric_difference_with ( & mut self , other : & BitvSet ) {
0 commit comments