diff --git a/Cargo.lock b/Cargo.lock index 56b4877..df7efb7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -128,9 +128,9 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "clap" -version = "4.5.20" +version = "4.5.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" +checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f" dependencies = [ "clap_builder", "clap_derive", @@ -138,9 +138,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.20" +version = "4.5.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" +checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec" dependencies = [ "anstream", "anstyle", @@ -165,9 +165,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" +checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7" [[package]] name = "colorchoice" @@ -216,9 +216,9 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "hashbrown" -version = "0.15.1" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" dependencies = [ "allocator-api2", "equivalent", @@ -240,15 +240,15 @@ checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "itoa" -version = "1.0.11" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" [[package]] name = "libc" -version = "0.2.162" +version = "0.2.166" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" +checksum = "c2ccc108bbc0b1331bd061864e7cd823c0cab660bbe6970e66e2c0614decde36" [[package]] name = "linux-raw-sys" @@ -384,16 +384,16 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.89" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] [[package]] name = "q" -version = "1.1.2" +version = "1.1.3" dependencies = [ "anyhow", "clap", @@ -455,9 +455,9 @@ checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustix" -version = "0.38.40" +version = "0.38.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99e4ea3e1cdc4b559b8e5650f9c8e5998e3e5c1343b4eaf034565f32318d63c0" +checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" dependencies = [ "bitflags", "errno", @@ -494,9 +494,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.132" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" +checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" dependencies = [ "itoa", "memchr", @@ -518,9 +518,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.87" +version = "2.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" +checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" dependencies = [ "proc-macro2", "quote", @@ -545,9 +545,9 @@ checksum = "7e51b68083f157f853b6379db119d1c1be0e6e4dec98101079dec41f6f5cf6df" [[package]] name = "unicode-ident" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] name = "unicode-width" diff --git a/Cargo.toml b/Cargo.toml index 9a6d2e3..9861f44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,6 @@ -cargo-features = ["edition2024"] - [package] name = "q" -version = "1.1.2" +version = "1.1.3" authors = ["jkjkmxmx "] edition = "2024" description = "Implementation of ideal unique factorization of quadratic integer domains" @@ -10,14 +8,14 @@ repository = "https://github.com/yhx-12243/q" [dependencies] anyhow = { version = "1.0.93", features = ["backtrace"] } -clap = { version = "4.5.20", features = ["derive", "unicode", "wrap_help", "env", "string", "unstable-v5"] } +clap = { version = "4.5.21", features = ["derive", "unicode", "wrap_help", "env", "string", "unstable-v5"] } clap_derive = { version = "4.5.18", features = ["unstable-v5"] } -hashbrown = { version = "0.15.1", features = ["serde"] } +hashbrown = { version = "0.15.2", features = ["serde"] } nix = { version = "0.29.0", features = ["signal"] } num = { version = "0.4.3", features = ["rand"] } rand = { version = "0.8.5", features = ["log", "nightly"] } serde = { version = "1.0.215", features = ["derive"] } -serde_json = { version = "1.0.132", features = ["float_roundtrip"] } +serde_json = { version = "1.0.133", features = ["float_roundtrip"] } smallvec = { version = "1.13.2", features = ["const_new", "may_dangle", "specialization", "union"] } [lints.rust] diff --git a/src/discriminant.rs b/src/discriminant.rs index 294f6d6..360a874 100644 --- a/src/discriminant.rs +++ b/src/discriminant.rs @@ -1,4 +1,4 @@ -use std::num::NonZeroI64; +use core::num::NonZeroI64; static mut DISCRIMINANT: NonZeroI64 = unsafe { NonZeroI64::new_unchecked(-1) }; static mut DISC_STR: String = String::new(); diff --git a/src/factor.rs b/src/factor.rs index a776e1c..507aaf7 100644 --- a/src/factor.rs +++ b/src/factor.rs @@ -1,9 +1,7 @@ -use nix::{ - sys::signal::{SigHandler, Signal, kill, signal}, - unistd::Pid, +use core::{ + sync::atomic::{AtomicI32, Ordering}, + time::Duration, }; -use num::{BigUint, One}; -use serde::Deserialize; use std::{ borrow::Cow, collections::{ @@ -14,10 +12,16 @@ use std::{ io::{BufRead, BufReader, Write}, path::PathBuf, process::{Command, Stdio}, - sync::atomic::{AtomicI32, Ordering}, - time::{Duration, Instant}, + time::Instant, }; +use nix::{ + sys::signal::{SigHandler, Signal, kill, signal}, + unistd::Pid, +}; +use num::{BigUint, One}; +use serde::Deserialize; + use crate::CONFIG; struct DropGuard(PathBuf); @@ -52,9 +56,9 @@ pub fn factor(ns: [&BigUint; N]) -> anyhow::Result<[Vec<(BigUint return Ok(result); } - let t1 = std::time::Instant::now(); + let t1 = Instant::now(); #[allow(clippy::transmute_undefined_repr)] - let td = unsafe { std::mem::transmute::(t1) }; + let td = unsafe { core::mem::transmute::(t1) }; let mut path = CONFIG .get() .map_or_else(|| PathBuf::from("./"), |config| config.dir.clone()); @@ -139,7 +143,7 @@ pub fn factor(ns: [&BigUint; N]) -> anyhow::Result<[Vec<(BigUint #[cfg(test)] mod tests { - use std::str::FromStr; + use core::str::FromStr; use num::BigUint; diff --git a/src/ideal.rs b/src/ideal.rs index 5d42384..2afb971 100644 --- a/src/ideal.rs +++ b/src/ideal.rs @@ -1,4 +1,9 @@ -use std::{cmp::Ordering, fmt::Formatter, io, str::FromStr}; +use core::{ + cmp::Ordering, + fmt::{self, Formatter}, + str::FromStr, +}; +use std::io; use num::{ BigInt, BigUint, Integer, One, Zero, @@ -314,7 +319,7 @@ impl Ideal { Ok(result) } - fn tex_common(&self, f: &mut Formatter<'_>, inner: fn(&QI, &mut Formatter) -> std::fmt::Result) -> std::fmt::Result { + fn tex_common(&self, f: &mut Formatter<'_>, inner: fn(&QI, &mut Formatter) -> fmt::Result) -> fmt::Result { f.write_str("\\left(")?; if self.is_zero() { f.write_str("0")?; @@ -329,11 +334,11 @@ impl Ideal { f.write_str("\\right)") } - pub fn latex(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + pub fn latex(&self, f: &mut Formatter<'_>) -> fmt::Result { self.tex_common(f, QI::latex) } - pub fn tex(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + pub fn tex(&self, f: &mut Formatter<'_>) -> fmt::Result { self.tex_common(f, QI::tex) } @@ -369,8 +374,8 @@ impl Ideal { } } -impl core::fmt::Display for Ideal { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { +impl fmt::Display for Ideal { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { let mut builder = f.debug_tuple(""); for qi in &self.0 { builder.field_with(|f| qi.fmt(f)); @@ -381,7 +386,7 @@ impl core::fmt::Display for Ideal { #[cfg(test)] mod tests { - use std::num::NonZeroI64; + use core::num::NonZeroI64; use num::BigInt; use smallvec::smallvec; diff --git a/src/pell.rs b/src/pell.rs index 55f27e3..c34ed7f 100644 --- a/src/pell.rs +++ b/src/pell.rs @@ -1,21 +1,17 @@ -use std::num::Wrapping; +use core::num::Wrapping; use hashbrown::HashSet; use num::{ - bigint::{IntDigits, Sign}, BigInt, BigUint, Integer, One, Signed, Zero, + bigint::{IntDigits, Sign}, }; -use crate::{qi::QI, qr::quadratic_residue, CONFIG}; +use crate::{CONFIG, qi::QI, qr::quadratic_residue}; #[inline] fn mod_2_64_signed(x: &BigInt) -> Wrapping { let y = mod_2_64(x.magnitude()); - if x.is_negative() { - -y - } else { - y - } + if x.is_negative() { -y } else { y } } #[inline] @@ -265,11 +261,7 @@ pub fn work_neg(D: u64, p: &BigUint) -> Option { let x = { let a = &Q * &y; let b = p * &z * 2u32; - if a < b { - b - a - } else { - a - b - } + if a < b { b - a } else { a - b } }; Some(QI { @@ -292,11 +284,7 @@ pub fn work_neg(D: u64, p: &BigUint) -> Option { let x = { let a = &Q * &y; let b = p * &z; - if a < b { - b - a - } else { - a - b - } + if a < b { b - a } else { a - b } }; Some(QI { @@ -366,11 +354,7 @@ pub fn work_pos(D: u64, p: &BigUint) -> Option { let x = { let a = &Q * &y; let b = p * &z * 2u32; - if a < b { - b - a - } else { - a - b - } + if a < b { b - a } else { a - b } }; Some(QI { @@ -401,11 +385,7 @@ pub fn work_pos(D: u64, p: &BigUint) -> Option { let x = { let a = &Q * &y; let b = p * &z; - if a < b { - b - a - } else { - a - b - } + if a < b { b - a } else { a - b } }; Some(QI { diff --git a/src/qi.rs b/src/qi.rs index e07cef2..db45f37 100644 --- a/src/qi.rs +++ b/src/qi.rs @@ -1,4 +1,4 @@ -use std::fmt::{Display, Formatter, Write}; +use core::fmt::{self, Display, Formatter, Write}; use num::{BigInt, BigUint, Integer, One, Signed, Zero, bigint::Sign}; @@ -154,7 +154,7 @@ impl QI { } } - fn tex_common(&self, f: &mut Formatter<'_>, plain: bool) -> std::fmt::Result { + fn tex_common(&self, f: &mut Formatter<'_>, plain: bool) -> fmt::Result { let e = discriminant::is4kp1(); let s = discriminant::get_latex(); if self.b.is_zero() { @@ -205,17 +205,17 @@ impl QI { } } - pub fn latex(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + pub fn latex(&self, f: &mut Formatter<'_>) -> fmt::Result { self.tex_common(f, false) } - pub fn tex(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + pub fn tex(&self, f: &mut Formatter<'_>) -> fmt::Result { self.tex_common(f, true) } } impl Display for QI { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { let e = discriminant::is4kp1(); let s = discriminant::get_str(); if !e { @@ -239,7 +239,7 @@ impl From for QI { #[cfg(test)] mod tests { - use std::num::NonZeroI64; + use core::num::NonZeroI64; use num::BigInt; diff --git a/src/qr.rs b/src/qr.rs index 86722aa..620e292 100644 --- a/src/qr.rs +++ b/src/qr.rs @@ -1,4 +1,4 @@ -use std::ptr::NonNull; +use core::ptr::NonNull; use num::{ BigUint, Integer, One, Zero, @@ -82,7 +82,7 @@ pub fn quadratic_residue(n: &BigUint, p: &BigUint) -> Option { #[cfg(test)] mod test { - use std::str::FromStr; + use core::str::FromStr; use num::BigUint;