Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split into separate crates #84

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .cargo/config.toml

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/target
**/target/
Cargo.lock
21 changes: 17 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[workspace]

[package]
name = "ac-library-rs"
version = "0.1.0"
Expand All @@ -10,10 +12,21 @@ keywords = ["competitive"]
categories = ["algorithms", "data-structures"]
publish = false

[package.metadata.docs.rs]
rustdoc-args = ["--html-in-header", "./katex-header.html"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

[dev-dependencies]
proconio = "=0.3.6"
rand = "0.7.3"
__acl_convolution = { package = "acl_convolution", version = "0.1.0", path = "./acl_convolution" }
__acl_dsu = { package = "acl_dsu" , version = "0.1.0", path = "./acl_dsu" }
__acl_fenwicktree = { package = "acl_fenwicktree", version = "0.1.0", path = "./acl_fenwicktree" }
__acl_lazysegtree = { package = "acl_lazysegtree", version = "0.1.0", path = "./acl_lazysegtree" }
__acl_math = { package = "acl_math" , version = "0.1.0", path = "./acl_math" }
__acl_maxflow = { package = "acl_maxflow" , version = "0.1.0", path = "./acl_maxflow" }
__acl_mincostflow = { package = "acl_mincostflow", version = "0.1.0", path = "./acl_mincostflow" }
__acl_modint = { package = "acl_modint" , version = "0.1.0", path = "./acl_modint" }
__acl_scc = { package = "acl_scc" , version = "0.1.0", path = "./acl_scc" }
__acl_segtree = { package = "acl_segtree" , version = "0.1.0", path = "./acl_segtree" }
__acl_string = { package = "acl_string" , version = "0.1.0", path = "./acl_string" }
__acl_twosat = { package = "acl_twosat" , version = "0.1.0", path = "./acl_twosat" }
22 changes: 22 additions & 0 deletions acl_convolution/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "acl_convolution"
version = "0.1.0"
authors = ["rust-lang-ja Developers"]
edition = "2018"
description = "A Rust port of AtCoder Library (ACL)."
license = "CC0-1.0"
repository = "https://github.com/rust-lang-ja/ac-library-rs"
keywords = ["competitive"]
categories = ["algorithms", "data-structures"]
publish = false

[package.metadata.docs.rs]
rustdoc-args = ["--html-in-header", "./katex-header.html"]

[dependencies]
__acl_internal_bit = { package = "acl_internal_bit", version = "0.1.0", path = "../acl_internal_bit" }
__acl_internal_math = { package = "acl_internal_math", version = "0.1.0", path = "../acl_internal_math" }
__acl_modint = { package = "acl_modint", version = "0.1.0", path = "../acl_modint" }

[dev-dependencies]
rand = "0.7.3"
File renamed without changes.
18 changes: 8 additions & 10 deletions src/convolution.rs → acl_convolution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ macro_rules! modulus {
const VALUE: u32 = $name as _;
const HINT_VALUE_IS_PRIME: bool = true;

fn butterfly_cache() -> &'static ::std::thread::LocalKey<::std::cell::RefCell<::std::option::Option<crate::modint::ButterflyCache<Self>>>> {
fn butterfly_cache() -> &'static ::std::thread::LocalKey<::std::cell::RefCell<::std::option::Option<self::modint::ButterflyCache<Self>>>> {
thread_local! {
static BUTTERFLY_CACHE: ::std::cell::RefCell<::std::option::Option<crate::modint::ButterflyCache<$name>>> = ::std::default::Default::default();
static BUTTERFLY_CACHE: ::std::cell::RefCell<::std::option::Option<self::modint::ButterflyCache<$name>>> = ::std::default::Default::default();
}
&BUTTERFLY_CACHE
}
Expand All @@ -19,10 +19,11 @@ macro_rules! modulus {
};
}

use crate::{
internal_bit, internal_math,
modint::{ButterflyCache, Modulus, RemEuclidU32, StaticModInt},
};
extern crate __acl_internal_bit as internal_bit;
extern crate __acl_internal_math as internal_math;
extern crate __acl_modint as modint;

