Skip to content

Commit

Permalink
build: cargo edition 2024 is stable
Browse files Browse the repository at this point in the history
  • Loading branch information
yhx-12243 committed Nov 27, 2024
1 parent 2dcade2 commit efd9dc4
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 83 deletions.
46 changes: 23 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
cargo-features = ["edition2024"]

[package]
name = "q"
version = "1.1.2"
version = "1.1.3"
authors = ["jkjkmxmx <[email protected]>"]
edition = "2024"
description = "Implementation of ideal unique factorization of quadratic integer domains"
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]
Expand Down
2 changes: 1 addition & 1 deletion src/discriminant.rs
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
24 changes: 14 additions & 10 deletions src/factor.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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);
Expand Down Expand Up @@ -52,9 +56,9 @@ pub fn factor<const N: usize>(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::<Instant, Duration>(t1) };
let td = unsafe { core::mem::transmute::<Instant, Duration>(t1) };
let mut path = CONFIG
.get()
.map_or_else(|| PathBuf::from("./"), |config| config.dir.clone());
Expand Down Expand Up @@ -139,7 +143,7 @@ pub fn factor<const N: usize>(ns: [&BigUint; N]) -> anyhow::Result<[Vec<(BigUint

#[cfg(test)]
mod tests {
use std::str::FromStr;
use core::str::FromStr;

use num::BigUint;

Expand Down
19 changes: 12 additions & 7 deletions src/ideal.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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")?;
Expand All @@ -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)
}

Expand Down Expand Up @@ -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));
Expand All @@ -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;
Expand Down
36 changes: 8 additions & 28 deletions src/pell.rs
Original file line number Diff line number Diff line change
@@ -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<u64> {
let y = mod_2_64(x.magnitude());
if x.is_negative() {
-y
} else {
y
}
if x.is_negative() { -y } else { y }
}

#[inline]
Expand Down Expand Up @@ -265,11 +261,7 @@ pub fn work_neg(D: u64, p: &BigUint) -> Option<QI> {
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 {
Expand All @@ -292,11 +284,7 @@ pub fn work_neg(D: u64, p: &BigUint) -> Option<QI> {
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 {
Expand Down Expand Up @@ -366,11 +354,7 @@ pub fn work_pos(D: u64, p: &BigUint) -> Option<QI> {
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 {
Expand Down Expand Up @@ -401,11 +385,7 @@ pub fn work_pos(D: u64, p: &BigUint) -> Option<QI> {
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 {
Expand Down
12 changes: 6 additions & 6 deletions src/qi.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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 {
Expand All @@ -239,7 +239,7 @@ impl From<BigInt> for QI {

#[cfg(test)]
mod tests {
use std::num::NonZeroI64;
use core::num::NonZeroI64;

use num::BigInt;

Expand Down
Loading

0 comments on commit efd9dc4

Please sign in to comment.