divisors_fixed 0.4.0

A fixed & enhanced version of the divisors crate
Documentation
  • Coverage
  • 100%
    4 out of 4 items documented1 out of 4 items with examples
  • Size
  • Source code size: 21.01 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.19 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • synabler/divisors
    0 0 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • jh05013

Divisors-fixed

A minimalistic crate for finding all divisors of an integer. Although its worst-case time complexity is (currently) still O(sqrt(n)), It is practically much faster than the naive method of trying every integers under sqrt(n).

This library works with u8, u16, u32, u64, u128, and usize types.

This originally started as a clone of the divisors crate with bug fixes (hence the name), but has since evolved with API changes and reimplementations.

Example

let n = 240u32;
println!("{:?}", n.divisors_unordered());
println!("{:?}", n.divisors());

/*
Output:
[1, 2, 4, 8, 16, 3, 6, 12, 24, 48, 5, 10, 20, 40, 80, 15, 30, 60, 120, 240]
[1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 16, 20, 24, 30, 40, 48, 60, 80, 120, 240]
*/

Usage

Add this to your Cargo.toml:

[dependencies]

divisors = "0.4.0"

Documentations

cargo doc --open

link

Benchmarks

cargo bench

Test

cargo test

License

MIT.