Skip to content

Commit

Permalink
refactor: simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiphereth-A committed May 4, 2024
1 parent 1bd5ad7 commit 756c9f8
Show file tree
Hide file tree
Showing 1,761 changed files with 4,950 additions and 9,456 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ ForEachMacros:
- FOR1_
- FOR2_
- dlxfor_
- fle_
- flt_
IndentRequiresClause: false
SortIncludes: CaseSensitive
SpacesBeforeTrailingComments: 2
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ jobs:
runs-on: ubuntu-latest
needs: [setup]
env:
SPLIT_SIZE: 20
SPLIT_SIZE: 18
strategy:
matrix:
# prettier-ignore
index:
["00", "01", "02", "03", "04", "05", "06", "07", "08", "09",
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19"]
["00", "01", "02", "03", "04", "05", "06", "07", "08",
"09", "10", "11", "12", "13", "14", "15", "16", "17"]
steps:
- uses: actions/checkout@v4
with:
Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# CP-lib

![GitHub](https://img.shields.io/github/license/Tiphereth-A/CP-lib)
[![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/Tiphereth-A/CP-lib/verify.yml?logo=github)](https://github.com/Tiphereth-A/CP-lib/actions)
[![GitHub deployments](https://img.shields.io/github/deployments/Tiphereth-A/CP-lib/github-pages?label=pages+state&logo=github)](https://cplib.tifa-233.com/)
![Code Size](https://img.shields.io/github/languages/code-size/Tiphereth-A/CP-lib)
![Standard](https://img.shields.io/static/v1?label=standard&message=C%2B%2B20+with+O2&color=green&logo=cplusplus)
![Requirments](https://img.shields.io/static/v1?label=requirments&message=GCC+>=12&color=blue&logo=cplusplus)

[![verify](https://github.com/Tiphereth-A/CP-lib/actions/workflows/verify.yml/badge.svg)](https://github.com/Tiphereth-A/CP-lib/actions/workflows/verify.yml)
[![Build & Relase LaTeX document](https://github.com/Tiphereth-A/CP-lib/actions/workflows/release.yml/badge.svg)](https://github.com/Tiphereth-A/CP-lib/actions/workflows/release.yml)
[![CodeQL](https://github.com/Tiphereth-A/CP-lib/actions/workflows/codeql.yml/badge.svg)](https://github.com/Tiphereth-A/CP-lib/actions/workflows/codeql.yml)
[![flawfinder](https://github.com/Tiphereth-A/CP-lib/actions/workflows/flawfinder.yml/badge.svg)](https://github.com/Tiphereth-A/CP-lib/actions/workflows/flawfinder.yml)
[![GitHub deployments](https://img.shields.io/github/deployments/Tiphereth-A/CP-lib/github-pages?label=pages+state&logo=github)](https://cplib.tifa-233.com/)
[![GitHub Workflow Status (with event) - verify](https://img.shields.io/github/actions/workflow/status/Tiphereth-A/CP-lib/verify.yml?label=verify&logo=github)](https://github.com/Tiphereth-A/CP-lib/actions)
[![GitHub Workflow Status (with event) - release](https://img.shields.io/github/actions/workflow/status/Tiphereth-A/CP-lib/release.yml?label=release&logo=github)](https://github.com/Tiphereth-A/CP-lib/actions)
[![GitHub Workflow Status (with event) - codeql](https://img.shields.io/github/actions/workflow/status/Tiphereth-A/CP-lib/codeql.yml?label=codeql&logo=github)](https://github.com/Tiphereth-A/CP-lib/actions)
[![GitHub Workflow Status (with event) - flawfinder](https://img.shields.io/github/actions/workflow/status/Tiphereth-A/CP-lib/flawfinder.yml?label=flawfinder&logo=github)](https://github.com/Tiphereth-A/CP-lib/actions)

My code library for Competitive Programming, powered by [competitive-verifier/competitive-verifier](https://github.com/competitive-verifier/competitive-verifier) & [Tiphereth-A/TINplate](https://github.com/Tiphereth-A/TINplate).
37 changes: 5 additions & 32 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ notebook:
- util: 共同依赖
code_ext: hpp
test_ext: cpp
- fp_const: 一些浮点常数
code_ext: hpp
test_ext: cpp
- fp_comp: 浮点数比较
code_ext: hpp
test_ext: cpp
Expand Down Expand Up @@ -158,7 +155,7 @@ notebook:
- segtree: 线段树
code_ext: hpp
test_ext: cpp
- segtree_old: 旧版线段树
- segtree_ctor: 常用线段树构造
code_ext: hpp
test_ext: cpp
- lichao_segtree: 李超线段树(线段添加,定点最值)
Expand Down Expand Up @@ -759,9 +756,6 @@ notebook:
- prime_seq: 素数序列
code_ext: hpp
test_ext: cpp
- atkin: Atkin 筛法
code_ext: hpp
test_ext: cpp
- lsieve: 线性筛
code_ext: hpp
test_ext: cpp
Expand All @@ -780,10 +774,7 @@ notebook:
- is_proot_nimber: 是否为原根(Nimber)
code_ext: hpp
test_ext: cpp
- proot_u32: 原根(32 位)
code_ext: hpp
test_ext: cpp
- proot_u64: 原根(64 位)
- proot: 原根
code_ext: hpp
test_ext: cpp
- proot_gint: 原根(Gauss 整数)
Expand Down Expand Up @@ -898,10 +889,10 @@ notebook:
- kahan: Kahan 求和
code_ext: hpp
test_ext: cpp
- basis_r: 实数线性基
- basis_z2: 异或线性基
code_ext: hpp
test_ext: cpp
- basis_z2: 异或线性基
- basis_r: 实数线性基
code_ext: hpp
test_ext: cpp
- mex: mex
Expand Down Expand Up @@ -1044,24 +1035,15 @@ notebook:
code_ext: hpp
test_ext: cpp
conv:
- dft_traits: DFT traits
code_ext: hpp
test_ext: cpp
- fft: 快速 Fourier 变换
code_ext: hpp
test_ext: cpp
- ntt: 数论变换
code_ext: hpp
test_ext: cpp
- ntt32: 数论变换(u32)
code_ext: hpp
test_ext: cpp
- ntt_doubling: NTT doubling
code_ext: hpp
test_ext: cpp
- cntt: 扩域 NTT
code_ext: hpp
test_ext: cpp
- conv_naive: 卷积(暴力)
code_ext: hpp
test_ext: cpp
Expand All @@ -1080,9 +1062,6 @@ notebook:
- conv_u128: 卷积(三模 NTT,高精度整数用)
code_ext: hpp
test_ext: cpp
- conv_cntt: 卷积(扩域 NTT)
code_ext: hpp
test_ext: cpp
- conv_czt: 卷积(Chirp-Z 变换)
code_ext: hpp
test_ext: cpp
Expand Down Expand Up @@ -1135,18 +1114,12 @@ notebook:
- polymtt: 多项式(基于 MTT)
code_ext: hpp
test_ext: cpp
- poly3ntt: 多项式(基于三模 MTT)
- poly3ntt: 多项式(基于三模 NTT)
code_ext: hpp
test_ext: cpp
- polyntt: 多项式(基于 NTT)
code_ext: hpp
test_ext: cpp
- polyntt32: 多项式(基于 NTT 32)
code_ext: hpp
test_ext: cpp
- polycntt: 多项式(基于 CNTT)
code_ext: hpp
test_ext: cpp
- shl_fps: 多项式左移
code_ext: hpp
test_ext: cpp
Expand Down
8 changes: 0 additions & 8 deletions notebook.bib
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,6 @@ @misc{tspvlsidatasets
howpublished = {\url{https://www.math.uwaterloo.ca/tsp/vlsi/}}
}

@misc{enwiki:1048307934,
author = {{Wikipedia contributors}},
title = {Sieve of Atkin --- {Wikipedia}{,} The Free Encyclopedia},
year = {2021},
url = {https://en.wikipedia.org/w/index.php?title=Sieve_of_Atkin&oldid=1048307934},
note = {[Online; accessed 29-November-2023]}
}

@misc{enwiki:1188156145,
author = {{Wikipedia contributors}},
title = {Alpha--beta pruning --- {Wikipedia}{,} The Free Encyclopedia},
Expand Down
14 changes: 8 additions & 6 deletions src/code/bit/bswap.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#ifndef TIFALIBS_BIT_BSWAP
#define TIFALIBS_BIT_BSWAP

#include "../util/util.hpp"

namespace tifa_libs::bit {

// From GCC lib
template <class T>
constexpr T bswap(T x) {
if constexpr (sizeof(T) == 2) return __builtin_bswap16(x);
if constexpr (sizeof(T) == 4) return __builtin_bswap32(x);
if constexpr (sizeof(T) == 8) return __builtin_bswap64(x);
if constexpr (sizeof(T) == 16) return __builtin_bswap128(x);
// if constexpr (sizeof(T) == 16) return (__builtin_bswap64(x >> 64) | (static_cast<T>(__builtin_bswap64(x)) << 64));
CEXP T bswap(T x) {
if CEXP (sizeof(T) == 2) return __builtin_bswap16(x);
if CEXP (sizeof(T) == 4) return __builtin_bswap32(x);
if CEXP (sizeof(T) == 8) return __builtin_bswap64(x);
if CEXP (sizeof(T) == 16) return __builtin_bswap128(x);
// if CEXP (sizeof(T) == 16) return (__builtin_bswap64(x >> 64) | (static_cast<T>(__builtin_bswap64(x)) << 64));
}

} // namespace tifa_libs::bit
Expand Down
12 changes: 7 additions & 5 deletions src/code/bit/cntlsb.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#ifndef TIFALIBS_BIT_CNTLSB
#define TIFALIBS_BIT_CNTLSB

#include "../util/util.hpp"

namespace tifa_libs::bit {

template <class T>
constexpr int cntlsb(T x) {
constexpr int nd = sizeof(T) * 8;
CEXP int cntlsb(T x) {
CEXP int nd = sizeof(T) * 8;
static_assert(nd <= 64);
if constexpr (nd <= sizeof(unsigned) * 8) return __builtin_clrsb(x);
else if constexpr (nd <= sizeof(unsigned long) * 8) return __builtin_clrsbl(x);
else return __builtin_clrsbll(x);
if CEXP (nd <= sizeof(unsigned) * 8) return __builtin_clrsb(x);
else if CEXP (nd <= sizeof(unsigned long) * 8) return __builtin_clrsbl(x);
return __builtin_clrsbll(x);
}

} // namespace tifa_libs::bit
Expand Down
14 changes: 8 additions & 6 deletions src/code/bit/ffs.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#ifndef TIFALIBS_BIT_FFS
#define TIFALIBS_BIT_FFS

#include "../util/util.hpp"

namespace tifa_libs::bit {

template <class T>
constexpr int ffs(T x) {
constexpr int nd = sizeof(T) * 8;
CEXP int ffs(T x) {
CEXP int nd = sizeof(T) * 8;
static_assert(nd <= 128);
constexpr int nd_ull = sizeof(long long) * 8;
if constexpr (nd <= sizeof(int) * 8) return __builtin_ffs(x);
else if constexpr (nd <= sizeof(long) * 8) return __builtin_ffsl(x);
else if constexpr (nd <= nd_ull) return __builtin_ffsll(x);
CEXP int nd_ull = sizeof(long long) * 8;
if CEXP (nd <= sizeof(int) * 8) return __builtin_ffs(x);
else if CEXP (nd <= sizeof(long) * 8) return __builtin_ffsl(x);
else if CEXP (nd <= nd_ull) return __builtin_ffsll(x);
else {
if (!x) return 0;
long long lo = x & (long long)(-1);
Expand Down
2 changes: 1 addition & 1 deletion src/code/bit/lowbit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace tifa_libs::bit {

template <class T>
constexpr T lowbit(T x) { return T(1) << std::countr_zero(x); }
CEXP T lowbit(T x) { return T(1) << std::countr_zero(x); }

} // namespace tifa_libs::bit

Expand Down
14 changes: 8 additions & 6 deletions src/code/bit/parity.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#ifndef TIFALIBS_BIT_PARITY
#define TIFALIBS_BIT_PARITY

#include "../util/util.hpp"

namespace tifa_libs::bit {

template <class T>
constexpr int parity(T x) {
constexpr int nd = sizeof(T) * 8;
CEXP int parity(T x) {
CEXP int nd = sizeof(T) * 8;
static_assert(nd <= 128);
constexpr int nd_ull = sizeof(unsigned long long) * 8;
if constexpr (nd <= sizeof(unsigned) * 8) return __builtin_parity(x);
else if constexpr (nd <= sizeof(unsigned long) * 8) return __builtin_parityl(x);
else if constexpr (nd <= nd_ull) return __builtin_parityll(x);
CEXP int nd_ull = sizeof(unsigned long long) * 8;
if CEXP (nd <= sizeof(unsigned) * 8) return __builtin_parity(x);
else if CEXP (nd <= sizeof(unsigned long) * 8) return __builtin_parityl(x);
else if CEXP (nd <= nd_ull) return __builtin_parityll(x);
else {
unsigned long long lo = x & (unsigned long long)(-1), hi = x >> nd_ull;
return __builtin_parityll(hi) ^ __builtin_parityll(lo);
Expand Down
2 changes: 1 addition & 1 deletion src/code/comb/ball_box_dda.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace tifa_libs::math {

template <class mint>
constexpr mint ball_box_dda(u32 ball, u32 box) { return qpow<mint>(box, ball); }
CEXP mint ball_box_dda(u32 ball, u32 box) { return qpow<mint>(box, ball); }

} // namespace tifa_libs::math

Expand Down
6 changes: 3 additions & 3 deletions src/code/comb/ball_box_ddl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
namespace tifa_libs::math {

template <class mint>
constexpr mint ball_box_ddl(u32, u32 box, vecu64 const& pows, Binom<mint> const& binom) {
CEXP mint ball_box_ddl(u32, u32 box, vecu64 CR pows, Binom<mint> CR binom) {
mint ans = 0;
bool f = box & 1;
for (u32 i = 1; i <= box; ++i) {
fle_ (u32, i, 1, box) {
f ? (ans += binom.mCn(box, i) * pows[i]) : (ans -= binom.mCn(box, i) * pows[i]);
f ^= 1;
}
return ans;
}
template <class mint>
constexpr mint ball_box_ddl(u32 ball, u32 box, Binom<mint> const& binom) { return ball_box_ddl<mint>(ball, box, gen_pows(box + 1, ball, mint::mod()), binom); }
CEXP mint ball_box_ddl(u32 ball, u32 box, Binom<mint> CR binom) { return ball_box_ddl<mint>(ball, box, gen_pows(box + 1, ball, mint::mod()), binom); }

} // namespace tifa_libs::math

Expand Down
2 changes: 1 addition & 1 deletion src/code/comb/ball_box_ddm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace tifa_libs::math {

template <class mint>
constexpr mint ball_box_ddm(u32 ball, u32 box, Binom<mint> const& binom) { return binom.mPn(box, ball); }
CEXP mint ball_box_ddm(u32 ball, u32 box, Binom<mint> CR binom) { return binom.mPn(box, ball); }

} // namespace tifa_libs::math

Expand Down
4 changes: 2 additions & 2 deletions src/code/comb/ball_box_dia.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
namespace tifa_libs::math {

template <class poly>
constexpr auto ball_box_dia(u32 ball, u32 box, poly const& s2r) { return std::reduce(s2r.data().begin(), s2r.data().begin() + (std::min(ball, box) + 1), typename poly::value_type{}); }
CEXP auto ball_box_dia(u32 ball, u32 box, cT_(poly) s2r) { return std::reduce(s2r.data().begin(), s2r.data().begin() + (min(ball, box) + 1), typename poly::value_type{}); }
template <class poly>
constexpr auto ball_box_dia(u32 ball, u32 box) { return ball_box_dia<poly>(ball, box, gen_stirling2_row<poly>(ball)); }
CEXP auto ball_box_dia(u32 ball, u32 box) { return ball_box_dia<poly>(ball, box, gen_stirling2_row<poly>(ball)); }

} // namespace tifa_libs::math

Expand Down
4 changes: 2 additions & 2 deletions src/code/comb/ball_box_dil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
namespace tifa_libs::math {

template <class poly>
constexpr auto ball_box_dil(u32 ball, u32 box, poly const& s2r) { return box > ball ? 0 : s2r[box]; }
CEXP auto ball_box_dil(u32 ball, u32 box, cT_(poly) s2r) { return box > ball ? 0 : s2r[box]; }
template <class poly>
constexpr auto ball_box_dil(u32 ball, u32 box) { return ball_box_dil<poly>(ball, box, gen_stirling2_row<poly>(ball)); }
CEXP auto ball_box_dil(u32 ball, u32 box) { return ball_box_dil<poly>(ball, box, gen_stirling2_row<poly>(ball)); }

} // namespace tifa_libs::math

Expand Down
2 changes: 1 addition & 1 deletion src/code/comb/ball_box_dim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace tifa_libs::math {

template <class mint>
constexpr mint ball_box_dim(u32 ball, u32 box) { return box >= ball; }
CEXP mint ball_box_dim(u32 ball, u32 box) { return box >= ball; }

} // namespace tifa_libs::math

Expand Down
2 changes: 1 addition & 1 deletion src/code/comb/ball_box_ida.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace tifa_libs::math {

template <class mint>
constexpr mint ball_box_ida(u32 ball, u32 box, Binom<mint> const& binom) { return binom.mCn(box + ball - 1, box - 1); }
CEXP mint ball_box_ida(u32 ball, u32 box, Binom<mint> CR binom) { return binom.mCn(box + ball - 1, box - 1); }

} // namespace tifa_libs::math

Expand Down
2 changes: 1 addition & 1 deletion src/code/comb/ball_box_idl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace tifa_libs::math {

template <class mint>
constexpr mint ball_box_idl(u32 ball, u32 box, Binom<mint> const& binom) { return binom.mCn(ball - 1, box - 1); }
CEXP mint ball_box_idl(u32 ball, u32 box, Binom<mint> CR binom) { return binom.mCn(ball - 1, box - 1); }

} // namespace tifa_libs::math

Expand Down
2 changes: 1 addition & 1 deletion src/code/comb/ball_box_idm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace tifa_libs::math {

template <class mint>
constexpr mint ball_box_idm(u32 ball, u32 box, Binom<mint> const& binom) { return binom.mCn(box, ball); }
CEXP mint ball_box_idm(u32 ball, u32 box, Binom<mint> CR binom) { return binom.mCn(box, ball); }

} // namespace tifa_libs::math

Expand Down
4 changes: 2 additions & 2 deletions src/code/comb/ball_box_iia.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
namespace tifa_libs::math {

template <class poly>
constexpr auto ball_box_iia(u32 ball, u32, poly const& bbiif) { return bbiif[ball]; }
CEXP auto ball_box_iia(u32 ball, u32, cT_(poly) bbiif) { return bbiif[ball]; }
template <class poly>
constexpr auto ball_box_iia(u32 ball, u32 box) { return ball_box_iia<poly>(ball, box, gen_ball_box_ii<poly>(box, ball)); }
CEXP auto ball_box_iia(u32 ball, u32 box) { return ball_box_iia<poly>(ball, box, gen_ball_box_ii<poly>(box, ball)); }

} // namespace tifa_libs::math

Expand Down
Loading

0 comments on commit 756c9f8

Please sign in to comment.