Skip to content

Commit

Permalink
Merge pull request #74 from pczarn/readme
Browse files Browse the repository at this point in the history
Update README & use cargo-rdme generator
  • Loading branch information
Gankra authored Feb 19, 2023
2 parents d15090d + 91ba7ff commit d3585be
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 10 deletions.
1 change: 1 addition & 0 deletions .cargo-rdme.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
line-terminator = "lf"
2 changes: 1 addition & 1 deletion LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2015 The Rust Project Developers
Copyright (c) 2023 The Rust Project Developers

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
Expand Down
91 changes: 84 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
<div align="center">
<h1>bit-vec</h1>
<p>
<strong>A vector of bits.</strong>
<strong>A compact vector of bits.</strong>
</p>
<p>

[![crates.io](https://img.shields.io/crates/v/bit-vec?label=latest)](https://crates.io/crates/bit-vec)
[![Documentation](https://docs.rs/bit-vec/badge.svg?version=0.6.3)](https://docs.rs/bit-vec/0.6.3/bit_vec/)
![Rust CI](https://github.com/contain-rs/linked-hash-map/workflows/Rust/badge.svg?branch=master)
[![crates.io][crates.io shield]][crates.io link]
[![Documentation][docs.rs badge]][docs.rs link]
![Rust CI][github ci badge]
[![rustc 1.0+]][Rust 1.0]
[![serde_derive: rustc 1.31+]][Rust 1.31]
<br />
<br />
[![Dependency Status](https://deps.rs/crate/bit-vec/0.6.3/status.svg)](https://deps.rs/crate/bit-vec/0.6.3)
[![Download Status](https://img.shields.io/crates/d/bit-vec.svg)](https://crates.io/crates/bit-vec)
[![Dependency Status][deps.rs status]][deps.rs link]
[![Download Status][shields.io download count]][crates.io link]

</p>
</div>

[crates.io shield]: https://img.shields.io/crates/v/bit-vec?label=latest
[crates.io link]: https://crates.io/crates/bit-vec
[docs.rs badge]: https://docs.rs/bit-vec/badge.svg?version=0.6.3
[docs.rs link]: https://docs.rs/bit-vec/0.6.3/bit_vec/
[github ci badge]: https://github.com/contain-rs/linked-hash-map/workflows/Rust/badge.svg?branch=master
[rustc 1.0+]: https://img.shields.io/badge/rustc-1.0%2B-blue.svg
[serde_derive: rustc 1.31+]: https://img.shields.io/badge/serde_derive-rustc_1.31+-lightgray.svg
[Rust 1.0]: https://blog.rust-lang.org/2015/05/15/Rust-1.0.html
[Rust 1.31]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html
[deps.rs status]: https://deps.rs/crate/bit-vec/0.6.3/status.svg
[deps.rs link]: https://deps.rs/crate/bit-vec/0.6.3
[shields.io download count]: https://img.shields.io/crates/d/bit-vec.svg

## Usage

Expand All @@ -32,7 +40,8 @@ Add this to your Cargo.toml:
bit-vec = "0.6"
```

and this to your crate root:
Since Rust 2018, `extern crate` is no longer mandatory. If your edition is old (Rust 2015),
add this to your crate root:

```rust
extern crate bit_vec;
Expand All @@ -51,3 +60,71 @@ If you want to use bit-vec in a program that has `#![no_std]`, just drop default
[dependencies]
bit-vec = { version = "0.6", default-features = false }
```

<!-- cargo-rdme start -->

### Description

Dynamic collections implemented with compact bit vectors.

### Examples

This is a simple example of the [Sieve of Eratosthenes][sieve]
which calculates prime numbers up to a given limit.

[sieve]: http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

```rust
use bit_vec::BitVec;

let max_prime = 10000;

// Store the primes as a BitVec
let primes = {
// Assume all numbers are prime to begin, and then we
// cross off non-primes progressively
let mut bv = BitVec::from_elem(max_prime, true);

// Neither 0 nor 1 are prime
bv.set(0, false);
bv.set(1, false);

for i in 2.. 1 + (max_prime as f64).sqrt() as usize {
// if i is a prime
if bv[i] {
// Mark all multiples of i as non-prime (any multiples below i * i
// will have been marked as non-prime previously)
for j in i.. {
if i * j >= max_prime {
break;
}
bv.set(i * j, false)
}
}
}
bv
};

// Simple primality tests below our max bound
let print_primes = 20;
print!("The primes below {} are: ", print_primes);
for x in 0..print_primes {
if primes.get(x).unwrap_or(false) {
print!("{} ", x);
}
}
println!();

let num_primes = primes.iter().filter(|x| *x).count();
println!("There are {} primes below {}", num_primes, max_prime);
assert_eq!(num_primes, 1_229);
```

<!-- cargo-rdme end -->

## License

Dual-licensed for compatibility with the Rust project.

Licensed under the Apache License Version 2.0: http://www.apache.org/licenses/LICENSE-2.0,
or the MIT license: http://opensource.org/licenses/MIT, at your option.
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012-2020 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2023 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -25,7 +25,9 @@
// (4) `BitSet` is tightly coupled with `BitVec`, so any changes you make in
// `BitVec` will need to be reflected in `BitSet`.

//! Collections implemented with bit vectors.
//! # Description
//!
//! Dynamic collections implemented with compact bit vectors.
//!
//! # Examples
//!
Expand Down

0 comments on commit d3585be

Please sign in to comment.