Alex Lyon
5544def54e
Remove pipe_* macros
2020-11-08 19:56:52 -06:00
Alex Lyon
f0bd170996
chmod, install: move mode parsing into uucore
2020-11-08 19:56:52 -06:00
Alex Lyon
fd555c6d21
Handle SIGPIPE correctly and autogenerate main() for each util
2020-11-08 19:56:52 -06:00
Joshua Miller
6998949c06
pin dependencies
2020-11-08 19:56:52 -06:00
Matt8898
e7940828f9
uucore: add support for optflagmulti and optmulti.
2020-11-08 19:56:52 -06:00
Arcterus
e2b8741a35
uucore: compile on Windows again
2020-11-08 19:56:52 -06:00
Arcterus
f61f30f52b
uucore: read symlinked directories correctly in resolve_relative_path()
2020-11-08 19:56:52 -06:00
Joseph Crail
f3639b9453
Fix comment spelling
2020-11-08 19:56:52 -06:00
Lei Zhang
3f4dba0de9
Turn off utmpx and signals for Fuchsia.
...
Fuchsia uses musl as its libc; musl only has stub implementation
for utmpx. From their wiki, that is deliberately chosen.
Fuchsia doesn't have signals mechanism.
2020-11-08 19:56:52 -06:00
Will Wykeham
cf2be8a6b1
Fix a number of Windows build warnings
2020-11-08 19:56:52 -06:00
knight42
09b0b9ad78
chown,chgrp: fix bug in option --preserve-root
2020-11-08 19:56:51 -06:00
knight42
b6dcafc675
uucore::fs: add fn resolve_relative_path
2020-11-08 19:56:51 -06:00
Nathan Ross
22fab1444e
uucore: allow 'wrong number of arguments' macro to be more precise
2020-11-08 19:56:51 -06:00
Nathan Ross
8cb2edecb1
uucore: add support for optflagopt to coreopts
2020-11-08 19:56:51 -06:00
Nathan Ross
35951ebf66
uucore: fix utility name in coreopts parsing error messages
2020-11-08 19:56:51 -06:00
Knight
1dab4510b5
Remove uucore::c_types
2020-11-08 19:56:51 -06:00
Knight
d22814201e
Add uucore::utsname to get system info
2020-11-08 19:56:51 -06:00
Knight
05b5317605
uucore::process: add functions to obtain uid/gid, euid/egid
2020-11-08 19:56:51 -06:00
Knight
5bc2276775
Add uucore::entries
2020-11-08 19:56:51 -06:00
Knight
434aae76bc
uucore::utmpx: fix doctest errors
2020-11-08 19:56:51 -06:00
Knight
0277848de7
uucore: make libc optional
2020-11-08 19:56:51 -06:00
nathanross
50887566ea
uucore: coreopts alignment, spacing, and optional usage
2020-11-08 19:56:51 -06:00
Nathan Ross
73d36a1d88
uucore: require version; syntax; summary; longhelp
2020-11-08 19:56:51 -06:00
Knight
6a22120d7b
uucore::utmpx: change API and fix error
2020-11-08 19:56:51 -06:00
Knight
58b6ac9393
uucore::utmpx: refine implementation
2020-11-08 19:56:51 -06:00
Knight
3751142ccb
coreopts: fix error when using msg_wrong_number_of_arguments
macro
2020-11-08 19:56:50 -06:00
Knight
68ad14f3c4
uucore: conditional enable different features
2020-11-08 19:56:50 -06:00
Knight
25018b112b
uucore: export latest libc
2020-11-08 19:56:50 -06:00
Knight
789141d926
coreopts: display package name instead of module path
2020-11-08 19:56:50 -06:00
Nathan Ross
bcec54f572
uucore: CoreOptions error and version message templates
2020-11-08 19:56:50 -06:00
Nathan Ross
76952579ac
uucore: add message templates
2020-11-08 19:56:50 -06:00
Knight
2c78b92801
uucore: add module encoding
2020-11-08 19:56:50 -06:00
Corey Farwell
bcdb682bf8
Remove unused imports.
2020-11-08 19:56:50 -06:00
Corey Farwell
c6909951aa
Cleanup logic around wait_or_timeout
exit status handling.
2020-11-08 19:56:50 -06:00
Corey Farwell
72d2ab208c
Prefer handling Duration
over f32
when dealing with times.
...
Also refactored out usage of the `time` crate in `uucore`.
2020-11-08 19:56:50 -06:00
Knight
463c6af4e3
uucore: update utmpx
2020-11-08 19:56:50 -06:00
Knight
79b6835612
pinky: cleanup the code
2020-11-08 19:56:50 -06:00
Knight
6e2c3ede40
uucore::utmpx: revert the changes
2020-11-08 19:56:50 -06:00
Knight
967babd1e6
pinky: implement short format
2020-11-08 19:56:50 -06:00
Knight
b0588e482e
uucore: add disp_err macro
2020-11-08 19:56:50 -06:00
Shiroy
713770c9ae
Add missing lib.name for uucore
...
Fix build on Linux
2020-11-08 19:56:50 -06:00
Arcterus
a149efe45a
uucore: don't follow symlinks when examining them ( fixes #799 )
2020-11-08 19:56:49 -06:00
Michael Gehring
512a6a3201
expand, unexpand: fix build on stable
2020-11-08 19:56:49 -06:00
Michael Gehring
0a3a2ca935
Fix clippy warnings
2020-11-08 19:56:49 -06:00
Michael Gehring
ce733b38a9
Fix arm build
...
Fixes #719
2020-11-08 19:56:49 -06:00
Joseph Crail
bde309a29f
Remove trait shim needed before Path stabilized
...
Now that Path has stabilized in Rust 1.5, I removed the UUPathExt trait
needed to support stable, beta, and nightly.
2020-11-08 19:56:49 -06:00
Joseph Crail
0678332a1f
Add macro to properly find program name.
2020-11-08 19:56:49 -06:00
Joseph Crail
b8ee12f703
More import fixes for Windows.
2020-11-08 19:56:49 -06:00
Joseph Crail
3863842fae
Fix errors with bools represented as ints.
2020-11-08 19:56:49 -06:00
Joseph Crail
9c4c9f6782
Refactor check for standard stream interactivity.
...
Since several utilities check if the standard streams are interactive, I
moved this into the uucore::fs library as is_std*_interactive(). I also
added Windows support for these methods, which only return false (or at
least until someone finds a way to support this).
2020-11-08 19:56:49 -06:00
Joseph Crail
14eccb4335
uucore: specify a few modules to be Unix-only
2020-11-08 19:56:49 -06:00
Michael Gehring
23e0315262
Remove deprecated lint
2020-11-08 19:56:49 -06:00
Joseph Crail
6095dfee66
Split utility files into separate library.
...
Everything in src/common has been moved to src/uucore. This is defined
as a Cargo library, instead of directly included. This gives us
flexibility to make the library an external crate in the future.
Fixes #717 .
2020-11-08 19:56:42 -06:00
Sylvestre Ledru
5c8e47a4d1
Remove version mgmt, it is done by clap
2020-11-08 17:55:31 +01:00
Sylvestre Ledru
897bcb2e67
refactor(mkdir): Move to clap + add a test
2020-11-08 17:51:04 +01:00
Sylvestre Ledru
92d5d47434
refactor(pwd): move to clap + add a test
2020-11-03 23:12:16 +01:00
Sylvestre Ledru
8bd533ffe8
refactor(uptime): some minor improvements
2020-11-03 23:10:32 +01:00
Sylvestre Ledru
a3f3a050a8
Merge pull request #1618 from sylvestre/wc-clap
...
refactor(wc): use clap instead of getopts
2020-11-03 09:39:53 +01:00
Sylvestre Ledru
38e90b9a03
Merge pull request #1621 from sylvestre/clap-stat
...
refactor(stat): Move to clap
2020-11-03 08:37:39 +01:00
Sylvestre Ledru
57c83db6b6
Merge pull request #1616 from sylvestre/users
...
refactor(users): move to clap and simplify the code a bit
2020-11-03 08:37:16 +01:00
Sylvestre Ledru
bd41cb621b
Merge pull request #1620 from sylvestre/clap-printenv
...
refactor(printenv): use clap instead of getopts
2020-11-03 08:36:56 +01:00
Sylvestre Ledru
32ccd7d54d
Merge pull request #1619 from sylvestre/rmdir-clap
...
refactor(rmdir): use clap instead of getopts
2020-11-03 08:36:25 +01:00
Sylvestre Ledru
daf0f96b94
Update of the about description
...
Co-authored-by: Roy Ivy III <rivy.dev@gmail.com>
2020-11-02 22:47:55 +01:00
Sylvestre Ledru
2ad587ccbd
Update of the about description
...
Co-authored-by: Roy Ivy III <rivy.dev@gmail.com>
2020-11-02 22:32:44 +01:00
Sylvestre Ledru
1e37c29b1f
refactor(stat): Move to clap
2020-11-02 22:18:51 +01:00
Sylvestre Ledru
58099f4203
refactor(wc): use clap instead of getopts
2020-10-29 20:40:00 +01:00
Roy Ivy III
114fda0519
tests ~ (sub-crate factor) refactor divisor() test for improved readability
2020-10-26 15:06:29 -05:00
Roy Ivy III
ae06368cd8
polish/factor ~ correct spelling
2020-10-26 15:06:29 -05:00
Roy Ivy III
6a525c950d
perf/factor ~ tune number of stack inlined decomposition values (~1% time improvement)
2020-10-26 15:06:29 -05:00
Roy Ivy III
6eea8c5f30
perf/factor ~ improve factor() quotient and loop comparison (~6% time improvement)
2020-10-26 15:06:28 -05:00
Roy Ivy III
368f47381b
fix/factor ~ fix fault when factoring number composed of a squared factor
2020-10-26 15:06:28 -05:00
Roy Ivy III
8593b4c46c
tests ~ (sub-crate/factor) add tests for known prior factorization failures
2020-10-26 15:06:28 -05:00
Roy Ivy III
3bb3080170
factor/refactor ~ fix cargo clippy
complaints (allow many_single_char_names)
2020-10-26 15:06:28 -05:00
nicoo
0d39732300
factor::Decomposition: Inline a small number (4) of factors
...
This avoids allocating on the heap when factoring most numbers,
without using much space on the stack.
This is ~3.5% faster than the previous commit, and ~8.3% faster than “master”.
2020-10-26 15:06:28 -05:00
nicoo
78ae0cca31
factor: Slightly refactor main loop, fix bug
2020-10-26 15:06:28 -05:00
nicoo
b7b0c76b8e
factor::Decomposition: Optimise as a factor is never added twice
...
The invariant is checked by a debug_assert!, and follows from the previous
commit, as `dec` and `factors` only ever contains coprime numbers:
- true at the start: factor = ∅ and dec = { n¹ } ;
- on every loop iteration, we pull out an element `f` from `dec` and either:
- discover it is prime, and add it to `factors` ;
- split it into a number of coprime factors, that get reinserted into `dec`;
the invariant is maintained, as all divisors of `f` are coprime with all
numbers in `dec` and `factors` (as `f` itself is coprime with them.
As we only add elements to `Decomposition` objects that are coprime with the
existing ones, they are distinct.
2020-10-26 15:06:28 -05:00
nicoo
ce218e01b6
factor: Ensure we only need to find every single factor once [WiP]
...
~17% faster, many optimisation opportunities still missed >:)
2020-10-26 15:06:28 -05:00
nicoo
3743a3e1e7
factor: Derecursify and refactor
...
~7% slowdown, paves the way for upcoming improvements
2020-10-26 15:06:28 -05:00
nicoo
8643489096
factor::Factors: Use a RefCell rather than copy data when printing
...
~2.9% faster than the previous commit, ~11% faster than “master” overall.
2020-10-26 15:06:28 -05:00
nicoo
30f9cf32f2
factor::Decomposition: Use a flat vector representation
...
~18% faster than BTreeMap, and ~5% faster than 'master'
2020-10-26 15:06:27 -05:00
nicoo
b8ef58c002
factor::Factors: Split off a Decomposition type
...
The new type can be used to represent in-progress factorisations,
which contain non-prime factors.
2020-10-26 15:06:27 -05:00
nicoo
6158cd5714
factor: Introduce a type alias for exponents
...
This way, we can easily replace u8 with a larger type when moving to support
larger integers.
2020-10-26 15:06:27 -05:00
Sylvestre Ledru
af151703b3
refactor(rmdir): use clap instead of getopts
2020-10-26 09:53:55 +01:00
Sylvestre Ledru
17a99f8e53
refactor(printenv): use clap instead of getopts
2020-10-26 09:52:53 +01:00
Roy Ivy III
5837bc4fc9
Merge pull request #1610 from sylvestre/sort-clap
...
refactor(sort): move to use of 'clap'
2020-10-25 18:56:58 -05:00
Roy Ivy III
a9fb64abb4
Merge pull request #1612 from sylvestre/clap-seq
...
Move seq to use of 'clap'
2020-10-25 18:56:24 -05:00
Sylvestre Ledru
dc4eb79329
refactor/sort ~ changes based on PR feedback
...
- change `const`=>`static` and remove unneeded help/version (supplied by default by `clap`)
- update of the ABOUT description
- move to alphabetical order (where reasonable)
- rename OPT_FILES => ARG_FILES
- change the order of the declarations
2020-10-25 11:14:15 -05:00
Sylvestre Ledru
7fb5aaa108
only one file is allowed
...
Co-authored-by: Roy Ivy III <rivy.dev@gmail.com>
2020-10-25 17:07:32 +01:00
Sylvestre Ledru
bd339f142e
Improve the "about" description
...
Co-authored-by: Roy Ivy III <rivy.dev@gmail.com>
2020-10-25 17:07:17 +01:00
Sylvestre Ledru
58b0aeabee
refactor(sort): move to clap
2020-10-25 11:01:30 -05:00
Sylvestre Ledru
75e1c517a0
refactor/seq ~ changes based on PR feedback
...
- fix the ABOUT description
- rename OPT_NUMBERS => ARG_NUMBERS
- improve the get_usage of seq
- rename seq => incremetal
- `cargo fmt`
2020-10-25 10:58:14 -05:00
Sylvestre Ledru
e06aaace59
refactor/readline ~ changes based on PR feedback
...
- add a trailing "." to ABOUT for consistency
- rename OPT_FILES => ARG_FILES
- move to alphabetical order for OPTIONs (where reasonable)
Co-authored-by: Roy Ivy III <rivy.dev@gmail.com>
2020-10-25 10:54:24 -05:00
Sylvestre Ledru
733fe925ad
refactor(readlink): move to clap
2020-10-25 10:53:09 -05:00
Sylvestre Ledru
dfb922f66e
refactor(seq): use clap instead of doing arg mgmt by hand
2020-10-25 10:46:38 -05:00
Roy Ivy III
58d7d89e07
Merge pull request #1617 from sylvestre/clippy-fix
...
Fix some clippy warnings
2020-10-25 10:35:35 -05:00
Sylvestre Ledru
a12509f32e
Fix some clippy warnings
2020-10-25 15:50:51 +01:00
Sylvestre Ledru
4804e52c97
refactor(users): move to clap and simplify the code a bit
2020-10-25 15:29:02 +01:00
Sylvestre Ledru
7c3dccb981
remove the useless format
2020-10-25 12:28:27 +01:00
Sylvestre Ledru
0d4e36d5cd
reorder the args
2020-10-25 12:27:04 +01:00
Sylvestre Ledru
b72972e0b2
Rename OPT_FILES => ARG_FILES
...
Co-authored-by: Roy Ivy III <rivy.dev@gmail.com>
2020-10-25 12:22:07 +01:00
Sylvestre Ledru
8ad2fd3534
refactor(truncate): Move to clap
2020-10-23 00:40:46 +02:00
Kevin Burke
7fc1b16115
sort: fix panic on write to closed pipe
...
If the output of sort is piped to another program that closes the file
descriptor, sort currently panics. The GNU coreutils is able to handle
this case.
Replacing panic with crash_if_err reports the closed pipe and exits
with a return code, which seems like the correct behavior. Tested on
my Mac and the panic disappears.
Add a test which pipes data to sort - it won't protect against this
specific regression, but it increases the test coverage, at least.
Fixes #1608 .
2020-10-21 16:55:10 -07:00
Roy Ivy III
92075c7d14
refactor/polish ~ (factor) fix cargo clippy
complaint (unused_imports)
2020-10-16 20:25:49 -05:00
Sylvestre Ledru
fba62f39c6
Merge pull request #1603 from rivy/fix.warnings
...
Fix `cargo clippy` warnings
2020-10-12 09:23:15 +02:00
Roy Ivy III
77a04546f0
fix/printf ~ use calculated VERSION
2020-10-11 17:39:50 -05:00
Roy Ivy III
46f30f3836
refactor/polish ~ fix cargo clippy
complaint (stable_sort_primitive)
2020-10-10 20:35:35 -05:00
Roy Ivy III
10b6926ccc
refactor/polish ~ fix cargo clippy
complaint (allow match_like_matches_macro)
2020-10-10 20:35:35 -05:00
Roy Ivy III
6fa16343f1
refactor/polish ~ fix cargo clippy
complaint (same_item_push)
2020-10-10 20:35:35 -05:00
Roy Ivy III
7b4d81efd4
refactor/polish ~ fix cargo clippy
complaint (needless_collect)
2020-10-10 20:35:35 -05:00
Roy Ivy III
4a041f95e3
Merge pull request #1598 from sylvestre/nproc
...
cleanup(nproc): remove some artifacts from the clap migration
2020-10-10 16:28:22 -05:00
Roy Ivy III
0fa249a944
Fix tr
argument handling for missing arguments ( #1601 )
...
* tests/tr ~ confirm failure for missing argument(s)
* fix/tr ~ mimic GNU error reponse for missing argument(s)
2020-10-02 22:43:57 +02:00
Sylvestre Ledru
c660684a8c
nproc: use the variable name
2020-09-26 23:09:08 +02:00
Sylvestre Ledru
805801ec39
nproc: remove the extern crate declaration
2020-09-26 23:09:02 +02:00
nicoo
9a1c560aba
factor: Refactor and optimise the Factors
datastructure ( #1572 )
...
* factor: Introduce a type alias for exponents
This way, we can easily replace u8 with a larger type when moving to support
larger integers.
* factor::Factors: Split off a Decomposition type
The new type can be used to represent in-progress factorisations,
which contain non-prime factors.
* factor::Decomposition: Use a flat vector representation
~18% faster than BTreeMap, and ~5% faster than “master”.
* factor::Factors: Use a RefCell rather than copy data when printing
~2.9% faster than the previous commit, ~11% faster than “master” overall.
2020-09-21 21:44:50 +02:00
Jens Humrich
bfca334ec1
style issues
2020-09-17 12:40:48 +02:00
Katzmann1983
f322f72c34
Update src/uu/split/src/split.rs
...
Co-authored-by: Sylvestre Ledru <sledru@mozilla.com>
2020-09-17 10:27:40 +02:00
Jens Humrich
5a75905476
Add additional-suffix option to split
2020-09-16 17:59:39 +02:00
Roy Ivy III
2ff6b67077
stat: fix cargo clippy
complaint (unnecessary_sort_by) ( #1594 )
2020-09-04 08:01:53 +02:00
Roy Ivy III
c33284f38b
factor::numeric::gcd: modify divisor()
test to return correct true/false results for all possible inputs
2020-09-03 14:56:14 -05:00
nicoo
07eaa7fe5a
factor::numeric::gcd: Add explicit test for the 0 case
2020-09-03 14:56:14 -05:00
nicoo
c11cebc4d3
factor::numeric::gcd: Exclude the 0 case from test divisor
2020-09-03 14:56:10 -05:00
16yuki0702
19e967ef31
ls: deleting user defined max function ( #1591 )
...
This is trivial refactor.
```usize``` can call max method, so deleting user defined max function.
2020-08-26 09:42:27 +02:00
Roy Ivy III
74510d2fa4
refactor/polish ~ cargo fmt
2020-08-19 09:13:09 -05:00
Roy Ivy III
74200f368b
tests ~ (sub-crate/mknod) fix WSL variation in expected test values
2020-08-19 09:13:09 -05:00
Roy Ivy III
2a50dc42c1
tests ~ (sub-crate/factor) fix divisor(0,0)
test of factor::numeric::gcd() with early value check and return ( fixes #1587 )
2020-08-19 09:13:09 -05:00
Roy Ivy III
5478ca9108
tests ~ (sub-crate/od) fix expected f16 formatted test value
2020-08-10 10:19:42 -05:00
Roy Ivy III
b2483cb3c3
tests ~ (sub-crate/od) fix/remove inadvertent doc test (by using ignore
)
2020-08-10 10:19:42 -05:00
Roy Ivy III
49d17f9587
tests ~ (sub-crate/od) fix compiler error (mismatched types)
2020-08-10 10:19:42 -05:00
Roy Ivy III
4fa27345be
tests ~ (sub-crate/od) fix cargo clippy
complaints (from deprecated half::consts to f16::...)
2020-08-10 10:19:42 -05:00
Roy Ivy III
c7cb5cbc37
tests ~ (sub-crate/cat) fix incorrect test attribute usage
2020-08-10 10:19:42 -05:00
Roy Ivy III
c3893edf94
tests ~ (sub-crates) fix 'edition=2018' module import errors
...
- ref: <https://users.rust-lang.org/t/imports-can-only-refer-to-extern-crate-names/24388 > @@ <https://archive.is/iCaXp >
2020-08-10 10:19:42 -05:00
Roy Ivy III
925137afce
tests ~ (sub-crate/od) fix cargo clippy
complaints (unused imports)
2020-08-10 10:19:41 -05:00
Roy Ivy III
dd72893771
tests ~ (sub-crate/od) fix cargo clippy
complaints (deprecated std::error::Error::description)
2020-08-10 10:19:41 -05:00
nicoo
dc6b9a8d62
CI: Improve annotations ( #1584 )
...
* CI: Only run rustfmt in one environment
- This displays clippy warnings even when rustfmt fails.
- This avoids displaying 3 copies of the same rustfmt warning as Github
annotations.
- Avoids duplicated work.
* CI: Suppress warnings when building for the oldest toolchain version
We had cases of warnings emitted due to `rustc` bugs that were fixed
in non-obsolete versions.
* factor: Remove a workaround for warnings on obsolete rustc
2020-08-10 16:53:32 +02:00
Felipe Lema
ba6b55f117
feature[env]: Add support for --chdir=DIR
in env
( fixes #1568 ) ( #1569 )
2020-08-08 22:26:49 -05:00
nicoo
d9be24e354
factor: Make the implementation of GCD more readable ( #1576 )
...
* factor::numeric::gcd: Switch variable names to be more consistent
* factor::numeric::gcd: Improve comments
* factor::numeric::gcd: Extend loop invariant to v
2020-08-08 22:26:49 -05:00
nicoo
37f717f5e3
factor: Add tests against (random) numbers with known factorisations ( #1573 ) ( #1578 )
...
* factor::Factors: Derive implementations of Eq and PartialEq
* factors::Factors: Implement quickcheck::Arbitrary
This generates uniformly-distributed integers with known factorisations,
and will enable further testing.
* factor: Test against random numbers with known factorisations
* factor::Factors::arbitrary: Simplify method signature
2020-08-08 22:26:25 -05:00
nicoo
34a5941ee9
factor::numeric: Add more property-based tests ( #1577 )
...
* factor::numeric::gcd: Rename test against the Euclidean algorithm
* factor::numeric::gcd: Add various property-based tests
* factor::numeric::modular_inverse: Rename test
* factor::numeric::modular_inverse: Add test on random values
2020-08-03 14:00:34 +02:00
nicoo
70828329ba
factor::miller_rabin: Deduplicate parametrized_check macro ( #1575 )
...
* factor::miller_rabin::tests::first_composite: Drop useless generic
* factor::miller_rabin::tests: Reuse parametrized_check macro
2020-08-03 13:58:09 +02:00
nicoo
1eabda91cf
factor: Split numeric.rs into multiple modules ( #1567 )
...
* factor::numeric: Start refactoring into multiple submodules
No change to the module's interface, but it should make it much easier to
keep the tests right next to the code they are related to.
Moreover, build.rs' dependency is now limited to numeric::{modular_inverse,
traits}, meaning that the rest of it can use build-time generated tables etc.
* factor::numeric: Move gcd (and its test) to a submodule
* factor::numeric: Move Montgomery arithmetic to its own module
Finally hollowed-out numeric.rs
* factor: Move numeric.rs to numeric/mod.rs
* factor::numeric: Fix an erroneous lint on obsolete Rust versions
2020-08-02 20:28:00 +02:00
Sylvestre Ledru
85e2e1d0ee
Merge pull request #1566 from nbraud/factor/miller-rabin/copyright
...
factor::miller_rabin: Add missing copyright header in source file
2020-08-02 14:09:44 +02:00
nicoo
645e9a24bd
factor::miller_rabin: Add missing copyright header in source file
2020-07-26 14:59:30 +02:00
Roy Ivy III
c36d71ba43
refactor/polish ~ fix cargo clippy
complaint (needless_lifetimes)
2020-07-25 11:09:10 -05:00
Roy Ivy III
305c3cbcdb
refactor/polish ~ fix cargo clippy
complaint (bind_instead_of_map)
2020-07-25 11:09:10 -05:00
Roy Ivy III
326ff36793
refactor/polosh ~ fix cargo clippy
complaint (reversed_empty_ranges)
2020-07-25 11:09:10 -05:00
Roy Ivy III
a6d7379b97
Merge pull request #1563 from nbraud/factor/faster/gcd
...
factor/perf ~ speed up factor::numeric::gcd
2020-07-25 11:07:57 -05:00
nicoo
6bef6306c0
factor::numeric::gcd: Avoid redundant u64::trailing_zeros and shifts
...
7 to 10% faster, according to criterion.
2020-07-25 15:04:57 +02:00
nicoo
3e55139c13
factor::miller_rabbin::Result: Mark as #[must_use]
...
Ignoring a value of that type is a bug: they are only produced by
`miller_rabbin::test`, which is a pure, but expensive, function.
As such, an ignored value is always either a mistake, or an easy
optimisation opportunity (just remove the useless call to `test`).
2020-07-24 23:06:08 +02:00
nicoo
ecc3e2db24
factor::miller_rabin::test: Minor readability improvement
2020-07-24 23:06:08 +02:00
nicoo
e415b17c01
factor::miller_rabin: Remove duplicated work
...
The duplicate work was introduced in 2015.
2020-07-24 23:06:06 +02:00
nicoo
29d45e472d
factor::numeric::gcd: Implement Stein's binary GCD algorithm
...
Also add a property-based test against the Euclidean implementation.
numeric::gcd got ~50-65% faster, according to criterion. The effect on the
overall system is small, but later PRs will use a lot more GCD computations.
2020-07-24 23:00:32 +02:00
nicoo
4f23767b85
factor::numeric::gcd: Add criterion-powered benchmark
...
The function had to be made `pub`, this is a [known limitation] of Criterion.
[known limitation]: https://bheisler.github.io/criterion.rs/book/user_guide/known_limitations.html
2020-07-24 22:58:26 +02:00
nicoo
1b593d94c9
factor: Update rand dependency to v0.7
2020-07-24 22:57:08 +02:00
nicoo
9a80ab7741
factor::numeric::DoubleInt: Document the DoubleWidth associated type
2020-07-24 11:28:26 -05:00
nicoo
17c69674eb
factor::numeric::Int: Remove from_u128
method
...
It was unused, the debug assertions only need `to_u128`.
2020-07-24 11:28:26 -05:00
nicoo
1172af09c0
factor::numeric::DoubleInt: Clarify methods and associated types
...
- `DoubleInt::Double` renamed to `DoubleWidth`
- `{as,from}_double()` renamed to `{as,from}_double_width()`.
This should hopefully clarify that this is not a “double precision”
floating-point type, but an integer type with a larger range (used
for storing intermediate results, typ. from a multiplication)
2020-07-24 11:28:26 -05:00
nicoo
86a4749e3a
factor::numeric: fix original "Generalise modular inverse computation"
2020-07-24 11:28:12 -05:00
nicoo
6e228d3184
Merge branches 'factor/faster/{centralise_logic, montgomery32}'
2020-07-05 00:20:16 +02:00
nicoo
4cfe754551
factor::miller_rabin::is_prime: Fix bug
...
Montgomery only works for odd n, so attempting to construct an instance
for an even number results in a panic!
The most obvious solution is to special-case even numbers.
2020-07-05 00:08:49 +02:00
nicoo
9b0f131135
Fix bug in factor::factor::factor (>_>")
...
Non-prime numbers, such as 0 or 1, shouldn't be inserted in the factorisation.
2020-07-05 00:07:38 +02:00
nicoo
e9e263ac66
factor::Factors: Derive Clone and Debug
...
Useful for printing out in-progress factorisations when debugging.
2020-07-05 00:07:33 +02:00
nicoo
7bdc81b882
factor: Add a first property-based test
2020-07-05 00:07:16 +02:00
nicoo
dcc22188ba
factor: Fix clippy warnings
2020-07-05 00:05:45 +02:00
nicoo
f1d1cb80e4
factor::Factors: Generalise invariant check (from prime() to add())
2020-07-05 00:05:45 +02:00
nicoo
2d2b6faab4
factor: Avoid moving data around in main factoring loop
...
Instead, the same `Factors` object is passed around through the execution.
~10% faster.
2020-07-05 00:05:45 +02:00
nicoo
6713d2ad62
factor: Move recursive factoring logic from rho to factor
...
No functional change, but prepares a coming optimisation.
2020-07-05 00:05:45 +02:00
nicoo
bd4d6fcac5
factor: Split the CLI and I/O code off the factoring logic
2020-07-05 00:05:45 +02:00
nicoo
6256750376
factor::miller_rabin: Use a macro to instantiate every test
2020-07-05 00:04:56 +02:00
nicoo
7a1b86c9c2
factor::numeric::tests: Use a macro to instantiate every test
2020-07-05 00:04:53 +02:00
nicoo
cbcc760f83
factor::miller_rabin: Squash another bug! >:3
...
Detected by the testsuite improvement just prior.
2020-07-05 00:04:49 +02:00
nicoo
3d6fdffe14
factor::miller_rabin: Generalise tests to 32 and 64b Montgomery
2020-07-05 00:04:29 +02:00
nicoo
9b149a759b
factor::miller_rabin: Hoist edge-cases (even, <2) out of test()
...
test() takes a modulus that is known to not be even or <2 (otherwise the
Montgomery value could not be constructed), so those checks can be hoisted
into is_prime() and out of the critical path.
2020-07-05 00:04:26 +02:00
nicoo
4f08e28167
factor::miller_rabin: Add property-based test
2020-07-05 00:04:08 +02:00
nicoo
d2fa0fe63c
factor::miller_rabin::tests: small_composites → small_semiprimes
...
This is more descriptive, as semiprime are the products of 2 primes;
all semiprimes are composite, but not all composite numbers are semiprime.
2020-07-05 00:01:48 +02:00
nicoo
1e4d824829
factor::miller_rabin: Add negative test over all small composites
2020-07-05 00:01:44 +02:00
nicoo
600268c6e4
factor::miller_rabin::tests: Refactor
2020-07-05 00:01:40 +02:00
nicoo
0a1200bdb8
factor::miller_rabin: Add test for the largest 64b composite numbers
2020-07-05 00:01:37 +02:00
nicoo
308290325a
factor::miller_rabin::is_prime: Fix bug
...
Montgomery<_> only works for odd n, so attempting to construct an instance
for an even number results in a panic!
The most obvious solution is to special-case even numbers.
2020-07-05 00:01:33 +02:00
nicoo
d2b43f49f9
factor::numeric::OverflowingAdd: Generate impls with a macro
2020-07-05 00:01:21 +02:00
nicoo
b25c77c5f9
factor::numeric: Generate implementations of DoubleInt with a macro
2020-07-05 00:01:21 +02:00
nicoo
f95f977f98
factor::numeric: Generate implementations of Int with a macro
2020-07-05 00:01:21 +02:00
nicoo
53954badd7
factor::numeric: Refactor away the use of {To,From}Primitives
2020-07-05 00:01:21 +02:00
nicoo
19a8231fb2
factor::numeric::Arithmetic: Rename associated type I to ModInt
2020-07-05 00:01:21 +02:00
nicoo
caa79a1261
factor::numeric: Split Int and DoubleInt traits
2020-07-05 00:01:21 +02:00
nicoo
28244413d1
factor::numeric: Document when to remove OverflowingAdd trait
2020-07-05 00:01:21 +02:00
nicoo
3f79be0219
factor::numeric: Use debug_assert! for runtime assertions.
2020-07-05 00:01:21 +02:00
nicoo
774feb0a40
factor::numeric: Generalise tests for Arithmetic trait
2020-07-05 00:01:21 +02:00
Alex Lyon
4d28f48ad9
factor: combine Montgomery and Montgomery32
2020-07-05 00:01:21 +02:00
nicoo
a440807e6c
factor::miller_rabin: Use a specialized basis for 32b integers
...
~3% faster
2020-07-05 00:01:21 +02:00
nicoo
e68bb192f2
factor::numeric: Add a 32b Montgomery variant [WiP]
...
~32% faster
2020-07-05 00:01:21 +02:00
nicoo
43ee92c40f
factor::numeric: Generalise modular inverse computation
2020-07-05 00:01:21 +02:00
Alex Lyon
9de82d92b0
Merge pull request #1557 from nbraud/factor/issue_1556
...
factor::miller_rabin: Fix bug #1556
2020-06-24 04:53:32 -07:00
Alex Lyon
700d51a92b
Merge pull request #1528 from sylvestre/cp-no-deref
...
feature(cp) implement -P/--no-deference
2020-06-23 23:05:26 -07:00
nicoo
abf579975c
factor::miller_rabin: Fix bug in primality test
...
Introduced in 6b9585b1
(#1525 : Performance improvements for `factor`).
Closes #1556
2020-06-23 16:19:16 +02:00
nicoo
c5c86b00e9
factor::miller_rabin: Add tests reproducing #1556
2020-06-23 16:14:52 +02:00
nicoo
8e040bbf1a
factor::table: Optimise the size of the precomputed table
...
A too-large precomputed table actually slows down the program: we spend
time fetching it from disk and from memory (into the CPU's cache), and
larger prime factors are more unlikely to occur in random integers (prime p
occurs with probability ~1/p when sampling 64b numbers uniformly-at-random)
The new value was chosen after measuring the execution time (for all
integers between 2 and 10⁷) for a broad set of values:
| n | time (s) |
|------|----------|
| 16 | 40.84 |
| 32 | 34.491 |
| 64 | 29.044 |
| 128 | 25.121 |
| 192 | 23.98 |
| 256 | 23.102 |
| 256 | 24.93 |
| 272 | 23.57 |
| 288 | 23.85 |
| 304 | 23.91 |
| 320 | 23.24 |
| 329 | 23.45 |
| 336 | 23.55 |
| 352 | 23.09 |
| 368 | 23.65 |
| 384 | 23.32 |
| 384 | 23.36 |
| 400 | 23.30 |
| 416 | 23.38 |
| 432 | 23.42 |
| 448 | 23.95 |
| 448 | 24.00 |
| 464 | 23.81 |
| 480 | 23.55 |
| 496 | 24.10 |
| 512 | 24.101 |
| 512 | 24.23 |
| 1027 | 29.864 |
2020-06-20 22:22:55 +02:00
nicoo
9d992b77b2
factor: Keep the primes table size in a single place
2020-06-20 22:22:55 +02:00
nicoo
b956e632e1
factor::table: Coalesce accesses to the factors
table
...
~5.6% faster
2020-06-20 22:22:55 +02:00
Sylvestre Ledru
2d62097843
feature(cp): Manage -P & -R
2020-06-20 10:49:15 +02:00
nicoo
0518e06053
factor::rho: Minor refactor for readability
2020-06-20 10:39:56 +02:00