Skip to content

Commit c8d763d

Browse files
committed
use bump_allocator in many_facts
1 parent d131d01 commit c8d763d

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

cp-algo/structures/eertree.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <iostream>
66
#include <vector>
77
#include <string>
8-
#include "../util/bump_alloc.hpp"
98
namespace cp_algo::structures {
109
template<int sigma = 26, char mch = 'a'>
1110
struct eertree {
@@ -63,7 +62,7 @@ namespace cp_algo::structures {
6362
print(std::identity{});
6463
}
6564
private:
66-
std::vector<std::forward_list<int, bump_alloc<int>>> to;
65+
std::vector<std::forward_list<int>> to;
6766
std::vector<int> len, link, par;
6867
std::string s;
6968
int n = 1, sz = 2, last = 0;

cp-algo/util/bump_alloc.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#ifndef CP_ALGO_UTIL_BUMP_ALLOC_HPP
22
#define CP_ALGO_UTIL_BUMP_ALLOC_HPP
33
#include <cstddef>
4+
#include "big_alloc.hpp"
45
namespace cp_algo {
5-
alignas(64) char buf[450 << 20];
6-
size_t buf_ind = sizeof buf;
7-
template<class T> struct bump_alloc {
6+
template<class T, size_t max_len>
7+
struct bump_alloc {
8+
static char* buf;
9+
static size_t buf_ind;
810
using value_type = T;
911
bump_alloc() = default;
1012
template<class U> bump_alloc(const U&) {}
@@ -15,5 +17,9 @@ namespace cp_algo {
1517
}
1618
void deallocate(T*, size_t) {}
1719
};
20+
template<class T, size_t max_len>
21+
char* bump_alloc<T, max_len>::buf = big_alloc<char>().allocate(max_len * sizeof(T));
22+
template<class T, size_t max_len>
23+
size_t bump_alloc<T, max_len>::buf_ind = max_len * sizeof(T);
1824
}
1925
#endif // CP_ALGO_UTIL_BUMP_ALLOC_HPP

verify/simd/many_facts.test.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "blazingio/blazingio.min.hpp"
77
#include "cp-algo/util/checkpoint.hpp"
88
#include "cp-algo/util/simd.hpp"
9+
#include "cp-algo/util/bump_alloc.hpp"
910
#include "cp-algo/math/common.hpp"
1011

1112
using namespace std;
@@ -14,13 +15,16 @@ using namespace cp_algo;
1415
constexpr int mod = 998244353;
1516
constexpr int imod = -math::inv2(mod);
1617

18+
template<int maxn = 100'000>
1719
vector<int> facts(vector<int> const& args) {
1820
constexpr int accum = 4;
1921
constexpr int simd_size = 8;
2022
constexpr int block = 1 << 18;
2123
constexpr int subblock = block / simd_size;
22-
static basic_string<array<int, 2>> odd_args_per_block[mod / subblock];
23-
static basic_string<array<int, 2>> reg_args_per_block[mod / subblock];
24+
using T = array<int, 2>;
25+
using alloc = bump_alloc<T, 30 * maxn>;
26+
basic_string<T, char_traits<T>, alloc> odd_args_per_block[mod / subblock];
27+
basic_string<T, char_traits<T>, alloc> reg_args_per_block[mod / subblock];
2428
constexpr int limit_reg = mod / 64;
2529
int limit_odd = 0;
2630

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy