Skip to content

Commit 159ba93

Browse files
author
poly000
committed
remove LRU cache support
1 parent 295ae57 commit 159ba93

File tree

5 files changed

+17
-120
lines changed

5 files changed

+17
-120
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ jobs:
5858
uses: softprops/action-gh-release@v1
5959
with:
6060
files: ${{ matrix.target }}.tar
61-
tag_name: v0.3.1
61+
tag_name: v0.4.0
6262
prerelease: true
6363

Cargo.lock

Lines changed: 12 additions & 83 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fibnacci"
3-
version = "0.3.1"
3+
version = "0.4.0"
44
edition = "2021"
55
license = "MIT"
66
repository = "https://github.com/poly000/fibonacci"
@@ -19,9 +19,6 @@ name = "fibonacci"
1919
rayon = "1.5.3"
2020
rust-gmp = "0.5.0"
2121
clap = { version = "3.2.20", features = ["derive"] }
22-
cache-macro = "0.4.1"
23-
lru-cache = "0.1.2"
24-
lazy_static = "1.4.0"
2522

2623
[profile.release]
2724
panic = "abort"

src/bin/fibonacci.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use clap::Parser;
2+
use fibonacci::fib;
23
use fibonacci::IndexType;
3-
use fibonacci::{_fib, fib};
44

55
fn main() {
66
let Args {
77
n,
88
r: range,
99
print_result,
10-
lru_cache: no_parralel,
1110
} = Args::parse();
1211

1312
match (n, range) {
@@ -28,15 +27,15 @@ fn main() {
2827
}
2928
}) {
3029
for i in r {
31-
let result = if no_parralel { _fib(i) } else { fib(i) };
30+
let result = fib(i);
3231
if print_result {
3332
println!("{i}: {result}");
3433
}
3534
}
3635
}
3736
}
3837
(Some(n), _) => {
39-
let result = if no_parralel { _fib(n) } else { fib(n) };
38+
let result = fib(n);
4039
if print_result {
4140
println!("{result}");
4241
}
@@ -65,8 +64,4 @@ struct Args {
6564
/// whether should we print the result or only perform calculation.
6665
#[clap(short = 'p', long = "print", value_parser)]
6766
print_result: bool,
68-
69-
/// lru_cache version
70-
#[clap(long, value_parser)]
71-
lru_cache: bool,
7267
}

src/lib.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,10 @@
1-
use cache_macro::cache;
2-
use lru_cache::LruCache;
3-
41
pub type IndexType = u64; // this is currently much larger than your mem/cpu limitation
52

63
use std::ops::Mul;
74

85
use gmp::mpz::Mpz;
96
use rayon::join;
107

11-
#[cache(LruCache : LruCache::new(1000000))]
12-
fn no_parralel_fib(x: IndexType) -> (Mpz, Mpz) {
13-
if x < 3 {
14-
(Mpz::from(0), Mpz::from(1))
15-
} else {
16-
if x % 2 == 1 {
17-
let n = (x + 1) / 2;
18-
(fib(n).pow(2), fib(n - 1).pow(2))
19-
} else {
20-
let n = x / 2;
21-
let (a, b) = (fib(n), fib(n - 1));
22-
(b.mul(Mpz::from(2)) * &a, a.pow(2))
23-
}
24-
}
25-
}
26-
27-
pub fn _fib(x: IndexType) -> Mpz {
28-
let (a, b) = no_parralel_fib(x);
29-
a + b
30-
}
31-
328
pub fn fib(x: IndexType) -> Mpz {
339
if x < 3 {
3410
Mpz::from(1)

0 commit comments

Comments
 (0)