Skip to content

Commit 949b115

Browse files
committed
Fix generator
1 parent 582ae55 commit 949b115

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

cp-algo/number_theory/discrete_log.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace cp_algo::math {
1818
using base = dynamic_modint<Int>;
1919
return base::with_mod(m, [&]() -> std::optional<_Int> {
2020
int sqrtmod = std::max(1, (int)std::sqrt(m) / 2);
21-
std::unordered_map<_Int, int> small;
21+
big_map<_Int, int> small;
2222
base cur = a;
2323
for(int i = 0; i < sqrtmod; i++) {
2424
small[cur.getr()] = i;

cp-algo/number_theory/factorize.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef CP_ALGO_MATH_FACTORIZE_HPP
22
#define CP_ALGO_MATH_FACTORIZE_HPP
33
#include "primality.hpp"
4+
#include "../util/big_alloc.hpp"
45
#include "../random/rng.hpp"
56
#include <generator>
67
namespace cp_algo::math {
@@ -34,7 +35,7 @@ namespace cp_algo::math {
3435
});
3536
}
3637
template<typename Int>
37-
std::generator<Int> factorize(Int m) {
38+
big_generator<Int> factorize(Int m) {
3839
if(is_prime(m)) {
3940
co_yield m;
4041
} else if(m > 1) {
@@ -44,7 +45,7 @@ namespace cp_algo::math {
4445
}
4546
}
4647
template<typename Int>
47-
std::generator<Int> divisors_sqrt(Int m) {
48+
big_generator<Int> divisors_sqrt(Int m) {
4849
for(Int i = 1; i * i <= m; i++) {
4950
if(m % i == 0) {
5051
co_yield i;

cp-algo/util/big_alloc.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <string>
1010
#include <cstddef>
1111
#include <iostream>
12+
#include <generator>
1213

1314
// Single macro to detect POSIX platforms (Linux, Unix, macOS)
1415
#if defined(__linux__) || defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
@@ -19,7 +20,7 @@
1920
#endif
2021

2122
namespace cp_algo {
22-
template <typename T, std::size_t Align = 32>
23+
template <typename T, size_t Align = 32>
2324
class big_alloc {
2425
static_assert( Align >= alignof(void*), "Align must be at least pointer-size");
2526
static_assert(std::popcount(Align) == 1, "Align must be a power of two");
@@ -81,5 +82,13 @@ namespace cp_algo {
8182
using big_queue = std::queue<T, big_deque<T>>;
8283
template<typename T>
8384
using big_priority_queue = std::priority_queue<T, big_vector<T>>;
85+
template<typename Ref, typename V = void>
86+
using big_generator = std::generator<Ref, V, big_alloc<std::byte>>;
87+
}
88+
89+
// Deduction guide to make elements_of with big_generator default to big_alloc
90+
namespace std::ranges {
91+
template<typename Ref, typename V>
92+
elements_of(cp_algo::big_generator<Ref, V>&&) -> elements_of<cp_algo::big_generator<Ref, V>&&, cp_algo::big_alloc<std::byte>>;
8493
}
8594
#endif // CP_ALGO_UTIL_big_alloc_HPP

0 commit comments

Comments
 (0)