computes and caches Catalan numbers
More...
|
value_type | get (std::size_t n) |
| computes the n-th Catalan number and updates the cache.
|
|
|
std::vector< value_type > | known {1, 1} |
|
computes and caches Catalan numbers
for assert for std::uint64_t for std::size_t for std::plus & std::multiplies for std::transform_reduce for std::vector
Definition at line 22 of file catalan_numbers.cpp.
◆ value_type
using catalan_numbers::value_type = std::uint64_t |
|
private |
◆ add()
void catalan_numbers::add |
( |
| ) |
|
|
inlineprivate |
◆ compute_next()
value_type catalan_numbers::compute_next |
( |
| ) |
|
|
inlineprivate |
Definition at line 26 of file catalan_numbers.cpp.
26 {
27 return std::transform_reduce(known.begin(), known.end(), known.rbegin(),
28 static_cast<value_type>(0), std::plus<>(),
29 std::multiplies<>());
30 }
◆ get()
value_type catalan_numbers::get |
( |
std::size_t | n | ) |
|
|
inline |
computes the n-th Catalan number and updates the cache.
- Returns
- the n-th Catalan number
Definition at line 39 of file catalan_numbers.cpp.
39 {
40 while (known.size() <= n) {
41 this->add();
42 }
43 return known[n];
44 }
◆ known
std::vector<value_type> catalan_numbers::known {1, 1} |
|
private |
The documentation for this class was generated from the following file: