| Crates.io | fib-o1 |
| lib.rs | fib-o1 |
| version | 0.1.3 |
| created_at | 2025-07-14 21:41:34.827413+00 |
| updated_at | 2025-07-15 13:34:44.081511+00 |
| description | generate Fibonacci sequence numbers in O(1) time |
| homepage | https://github.com/theryangeary/fib-o1 |
| repository | https://github.com/theryangeary/fib-o1 |
| max_upload_size | |
| id | 1752263 |
| size | 23,132 |
fib_o1 is a rust crate which provides a fn fib(n) which produces a member of
the Fibonacci sequence in constant (O(1)) time, up to a compile-time defined
upper limit (or limits imposed by your chosen datatype).
fn fib(n) works will all rust primitive unsigned integer types (i.e. u8 to
u128, usize) as well as with num::BigInt and num::BigUint from
num_bigint.
To flex about how fast it is. It's almost as fast as writing to /dev/null.
Realistically it is mostly pointless. Ask your local mathmatician about practical applications.
fib_o1 will always give the requested result in constant O(1) time.
Comparison of alternative algorithms:
Producing O(1) Fibonacci sequence members does require some leg work1 at compile time, which can impact build times depending on what maximum sequence value you require. Just remember how much time you will save at runtime and have a sword fight.
On my 2021 MacBook Pro with M1 Pro chip, compile times for fib() up to:
| 2^ | time |
|---|---|
| 12 | negligible |
| 13 | ~10s |
| 14 | ~1m20s |
| 15 | the rust compiler complains that files larger than a certain size are unsupported |
You may think encoding many Fibonacci sequence numbers into your binary will
increase its size. However, when feature bigint is off, the bin size of
bin/hello_fib.rs is the same as bin/hello_world.rs (around 400kb).
When feature bigint is on, however, the binary size will start to be
impacted2.
| features | bin size (kb) |
|---|---|
| bigint,pow10 | 678 |
| bigint,pow11 | 1,090 |
| bigint,pow12 | 2,577 |
| bigint,pow13 | 8,306 |
| bigint,pow14 | 30,267 |