Skip to content

Commit ae93fd5

Browse files
treemanalexcrichton
authored andcommitted
---
yaml --- r: 124825 b: refs/heads/auto c: 4574b2f h: refs/heads/master i: 124823: 1edbf8e v: v3
1 parent 3046df0 commit ae93fd5

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 26047f15e5f1db33d66979554c29fba3cf4d2c33
16+
refs/heads/auto: 4574b2fbaa866fbe73224f57981151aab1f1f15b
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/libcollections/bitv.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,55 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
//! Collections implemented with bit vectors.
12+
//!
13+
//! # Example
14+
//!
15+
//! This is a simple example of the [Sieve of Eratosthenes][sieve]
16+
//! which calculates prime numbers up to a given limit.
17+
//!
18+
//! [sieve]: http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
19+
//!
20+
//! ```
21+
//! use std::collections::{BitvSet, Bitv};
22+
//! use std::iter;
23+
//!
24+
//! let max_prime = 10000;
25+
//!
26+
//! // Store the primes as a BitvSet
27+
//! let primes = {
28+
//! let mut bv = Bitv::with_capacity(max_prime, true);
29+
//!
30+
//! // Neither 0 nor 1 are prime
31+
//! bv.set(0, false);
32+
//! bv.set(1, false);
33+
//!
34+
//! for i in range(2, max_prime) {
35+
//! // 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+
//! // will have been marked as non-prime previously)
39+
//! for j in iter::range_step(i * i, max_prime, i) { bv.set(j, false) }
40+
//! }
41+
//! }
42+
//! BitvSet::from_bitv(bv)
43+
//! };
44+
//!
45+
//! // Simple primality tests below our max bound
46+
//! let print_primes = 20;
47+
//! print!("The primes below {} are: ", print_primes);
48+
//! for x in range(0, print_primes) {
49+
//! if primes.contains(&x) {
50+
//! print!("{} ", x);
51+
//! }
52+
//! }
53+
//! println!("");
54+
//!
55+
//! // We can manipulate the internal Bitv
56+
//! let num_primes = primes.get_ref().iter().filter(|x| *x).count();
57+
//! println!("There are {} primes below {}", num_primes, max_prime);
58+
//! ```
59+
1160
#![allow(missing_doc)]
1261

1362
use core::prelude::*;

0 commit comments

Comments
 (0)