diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9658366..0c8fcba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -76,6 +76,78 @@ jobs: profile: minimal components: clippy + - name: cargo-clippy (convolution) + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --workspace --all-targets --no-default-features --features convolution -- -D warnings + + - name: cargo-clippy (dsu) + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --workspace --all-targets --no-default-features --features dsu -- -D warnings + + - name: cargo-clippy (fenwicktree) + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --workspace --all-targets --no-default-features --features fenwicktree -- -D warnings + + - name: cargo-clippy (lazysegtree) + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --workspace --all-targets --no-default-features --features lazysegtree -- -D warnings + + - name: cargo-clippy (math) + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --workspace --all-targets --no-default-features --features math -- -D warnings + + - name: cargo-clippy (maxflow) + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --workspace --all-targets --no-default-features --features maxflow -- -D warnings + + - name: cargo-clippy (mincostflow) + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --workspace --all-targets --no-default-features --features mincostflow -- -D warnings + + - name: cargo-clippy (modint) + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --workspace --all-targets --no-default-features --features modint -- -D warnings + + - name: cargo-clippy (scc) + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --workspace --all-targets --no-default-features --features scc -- -D warnings + + - name: cargo-clippy (segtree) + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --workspace --all-targets --no-default-features --features segtree -- -D warnings + + - name: cargo-clippy (string) + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --workspace --all-targets --no-default-features --features string -- -D warnings + + - name: cargo-clippy (twosat) + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --workspace --all-targets --no-default-features --features twosat -- -D warnings + - name: cargo-clippy uses: actions-rs/cargo@v1 with: diff --git a/Cargo.toml b/Cargo.toml index 5348943..351cc50 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,40 @@ keywords = ["competitive"] categories = ["algorithms", "data-structures"] publish = false -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[[example]] +name = "practice2_d_maxflow" +path = "examples/practice2_d_maxflow.rs" +required-features = ["maxflow"] + +[[example]] +name = "practice2_j_segment_tree" +path = "examples/practice2_j_segment_tree.rs" +required-features = ["segtree"] + +[[example]] +name = "practice2_k_range_affine_range_sum" +path = "examples/practice2_k_range_affine_range_sum.rs" +required-features = ["lazysegtree", "modint"] + +[[example]] +name = "practice2_l_lazy_segment_tree" +path = "examples/practice2_l_lazy_segment_tree.rs" +required-features = ["lazysegtree"] + +[features] +default = ["convolution", "dsu", "fenwicktree", "lazysegtree", "math", "maxflow", "mincostflow", "modint", "scc", "segtree", "string", "twosat"] +convolution = ["modint"] +dsu = [] +fenwicktree = [] +lazysegtree = ["segtree"] +math = [] +maxflow = [] +mincostflow = [] +modint = [] +scc = [] +segtree = [] +string = [] +twosat = [] [dependencies] diff --git a/src/convolution.rs b/src/convolution.rs index 9576e3e..d084e3a 100644 --- a/src/convolution.rs +++ b/src/convolution.rs @@ -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>>> { + fn butterfly_cache() -> &'static ::std::thread::LocalKey<::std::cell::RefCell<::std::option::Option>>> { thread_local! { - static BUTTERFLY_CACHE: ::std::cell::RefCell<::std::option::Option>> = ::std::default::Default::default(); + static BUTTERFLY_CACHE: ::std::cell::RefCell<::std::option::Option>> = ::std::default::Default::default(); } &BUTTERFLY_CACHE } @@ -19,9 +19,9 @@ macro_rules! modulus { }; } -use crate::{ +use super::{ internal_bit, internal_math, - modint::{ButterflyCache, Modulus, RemEuclidU32, StaticModInt}, + modint::{self, ButterflyCache, Modulus, RemEuclidU32, StaticModInt}, }; use std::{ cmp, @@ -232,10 +232,7 @@ fn prepare() -> ButterflyCache { #[cfg(test)] mod tests { - use crate::{ - modint::{Mod998244353, Modulus, StaticModInt}, - RemEuclidU32, - }; + use super::super::modint::{self, Mod998244353, Modulus, RemEuclidU32, StaticModInt}; use rand::{rngs::ThreadRng, Rng as _}; use std::{ convert::{TryFrom, TryInto as _}, diff --git a/src/internal_math.rs b/src/internal_math.rs index 515191c..ce1aaa8 100644 --- a/src/internal_math.rs +++ b/src/internal_math.rs @@ -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] diff --git a/src/internal_queue.rs b/src/internal_queue.rs index 5e51e9a..5266591 100644 --- a/src/internal_queue.rs +++ b/src/internal_queue.rs @@ -51,7 +51,7 @@ impl SimpleQueue { #[cfg(test)] mod test { - use crate::internal_queue::SimpleQueue; + use super::SimpleQueue; #[allow(clippy::cognitive_complexity)] #[test] diff --git a/src/internal_scc.rs b/src/internal_scc.rs index dbdbdc4..85a0a72 100644 --- a/src/internal_scc.rs +++ b/src/internal_scc.rs @@ -45,6 +45,7 @@ impl SccGraph { SccGraph { n, edges: vec![] } } + #[allow(dead_code)] pub fn num_vertices(&self) -> usize { self.n } @@ -115,6 +116,7 @@ impl SccGraph { (env.group_num, env.ids) } + #[allow(dead_code)] pub fn scc(&self) -> Vec> { let ids = self.scc_ids(); let group_num = ids.0; diff --git a/src/lazysegtree.rs b/src/lazysegtree.rs index 47020a8..959fabf 100644 --- a/src/lazysegtree.rs +++ b/src/lazysegtree.rs @@ -1,5 +1,5 @@ -use crate::internal_bit::ceil_pow2; -use crate::Monoid; +use super::internal_bit::ceil_pow2; +use super::segtree::Monoid; pub trait MapMonoid { type M: Monoid; @@ -314,7 +314,8 @@ where #[cfg(test)] mod tests { - use crate::{LazySegtree, MapMonoid, Max}; + use super::super::segtree::Max; + use super::{LazySegtree, MapMonoid}; struct MaxAdd; impl MapMonoid for MaxAdd { diff --git a/src/lib.rs b/src/lib.rs index 5452b25..d3ef82c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,37 +1,66 @@ +#[cfg(feature = "convolution")] pub mod convolution; +#[cfg(feature = "dsu")] pub mod dsu; +#[cfg(feature = "fenwicktree")] pub mod fenwicktree; +#[cfg(feature = "lazysegtree")] pub mod lazysegtree; +#[cfg(feature = "math")] pub mod math; +#[cfg(feature = "maxflow")] pub mod maxflow; +#[cfg(feature = "mincostflow")] pub mod mincostflow; +#[cfg(feature = "modint")] pub mod modint; +#[cfg(feature = "scc")] pub mod scc; +#[cfg(feature = "segtree")] pub mod segtree; +#[cfg(feature = "string")] pub mod string; +#[cfg(feature = "twosat")] pub mod twosat; +#[cfg(any(feature = "convolution", feature = "lazysegtree", feature = "segtree"))] pub(crate) mod internal_bit; +#[cfg(any(feature = "math", feature = "modint"))] pub(crate) mod internal_math; +#[cfg(feature = "maxflow")] pub(crate) mod internal_queue; +#[cfg(any(feature = "scc", feature = "twosat"))] pub(crate) mod internal_scc; +#[cfg(any(feature = "maxflow", feature = "mincostflow", feature = "segtree"))] pub(crate) mod internal_type_traits; +#[cfg(feature = "convolution")] pub use convolution::{convolution, convolution_i64}; +#[cfg(feature = "dsu")] pub use dsu::Dsu; +#[cfg(feature = "fenwicktree")] pub use fenwicktree::FenwickTree; +#[cfg(feature = "lazysegtree")] pub use lazysegtree::{LazySegtree, MapMonoid}; +#[cfg(feature = "math")] pub use math::{crt, floor_sum, inv_mod, pow_mod}; +#[cfg(feature = "maxflow")] pub use maxflow::{Edge, MfGraph}; +#[cfg(feature = "mincostflow")] pub use mincostflow::MinCostFlowGraph; +#[cfg(feature = "modint")] pub use modint::{ Barrett, ButterflyCache, DefaultId, DynamicModInt, Id, Mod1000000007, Mod998244353, ModInt, ModInt1000000007, ModInt998244353, Modulus, RemEuclidU32, StaticModInt, }; +#[cfg(feature = "scc")] pub use scc::SccGraph; +#[cfg(feature = "segtree")] pub use segtree::{Additive, Max, Min, Monoid, Multiplicative, Segtree}; +#[cfg(feature = "string")] pub use string::{ lcp_array, lcp_array_arbitrary, suffix_array, suffix_array_arbitrary, suffix_array_manual, z_algorithm, z_algorithm_arbitrary, }; +#[cfg(feature = "twosat")] pub use twosat::TwoSat; diff --git a/src/math.rs b/src/math.rs index 61f15d5..f29a819 100644 --- a/src/math.rs +++ b/src/math.rs @@ -1,6 +1,6 @@ //! Number-theoretic algorithms. -use crate::internal_math; +use super::internal_math; use std::mem::swap; diff --git a/src/maxflow.rs b/src/maxflow.rs index 93b337c..6f884c4 100644 --- a/src/maxflow.rs +++ b/src/maxflow.rs @@ -1,6 +1,6 @@ #![allow(dead_code)] -use crate::internal_queue::SimpleQueue; -use crate::internal_type_traits::Integral; +use super::internal_queue::SimpleQueue; +use super::internal_type_traits::Integral; use std::cmp::min; use std::iter; @@ -224,7 +224,7 @@ struct _Edge { #[cfg(test)] mod test { - use crate::{Edge, MfGraph}; + use super::{Edge, MfGraph}; #[test] fn test_max_flow_wikipedia() { diff --git a/src/mincostflow.rs b/src/mincostflow.rs index 158a9e8..aafc45e 100644 --- a/src/mincostflow.rs +++ b/src/mincostflow.rs @@ -1,4 +1,4 @@ -use crate::internal_type_traits::Integral; +use super::internal_type_traits::Integral; pub struct MinCostFlowEdge { pub from: usize, diff --git a/src/modint.rs b/src/modint.rs index 8aa5220..c47dfef 100644 --- a/src/modint.rs +++ b/src/modint.rs @@ -48,7 +48,7 @@ //! [`ModInt998244353`]: ./type.ModInt998244353.html //! [`ModInt`]: ./type.ModInt.html -use crate::internal_math; +use super::internal_math; use std::{ cell::RefCell, convert::{Infallible, TryInto as _}, @@ -283,7 +283,9 @@ impl Modulus for Mod998244353 { /// Cache for butterfly operations. pub struct ButterflyCache { + #[allow(dead_code)] pub(crate) sum_e: Vec>, + #[allow(dead_code)] pub(crate) sum_ie: Vec>, } @@ -1050,7 +1052,7 @@ impl_folding! { #[cfg(test)] mod tests { - use crate::modint::ModInt1000000007; + use super::ModInt1000000007; #[test] fn static_modint_new() { diff --git a/src/scc.rs b/src/scc.rs index 2eff835..d33c15b 100644 --- a/src/scc.rs +++ b/src/scc.rs @@ -1,4 +1,4 @@ -use crate::internal_scc; +use super::internal_scc; pub struct SccGraph { internal: internal_scc::SccGraph, diff --git a/src/segtree.rs b/src/segtree.rs index b543aa3..9d6b820 100644 --- a/src/segtree.rs +++ b/src/segtree.rs @@ -1,5 +1,5 @@ -use crate::internal_bit::ceil_pow2; -use crate::internal_type_traits::{BoundedAbove, BoundedBelow, One, Zero}; +use super::internal_bit::ceil_pow2; +use super::internal_type_traits::{BoundedAbove, BoundedBelow, One, Zero}; use std::cmp::{max, min}; use std::convert::Infallible; use std::marker::PhantomData; @@ -238,8 +238,8 @@ where #[cfg(test)] mod tests { - use crate::segtree::Max; - use crate::Segtree; + use super::super::Segtree; + use super::Max; #[test] fn test_max_segtree() { diff --git a/src/twosat.rs b/src/twosat.rs index ac5f8b6..213d486 100644 --- a/src/twosat.rs +++ b/src/twosat.rs @@ -1,4 +1,4 @@ -use crate::internal_scc; +use super::internal_scc; pub struct TwoSat { n: usize,