use self::modint::{ButterflyCache, Modulus, RemEuclidU32, StaticModInt};
use std::{
cmp,
convert::{TryFrom, TryInto as _},
Expand Down Expand Up @@ -232,10 +233,7 @@ fn prepare<M: Modulus>() -> ButterflyCache<M> {

#[cfg(test)]
mod tests {
use crate::{
modint::{Mod998244353, Modulus, StaticModInt},
RemEuclidU32,
};
use super::modint::{self, Mod998244353, Modulus, RemEuclidU32, StaticModInt};
use rand::{rngs::ThreadRng, Rng as _};
use std::{
convert::{TryFrom, TryInto as _},
Expand Down
16 changes: 16 additions & 0 deletions acl_dsu/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "acl_dsu"
version = "0.1.0"
authors = ["rust-lang-ja Developers"]
edition = "2018"
description = "A Rust port of AtCoder Library (ACL)."
license = "CC0-1.0"
repository = "https://github.com/rust-lang-ja/ac-library-rs"
keywords = ["competitive"]
categories = ["algorithms", "data-structures"]
publish = false

[package.metadata.docs.rs]
rustdoc-args = ["--html-in-header", "./katex-header.html"]

[dependencies]
15 changes: 15 additions & 0 deletions acl_dsu/katex-header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-AfEj0r4/OFrOo5t7NnNe46zW/tFgW6x/bCJG8FqQCEo3+Aro6EYUG4+cU+KJWu/X" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-g7c+Jr9ZivxKLnZTDUhnkOnsh30B4H0rpLUpJ4jAIKs4fnJI+sEnkvrMWph2EDg4" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-mll67QQFJfxn0IYznZYonOWZ644AWYC+Pt2cHqMaRhXVrursRwvLnLaebdGIlYNa" crossorigin="anonymous"></script>
<script>
document.addEventListener("DOMContentLoaded", () => {
renderMathInElement(document.body, {
delimiters: [
{left: "$$", right: "$$", display: true},
{left: "\\[", right: "\\]", display: true},
{left: "$", right: "$", display: false},
{left: "\\(", right: "\\)", display: false}
],
})
});
</script>
File renamed without changes.
16 changes: 16 additions & 0 deletions acl_fenwicktree/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "acl_fenwicktree"
version = "0.1.0"
authors = ["rust-lang-ja Developers"]
edition = "2018"
description = "A Rust port of AtCoder Library (ACL)."
license = "CC0-1.0"
repository = "https://github.com/rust-lang-ja/ac-library-rs"
keywords = ["competitive"]
categories = ["algorithms", "data-structures"]
publish = false

[package.metadata.docs.rs]
rustdoc-args = ["--html-in-header", "./katex-header.html"]

[dependencies]
15 changes: 15 additions & 0 deletions acl_fenwicktree/katex-header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-AfEj0r4/OFrOo5t7NnNe46zW/tFgW6x/bCJG8FqQCEo3+Aro6EYUG4+cU+KJWu/X" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-g7c+Jr9ZivxKLnZTDUhnkOnsh30B4H0rpLUpJ4jAIKs4fnJI+sEnkvrMWph2EDg4" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-mll67QQFJfxn0IYznZYonOWZ644AWYC+Pt2cHqMaRhXVrursRwvLnLaebdGIlYNa" crossorigin="anonymous"></script>
<script>
document.addEventListener("DOMContentLoaded", () => {
renderMathInElement(document.body, {
delimiters: [
{left: "$$", right: "$$", display: true},
{left: "\\[", right: "\\]", display: true},
{left: "$", right: "$", display: false},
{left: "\\(", right: "\\)", display: false}
],
})
});
</script>
File renamed without changes.
16 changes: 16 additions & 0 deletions acl_internal_bit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "acl_internal_bit"
version = "0.1.0"
authors = ["rust-lang-ja Developers"]
edition = "2018"
description = "A Rust port of AtCoder Library (ACL)."
license = "CC0-1.0"
repository = "https://github.com/rust-lang-ja/ac-library-rs"
keywords = ["competitive"]
categories = ["algorithms", "data-structures"]
publish = false

[package.metadata.docs.rs]
rustdoc-args = ["--html-in-header", "./katex-header.html"]

[dependencies]
15 changes: 15 additions & 0 deletions acl_internal_bit/katex-header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-AfEj0r4/OFrOo5t7NnNe46zW/tFgW6x/bCJG8FqQCEo3+Aro6EYUG4+cU+KJWu/X" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-g7c+Jr9ZivxKLnZTDUhnkOnsh30B4H0rpLUpJ4jAIKs4fnJI+sEnkvrMWph2EDg4" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-mll67QQFJfxn0IYznZYonOWZ644AWYC+Pt2cHqMaRhXVrursRwvLnLaebdGIlYNa" crossorigin="anonymous"></script>
<script>
document.addEventListener("DOMContentLoaded", () => {
renderMathInElement(document.body, {
delimiters: [
{left: "$$", right: "$$", display: true},
{left: "\\[", right: "\\]", display: true},
{left: "$", right: "$", display: false},
{left: "\\(", right: "\\)", display: false}
],
})
});
</script>
2 changes: 1 addition & 1 deletion src/internal_bit.rs → acl_internal_bit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// - `bsf` = `__builtin_ctz`: is equivalent to `{integer}::trailing_zeros`

#[allow(dead_code)]
pub(crate) fn ceil_pow2(n: u32) -> u32 {
pub fn ceil_pow2(n: u32) -> u32 {
32 - n.saturating_sub(1).leading_zeros()
}

Expand Down
16 changes: 16 additions & 0 deletions acl_internal_math/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "acl_internal_math"
version = "0.1.0"
authors = ["rust-lang-ja Developers"]
edition = "2018"
description = "A Rust port of AtCoder Library (ACL)."
license = "CC0-1.0"
repository = "https://github.com/rust-lang-ja/ac-library-rs"
keywords = ["competitive"]
categories = ["algorithms", "data-structures"]
publish = false

[package.metadata.docs.rs]
rustdoc-args = ["--html-in-header", "./katex-header.html"]

[dependencies]
15 changes: 15 additions & 0 deletions acl_internal_math/katex-header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-AfEj0r4/OFrOo5t7NnNe46zW/tFgW6x/bCJG8FqQCEo3+Aro6EYUG4+cU+KJWu/X" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-g7c+Jr9ZivxKLnZTDUhnkOnsh30B4H0rpLUpJ4jAIKs4fnJI+sEnkvrMWph2EDg4" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-mll67QQFJfxn0IYznZYonOWZ644AWYC+Pt2cHqMaRhXVrursRwvLnLaebdGIlYNa" crossorigin="anonymous"></script>
<script>
document.addEventListener("DOMContentLoaded", () => {
renderMathInElement(document.body, {
delimiters: [
{left: "$$", right: "$$", display: true},
{left: "\\[", right: "\\]", display: true},
{left: "$", right: "$", display: false},
{left: "\\(", right: "\\)", display: false}
],
})
});
</script>
26 changes: 13 additions & 13 deletions src/internal_math.rs → acl_internal_math/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::mem::swap;
/// # Returns
/// x mod m
/* const */
pub(crate) fn safe_mod(mut x: i64, m: i64) -> i64 {
pub fn safe_mod(mut x: i64, m: i64) -> i64 {
x %= m;
if x < 0 {
x += m;
Expand All @@ -19,9 +19,9 @@ pub(crate) fn safe_mod(mut x: i64, m: i64) -> i64 {
/// Fast modular by barrett reduction
/// Reference: https://en.wikipedia.org/wiki/Barrett_reduction
/// NOTE: reconsider after Ice Lake
pub(crate) struct Barrett {
pub(crate) _m: u32,
pub(crate) im: u64,
pub struct Barrett {
pub _m: u32,
pub im: u64,
}

impl Barrett {
Expand All @@ -30,7 +30,7 @@ impl Barrett {
/// (Note: `m <= 2^31` should also hold, which is undocumented in the original library.
/// See the [pull reqeust commment](https://github.com/rust-lang-ja/ac-library-rs/pull/3#discussion_r484661007)
/// for more details.)
pub(crate) fn new(m: u32) -> Barrett {
pub fn new(m: u32) -> Barrett {
Barrett {
_m: m,
im: (-1i64 as u64 / m as u64).wrapping_add(1),
Expand All @@ -39,7 +39,7 @@ impl Barrett {

/// # Returns
/// `m`
pub(crate) fn umod(&self) -> u32 {
pub fn umod(&self) -> u32 {
self._m
}

Expand All @@ -50,7 +50,7 @@ impl Barrett {
/// # Returns
/// a * b % m
#[allow(clippy::many_single_char_names)]
pub(crate) fn mul(&self, a: u32, b: u32) -> u32 {
pub fn mul(&self, a: u32, b: u32) -> u32 {
mul_mod(a, b, self._m, self.im)
}
}
Expand All @@ -62,7 +62,7 @@ impl Barrett {
/// * `m` `1 <= m <= 2^31`
/// * `im` = ceil(2^64 / `m`)
#[allow(clippy::many_single_char_names)]
pub(crate) fn mul_mod(a: u32, b: u32, m: u32, im: u64) -> u32 {
pub fn mul_mod(a: u32, b: u32, m: u32, im: u64) -> u32 {
// [1] m = 1
// a = b = im = 0, so okay

Expand Down Expand Up @@ -91,7 +91,7 @@ pub(crate) fn mul_mod(a: u32, b: u32, m: u32, im: u64) -> u32 {
/// `(x ** n) % m`
/* const */
#[allow(clippy::many_single_char_names)]
pub(crate) fn pow_mod(x: i64, mut n: i64, m: i32) -> i64 {
pub fn pow_mod(x: i64, mut n: i64, m: i32) -> i64 {
if m == 1 {
return 0;
}
Expand All @@ -115,7 +115,7 @@ pub(crate) fn pow_mod(x: i64, mut n: i64, m: i32) -> i64 {
/// # Parameters
/// * `n` `0 <= n`
/* const */
pub(crate) fn is_prime(n: i32) -> bool {
pub fn is_prime(n: i32) -> bool {
let n = n as i64;
match n {
_ if n <= 1 => return false,
Expand Down Expand Up @@ -151,7 +151,7 @@ pub(crate) fn is_prime(n: i32) -> bool {
/// (g, x) s.t. g = gcd(a, b), xa = g (mod b), 0 <= x < b/g
/* const */
#[allow(clippy::many_single_char_names)]
pub(crate) fn inv_gcd(a: i64, b: i64) -> (i64, i64) {
pub fn inv_gcd(a: i64, b: i64) -> (i64, i64) {
let a = safe_mod(a, b);
if a == 0 {
return (b, 0);
Expand Down Expand Up @@ -191,7 +191,7 @@ pub(crate) fn inv_gcd(a: i64, b: i64) -> (i64, i64) {
/// @param m must be prime
/// @return primitive root (and minimum in now)
/* const */
pub(crate) fn primitive_root(m: i32) -> i32 {
pub fn primitive_root(m: i32) -> i32 {
match m {
2 => return 1,
167_772_161 => return 3,
Expand Down Expand Up @@ -239,7 +239,7 @@ pub(crate) fn primitive_root(m: i32) -> i32 {
mod tests {
#![allow(clippy::unreadable_literal)]
#![allow(clippy::cognitive_complexity)]
use crate::internal_math::{inv_gcd, is_prime, pow_mod, primitive_root, safe_mod, Barrett};
use super::{inv_gcd, is_prime, pow_mod, primitive_root, safe_mod, Barrett};
use std::collections::HashSet;

#[test]
Expand Down
16 changes: 16 additions & 0 deletions acl_internal_queue/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "acl_internal_queue"
version = "0.1.0"
authors = ["rust-lang-ja Developers"]
edition = "2018"
description = "A Rust port of AtCoder Library (ACL)."
license = "CC0-1.0"
repository = "https://github.com/rust-lang-ja/ac-library-rs"
keywords = ["competitive"]
categories = ["algorithms", "data-structures"]
publish = false

[package.metadata.docs.rs]
rustdoc-args = ["--html-in-header", "./katex-header.html"]

[dependencies]
15 changes: 15 additions & 0 deletions acl_internal_queue/katex-header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-AfEj0r4/OFrOo5t7NnNe46zW/tFgW6x/bCJG8FqQCEo3+Aro6EYUG4+cU+KJWu/X" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-g7c+Jr9ZivxKLnZTDUhnkOnsh30B4H0rpLUpJ4jAIKs4fnJI+sEnkvrMWph2EDg4" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-mll67QQFJfxn0IYznZYonOWZ644AWYC+Pt2cHqMaRhXVrursRwvLnLaebdGIlYNa" crossorigin="anonymous"></script>
<script>
document.addEventListener("DOMContentLoaded", () => {
renderMathInElement(document.body, {
delimiters: [
{left: "$$", right: "$$", display: true},
{left: "\\[", right: "\\]", display: true},
{left: "$", right: "$", display: false},
{left: "\\(", right: "\\)", display: false}
],
})
});
</script>
Loading