Created examples
This commit is contained in:
parent
81ed7f8c9a
commit
0bcfeb3efe
4 changed files with 26 additions and 40 deletions
|
@ -6,5 +6,5 @@ authors = ["Zach Dziura <zcdziura@gmail.com>"]
|
|||
[dependencies]
|
||||
custom_derive = "0.1.2"
|
||||
newtype_derive = "0.1.2"
|
||||
ramp = "0.1.9"
|
||||
ramp = "0.1.*"
|
||||
rand = "0.3.11"
|
||||
|
|
11
examples/multiply.rs
Normal file
11
examples/multiply.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
extern crate pumpkin;
|
||||
|
||||
use pumpkin::Prime;
|
||||
|
||||
fn main() {
|
||||
let p = Prime::new(2048);
|
||||
let q = Prime::new(2048);
|
||||
let s = p * q;
|
||||
|
||||
println!("{}", s);
|
||||
}
|
27
src/lib.rs
27
src/lib.rs
|
@ -1,6 +1,6 @@
|
|||
#![feature(augmented_assignments)]
|
||||
#![feature(core)]
|
||||
#![feature(test)]
|
||||
#![feature(custom_derive)]
|
||||
|
||||
/// # The Pumpkin Prime Number Generator
|
||||
///
|
||||
|
@ -10,26 +10,20 @@
|
|||
/// secure source of entrophy and are verified using three different primality
|
||||
/// tests.
|
||||
///
|
||||
/// ## Installation
|
||||
///
|
||||
/// To include `pumpkin` in your project add the following line to your
|
||||
/// Cargo.toml file:
|
||||
///
|
||||
/// ```
|
||||
/// [dependencies]
|
||||
/// pumpkin = "*"
|
||||
/// ```
|
||||
///
|
||||
/// ## Examples
|
||||
///
|
||||
/// ```
|
||||
/// extern crate pumpkin;
|
||||
///
|
||||
/// use pumpkin::Prime;
|
||||
///
|
||||
/// fn main() {
|
||||
/// // Generate a 2048-bit prime number
|
||||
/// let prime = pumpkin::Prime::new(2048);
|
||||
/// let p = Prime::new(2048);
|
||||
/// let q = Prime::new(2048);
|
||||
///
|
||||
/// // Want to very the prime you generated is ACTUALLY prime, and not
|
||||
/// // simply a probable prime? Easy!
|
||||
/// assert_eq!(prime.verify(), true);
|
||||
/// let r = p * q;
|
||||
/// println!("{}", r); // Some ridiculously large number
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
|
@ -39,4 +33,5 @@ extern crate core;
|
|||
extern crate ramp;
|
||||
extern crate rand;
|
||||
|
||||
pub mod prime;
|
||||
mod prime;
|
||||
pub use prime::Prime;
|
||||
|
|
26
src/prime.rs
26
src/prime.rs
|
@ -94,11 +94,10 @@ static SMALL_PRIMES: [u32; 999] = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,
|
|||
///
|
||||
/// `Prime`s are built upon the `Int` type as defined in the `ramp` crate. In
|
||||
/// fact, all operations that you can do with `Int`s, you can do with `Prime`s
|
||||
/// as well. `Prime`s simply guarantee that the number you're dealing with is,
|
||||
/// a prime number.
|
||||
/// as well. `Prime`s simply claim that the number you're dealing with is a
|
||||
/// prime number.
|
||||
custom_derive! {
|
||||
#[derive(Debug)]
|
||||
#[derive(NewtypeAdd, NewtypeSub, NewtypeMul, NewtypeDiv)]
|
||||
#[derive(Debug, NewtypeAdd, NewtypeSub, NewtypeMul, NewtypeDiv)]
|
||||
pub struct Prime(Int);
|
||||
}
|
||||
|
||||
|
@ -240,22 +239,3 @@ fn rewrite(candidate: &Int) -> (Int, Int) {
|
|||
|
||||
(s, d)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate test;
|
||||
|
||||
use super::*;
|
||||
use self::test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn bench_prime_gen_1024(b: &mut Bencher) {
|
||||
b.iter(|| Prime::new(1024));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_prime_gen_2048(b: &mut Bencher) {
|
||||
b.iter(|| Prime::new(2048));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue