Skip to content

Commit

Permalink
Better docs
Browse files Browse the repository at this point in the history
  • Loading branch information
wackywendell committed Aug 29, 2018
1 parent c6882c8 commit 387f7e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "primes"
version = "0.2.2"
version = "0.2.3"
authors = ["Wendell Smith <wendellwsmith@gmail.com>"]
license="BSD-3-Clause"

Expand Down
29 changes: 15 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ pub struct PrimeSet {
lst: Vec<u64>,
}

/// An iterator over generated primes. Created by PrimeSet::iter or
/// PrimeSet::generator
/// An iterator over generated primes. Created by `PrimeSet::iter` or
/// `PrimeSet::generator`
pub struct PrimeSetIter<'a> {
p: &'a mut PrimeSet,
n: usize,
Expand Down Expand Up @@ -135,7 +135,7 @@ impl PrimeSet {
}

/// Iterator over all primes, starting with 2. If you don't care about the "state" of the
/// PrimeSet, this is what you want!
/// `PrimeSet`, this is what you want!
pub fn iter(&mut self) -> PrimeSetIter {
PrimeSetIter {
p: self,
Expand All @@ -144,18 +144,16 @@ impl PrimeSet {
}
}

//~ pub fn iter_once(&'self mut self) -> PrimeSetIter<'self> {
//~ PrimeSetIter{p:self, n:0, expand:false}
//~ }

/// Iterator over just the primes found so far
pub fn iter_vec(&self) -> slice::Iter<u64> {
self.lst.iter()
}

/// Find the next largest prime from a number
/// Returns (idx, prime)
/// Note that if n is prime, then the output will be (idx, n)
///
/// Returns `(idx, prime)`
///
/// Note that if `n` is prime, then the output will be `(idx, n)`
pub fn find(&mut self, n: u64) -> (usize, u64) {
while n > *(self.lst.last().unwrap_or(&0)) {
self.expand();
Expand All @@ -164,7 +162,8 @@ impl PrimeSet {
}

/// Check if a number is prime
/// Note that this only requires primes up to n.sqrt() to be generated, and will generate
///
/// Note that this only requires primes up to `n.sqrt()` to be generated, and will generate
/// them as necessary on its own.
#[cfg_attr(feature = "cargo-clippy", allow(wrong_self_convention))]
pub fn is_prime(&mut self, n: u64) -> bool {
Expand All @@ -186,8 +185,10 @@ impl PrimeSet {
}

/// Find the next largest prime from a number, if it is within the already-found list
/// Returns (idx, prime)
/// Note that if n is prime, then the output will be (idx, n)
///
/// Returns `(idx, prime)`
///
/// Note that if `n` is prime, then the output will be `(idx, n)`
pub fn find_vec(&self, n: u64) -> Option<(usize, u64)> {
if n > *(self.lst.last().unwrap_or(&0)) {
return None;
Expand Down Expand Up @@ -289,7 +290,7 @@ fn firstfac(x: u64) -> u64 {
}

/// Find all prime factors of a number
/// Does not use a PrimeSet, but simply counts upwards
/// Does not use a `PrimeSet`, but simply counts upwards
pub fn factors(x: u64) -> Vec<u64> {
if x <= 1 {
return vec![];
Expand Down Expand Up @@ -331,7 +332,7 @@ pub fn factors_uniq(x: u64) -> Vec<u64> {
lst
}

/// Test whether a number is prime. Checks every odd number up to sqrt(n).
/// Test whether a number is prime. Checks every odd number up to `sqrt(n)`.
pub fn is_prime(n: u64) -> bool {
if n <= 1 {
return false;
Expand Down

0 comments on commit 387f7e4

Please sign in to comment.