Skip to content

Commit

Permalink
style: rename
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiphereth-A committed Feb 8, 2024
1 parent 84f5e46 commit 1abd2d8
Show file tree
Hide file tree
Showing 62 changed files with 113 additions and 113 deletions.
2 changes: 1 addition & 1 deletion src/code/fast/str2uint_mod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace tifa_libs {

constexpr u64 str2uint_mod(std::string_view s, u64 mod) {
constexpr u64 str2uint_mod(strnv s, u64 mod) {
u32 n = (u32)s.size();
if (!n) return 0;
u64 ans = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/code/game/texas_holdem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class th_card {
static constexpr char SUITS[5] = "CDHS";
explicit constexpr th_card() {}
constexpr th_card(char rank, char suit) { encode(rank, suit); }
explicit constexpr th_card(std::string_view str) : th_card(str[0], str[1]) { assert(str.size() == 2); }
explicit constexpr th_card(strnv str) : th_card(str[0], str[1]) { assert(str.size() == 2); }
// Parses a card in a format as "2C"
// @return: 4 * (rank - 2) + suit (2 <= rank <= 14)
constexpr void encode(char rank, char suit) {
Expand Down
12 changes: 6 additions & 6 deletions src/code/math/mpi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class mpi {
if (x < 0) neg = true, x = -x;
while (x) dt.push_back(u32(to_uint_t<T>(x) % D)), x /= D;
}
constexpr mpi(std::string s) : neg(false) {
constexpr mpi(strn s) : neg(false) {
assert(!s.empty());
if (s.size() == 1u) {
if (s[0] == '0') return;
Expand Down Expand Up @@ -93,9 +93,9 @@ class mpi {
constexpr u32 size() const { return (u32)dt.size(); }
constexpr void shrink() { shrink_(dt); }

constexpr std::string to_str() const {
constexpr strn to_str() const {
if (is_zero()) return "0";
std::string res;
strn res;
if (neg) res.push_back('-');
for (u32 i = size() - 1; ~i; --i) res += itos_((u32)dt[i], i != size() - 1);
return res;
Expand All @@ -111,7 +111,7 @@ class mpi {
}

friend std::istream& operator>>(std::istream& is, mpi& m) {
std::string s;
strn s;
is >> s;
m = mpi{s};
return is;
Expand Down Expand Up @@ -301,9 +301,9 @@ class mpi {
return {q, q2};
}

static constexpr std::string itos_(u32 x, bool zero_padding) {
static constexpr strn itos_(u32 x, bool zero_padding) {
assert(x < D);
std::string res;
strn res;
for (u32 i = 0; i < lgD; ++i) res.push_back(char(48 + x % 10)), x /= 10;
if (!zero_padding) {
while (res.size() && res.back() == '0') res.pop_back();
Expand Down
4 changes: 2 additions & 2 deletions src/code/str/aho_corasick_automaton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class aho_corasick_automaton {

explicit constexpr aho_corasick_automaton() : t(1), sz(1) {}

constexpr void insert(std::string_view s, u32 id = -1u) {
constexpr void insert(strnv s, u32 id = -1u) {
u32 u = 0;
++t[u].tot;
for (auto c : s) {
Expand All @@ -43,7 +43,7 @@ class aho_corasick_automaton {
}
}
}
constexpr void build(vec<std::string> const& s_) {
constexpr void build(vec<strn> const& s_) {
for (u32 i = 0; i < s_.size(); ++i) insert(s_[i], i);
getfail();
}
Expand Down
2 changes: 1 addition & 1 deletion src/code/str/hash_substr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class hash_substr {
public:
explicit constexpr hash_substr() {}

constexpr void set(std::string_view s) {
constexpr void set(strnv s) {
hash.resize(1, 0), hash.reserve(s.size() + 1);
for (char c : s) hash.push_back(hash.back() * base + (u32)c + 1);
if (p.size() <= s.size()) {
Expand Down
2 changes: 1 addition & 1 deletion src/code/str/hash_substr2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class hash_substr2 {
public:
explicit constexpr hash_substr2() {}

constexpr void set(std::string_view s) { h0.set(s), h1.set(s); }
constexpr void set(strnv s) { h0.set(s), h1.set(s); }
constexpr u32 size() const { return h0.size(); }
constexpr std::pair<mint0, mint1> get(u32 pos, u32 len = -1_u32) const { return {h0.get(pos, len), h1.get(pos, len)}; }
};
Expand Down
4 changes: 2 additions & 2 deletions src/code/str/kmp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace tifa_libs::str {

// @return nxt of pattern
inline vec<i32> kmp_nxt(std::string_view pattern) {
inline vec<i32> kmp_nxt(strnv pattern) {
i32 n = (i32)pattern.size();
vec<i32> nxt((u32)n);
i32 i, j;
Expand All @@ -21,7 +21,7 @@ inline vec<i32> kmp_nxt(std::string_view pattern) {

// find pattern in text
// @return matched position in s
inline vec<u32> kmp(std::string_view pattern, std::string_view text) {
inline vec<u32> kmp(strnv pattern, strnv text) {
vec<i32> nxt = kmp_nxt(pattern);
vec<u32> ret;
i32 n = (i32)pattern.size(), m = (i32)text.size();
Expand Down
2 changes: 1 addition & 1 deletion src/code/str/lyndon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace tifa_libs::str {

constexpr vec<u32> duval(std::string_view s) {
constexpr vec<u32> duval(strnv s) {
const u32 n = (u32)s.size();
vec<u32> res{0};
while (res.back() != n) {
Expand Down
4 changes: 2 additions & 2 deletions src/code/str/manacher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

namespace tifa_libs::str {

constexpr vec<u32> manacher(std::string_view t) {
std::string s{'\001', '\002'};
constexpr vec<u32> manacher(strnv t) {
strn s{'\001', '\002'};
for (char c : t) (s += c) += '\002';
s += '\003';
vec<u32> p(s.size());
Expand Down
2 changes: 1 addition & 1 deletion src/code/str/orthodox_ex_suffix_automaton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class orthodox_ex_suffix_automaton {
}
return cur;
}
constexpr void insert(std::string_view s) {
constexpr void insert(strnv s) {
u32 u = 0;
for (auto cc : s) {
u32 c = cc - BASE;
Expand Down
2 changes: 1 addition & 1 deletion src/code/str/suffix_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "../util/util.hpp"

namespace tifa_libs::str {
template <typename T = std::string>
template <typename T = strn>
class suffixarray {
T s;

Expand Down
4 changes: 2 additions & 2 deletions src/code/str/suffix_automaton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class suffix_automaton {

// app 0
//! default: each character of t is lowercase English letters.
constexpr std::pair<u32, bool> search(std::string t) {
constexpr std::pair<u32, bool> search(strn t) {
u32 u = 0, i = 0, base = u32('a');
while (i < t.size()) {
if (!st[u].nex[u32(t[i]) - base]) return {i, false};
Expand Down Expand Up @@ -90,7 +90,7 @@ class suffix_automaton {
}
// app 4
//! default: each character of t is lowercase English letters.
constexpr ptt<u32> lcs(std::string_view t) {
constexpr ptt<u32> lcs(strnv t) {
u32 v = 0, len = 0, ret = 0, end = 0, base = u32('a');
for (u32 i = 0; i < t.size(); ++i) {
while (v && !st[v].nex[u32(t[i]) - base]) v = st[v].link, len = st[v].len;
Expand Down
2 changes: 1 addition & 1 deletion src/code/str/z_func.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace tifa_libs::str {

constexpr vec<u32> z_func(std::string_view s) {
constexpr vec<u32> z_func(strnv s) {
u32 n = (u32)s.size();
vec<u32> z(n);
for (u32 i = 1, l = 0, r = 0; i < n; ++i) {
Expand Down
6 changes: 3 additions & 3 deletions src/code/util/base64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ class Base64 {
// clang-format on

public:
static constexpr std::string encode(vec<usz> const &a) {
static constexpr strn encode(vec<usz> const &a) {
usz x = *std::max_element(a.begin(), a.end()), y = *std::min_element(a.begin(), a.end());
usz N = a.size(), B = std::max(usz(6), (sizeof(usz) * 8 - (usz)(y < 0 ? 0 : std::countl_zero(x))));
std::string S((B * N + 11) / 6, 0);
strn S((B * N + 11) / 6, 0);
S[0] = (char)B;
for (usz i = 0; i < N; ++i)
for (usz j = 0; j < B; ++j)
if ((a[i] >> j) & 1) S[(i * B + j) / 6 + 1] |= 1 << ((i * B + j) % 6);
for (auto &c : S) c = base[(usz)c];
return S;
}
static constexpr vec<usz> decode(std::string S) {
static constexpr vec<usz> decode(strn S) {
for (auto &c : S) c = ibase(c);
usz B = (usz)S[0], M = (usz)S.size() - 1;
vec<usz> a(6 * M / B, 0);
Expand Down
6 changes: 3 additions & 3 deletions src/code/util/fastio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class fastin {
*n_ = '\0';
return *this;
}
fastin &read(std::string &n) {
fastin &read(strn &n) {
n.clear();
char n_;
while (!isgraph(n_ = get()))
Expand Down Expand Up @@ -117,7 +117,7 @@ class fastin {
*n_ = '\0';
return *this;
}
fastin &getline(std::string &n) {
fastin &getline(strn &n) {
char n_;
while (!isprint(n_ = get()))
;
Expand Down Expand Up @@ -209,7 +209,7 @@ class fastout {
}
template <mint_c T>
fastout &write(T n) { return write(n.val()); }
fastout &write(std::string const &str) { return write(str.c_str()); }
fastout &write(strn const &str) { return write(str.c_str()); }
template <class T, class U>
fastout &write(std::pair<T, U> const &p) { return write(p.first).space().write(p.second); }
template <typename... Ts>
Expand Down
4 changes: 2 additions & 2 deletions src/code/util/huffman_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class huffman {
}
}

constexpr vec<std::string> encode(std::string_view char_set = "01") const {
constexpr vec<strn> encode(strnv char_set = "01") const {
assert(char_set.size() == ch_sz);
return run<std::string>([&](std::string const &pre_code, u32 idx) { return pre_code + char_set[idx]; });
return run<strn>([&](strn const &pre_code, u32 idx) { return pre_code + char_set[idx]; });
}
constexpr vec<u32> depths() const {
return run<u32>([](u32 const &pre_depth, u32) { return pre_depth + 1; });
Expand Down
14 changes: 7 additions & 7 deletions src/code/util/unordered_stl_hacker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace tifa_libs::util {

// Just run it on the same compiler and same options as the solution you want to hack.
// Works for integral types, and std::string. Slow for std::string.
// Works for integral types, and strn. Slow for strn.
template <class T>
inline vec<T> unordered_stl_hacker(usz n) {
auto get_bucket_counts = [n]() {
Expand All @@ -24,19 +24,19 @@ inline vec<T> unordered_stl_hacker(usz n) {

vec<usz> bc = get_bucket_counts();

if constexpr (std::is_same_v<std::string, T>) {
if constexpr (std::is_same_v<strn, T>) {
// Edit these if need
const usz len = 15;
const std::string pref = "";
const std::string alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
const strn pref = "";
const strn alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";

rand::Gen<std::uniform_int_distribution<usz>> gen(0, alphabet.size() - 1);
auto gen_str_with_divisible_hash = [&](usz mod) -> std::string {
std::string s = pref;
auto gen_str_with_divisible_hash = [&](usz mod) -> strn {
strn s = pref;
while (true) {
s.resize(pref.size());
while (s.size() < len) s += alphabet[gen()];
if (!(std::hash<std::string>{}(s) % mod)) return s;
if (!(std::hash<strn>{}(s) % mod)) return s;
}
return "";
};
Expand Down
2 changes: 1 addition & 1 deletion src/test_cpverifier/aizu/alds1_14_a.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::string s, p;
strn s, p;
std::cin >> s >> p;
auto _ = tifa_libs::str::kmp(p, s);
for (auto i : _) std::cout << i << '\n';
Expand Down
2 changes: 1 addition & 1 deletion src/test_cpverifier/aizu/alds1_14_b.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::string s, p;
strn s, p;
std::cin >> s >> p;
auto _ = tifa_libs::str::kmp(p, s);
for (auto i : _) std::cout << i << '\n';
Expand Down
2 changes: 1 addition & 1 deletion src/test_cpverifier/aizu/alds1_14_d.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::string t, s;
strn t, s;
std::cin >> t;
t = " " + t;
u32 n;
Expand Down
2 changes: 1 addition & 1 deletion src/test_cpverifier/aizu/alds1_15_d.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::string s;
strn s;
std::cin >> s;
std::map<char, u32> mp;
for (char c : s) ++mp[c];
Expand Down
2 changes: 1 addition & 1 deletion src/test_cpverifier/aizu/alds1_4_c.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int main() {
std::cin >> n;
tifa_libs::hset<u64> dict;
for (u32 i = 0; i < n; ++i) {
std::string s, t;
strn s, t;
std::cin >> s >> t;
u64 x = 0;
for (char c : t) switch (c) {
Expand Down
2 changes: 1 addition & 1 deletion src/test_cpverifier/aizu/itp1_8_d.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::string s, p;
strn s, p;
std::cin >> s >> p;
s += s;
std::cout << (tifa_libs::str::kmp(p, s).empty() ? "No" : "Yes") << '\n';
Expand Down
2 changes: 1 addition & 1 deletion src/test_cpverifier/aizu/itp1_9_a.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::string s, p, _;
strn s, p, _;
std::cin >> p;
while (std::cin >> _, _ != "END_OF_TEXT") {
for (char &c : _)
Expand Down
2 changes: 1 addition & 1 deletion src/test_cpverifier/library-checker/aplusb.stoi.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ constexpr u64 MOD = u64(1e9) + 1;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::string s, t;
strn s, t;
std::cin >> s >> t;
char ans[16] = {0};
tifa_libs::u32tostr(tifa_libs::str2uint_mod(s, MOD) + tifa_libs::str2uint_mod(t, MOD), ans);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ using hashstr = tifa_libs::str::hash_substr<mint>;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::string s;
strn s;
std::cin >> s;
{
std::string x;
strn x;
x.reserve(s.size() * 2 + 1);
x.push_back('$');
for (char c : s) x.push_back(c), x.push_back('$');
s.swap(x);
}
std::string t = s;
strn t = s;
std::reverse(t.begin(), t.end());
hashstr hs, ht;
hs.set(s), ht.set(t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ int main() {
mintdata1::set_mod(1'000'000'007);
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::string s;
strn s;
std::cin >> s;
{
std::string x;
strn x;
x.reserve(s.size() * 2 + 1);
x.push_back('$');
for (char c : s) x.push_back(c), x.push_back('$');
s.swap(x);
}
std::string t = s;
strn t = s;
std::reverse(t.begin(), t.end());
hashstr hs, ht;
hs.set(s), ht.set(t);
Expand Down
Loading

0 comments on commit 1abd2d8

Please sign in to comment.