Skip to content

Commit 3bac076

Browse files
treemanalexcrichton
authored andcommitted
---
yaml --- r: 132037 b: refs/heads/dist-snap c: 4574b2f h: refs/heads/master i: 132035: 4826ec0 v: v3
1 parent 8387344 commit 3bac076

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
@@ -6,7 +6,7 @@ refs/heads/try: 457a3c991d79b971be07fce75f9d0c12848fb37c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 26047f15e5f1db33d66979554c29fba3cf4d2c33
9+
refs/heads/dist-snap: 4574b2fbaa866fbe73224f57981151aab1f1f15b
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/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)