|
| bool | ends_with (const std::string &str, const std::string &suffix) |
| | Tests whether a string ends with a given suffix.
|
| |
| std::vector< std::string > | split (const std::string &s, char delimiter) |
| | Splits a string into parts using a single-character delimiter.
|
| |
| std::string | doubleToString (double value, int precision) |
| | Converts a double to a fixed-format string with a given precision.
|
| |
| std::string | to_lowercase (const std::string &str) |
| | Returns a lowercase copy of the input string.
|
| |
| template<typename T , typename U > |
| std::unordered_set< T > | get_keys (const std::map< T, U > &map) |
| | Extracts the key set from a std::map into an unordered_set.
|
| |
| template<typename T , typename U > |
| std::unordered_set< T > | get_keys (const std::unordered_map< T, U > &map) |
| | Extracts the key set from a std::unordered_map into an unordered_set.
|
| |
| template<typename T , typename U > |
| bool | haveSameKeys (const std::map< T, U > &map1, const std::map< T, U > &map2) |
| | Checks whether two std::map instances have the same set of keys.
|
| |
| template<typename T > |
| void | print_value (std::ostream &os, const T &value) |
| | Generic helper to print a value to an output stream.
|
| |
| template<typename T > |
| void | print_value (std::ostream &os, const std::shared_ptr< T > &ptr) |
| | Specialization of print_value for std::shared_ptr.
|
| |
| template<typename Map > |
| std::enable_if_t< std::is_same_v< typename Map::value_type, std::pair< const typename Map::key_type, typename Map::mapped_type > >, std::ostream & > | operator<< (std::ostream &os, const Map &m) |
| | Generic stream output operator for map-like containers.
|
| |
| template<typename T , std::size_t cache_size, typename Func , typename... Args> |
| void | fill_cache (Func &&f, double a, double b, std::array< T, cache_size > &cache, Args &&... args) |
| | Fills a lookup cache for a function on a finite interval [a, b].
|
| |
| template<typename T , typename U , std::size_t cache_size> |
| T | lerp (U x, const std::array< T, cache_size > &lookup, double a=0.0, double b=1.0) |
| | Linearly interpolates a cached function on [a, b].
|
| |
template<typename
T , std::size_t cache_size, typename Func , typename... Args>
| void fill_cache |
( |
Func && |
f, |
|
|
double |
a, |
|
|
double |
b, |
|
|
std::array< T, cache_size > & |
cache, |
|
|
Args &&... |
args |
|
) |
| |
Fills a lookup cache for a function on a finite interval [a, b].
The function f is evaluated at cache_size sample points in the interval [a, b], and the results are stored in cache. The first and last points are slightly shifted away from the exact endpoints using nld.epsilon() to avoid potential issues (e.g. singularities) exactly at the boundaries.
The intermediate points are placed uniformly between a and b.
- Template Parameters
-
| T | Value type stored in the cache. |
| cache_size | Size of the cache array. |
| Func | Callable type; must be invocable as f(double, Args...). |
| Args | Additional argument types forwarded to f. |
- Parameters
-
| f | Function to sample. |
| a | Lower bound of the interval. |
| b | Upper bound of the interval. |
| cache | Preallocated array to fill with sampled values. |
| args | Additional arguments forwarded to f. |
Definition at line 241 of file Utils.h.
template<typename
T , typename U , std::size_t cache_size>
| T lerp |
( |
U |
x, |
|
|
const std::array< T, cache_size > & |
lookup, |
|
|
double |
a = 0.0, |
|
|
double |
b = 1.0 |
|
) |
| |
Linearly interpolates a cached function on [a, b].
Given a lookup table lookup filled with values of some function f at uniformly spaced points in [a, b] (as produced by fill_cache), this routine returns an interpolated value for an input x.
The input x is first clamped to [a, b]. Then:
- it is mapped to a floating-point index in [0, cache_size - 1],
- the two neighboring cache entries are linearly combined according to the fractional part of the index.
- Template Parameters
-
| T | Value type stored in the cache and returned. |
| U | Type of x (convertible to double). |
| cache_size | Size of the lookup array. |
- Parameters
-
| x | Input coordinate at which the function is approximated. |
| lookup | Cache/lookup table of sampled values. |
| a | Lower bound of the sampling interval (default: 0.0). |
| b | Upper bound of the sampling interval (default: 1.0). |
- Returns
- Interpolated value at
x.
Definition at line 276 of file Utils.h.
template<typename Map >
| std::enable_if_t< std::is_same_v< typename Map::value_type, std::pair< const typename Map::key_type, typename Map::mapped_type > >, std::ostream & > operator<< |
( |
std::ostream & |
os, |
|
|
const Map & |
m |
|
) |
| |
Generic stream output operator for map-like containers.
This template is enabled only for types Map whose value_type matches std::pair<const key_type, mapped_type>, i.e. true associative maps. The contents are printed in a JSON-like style:
{ key1: value1, key2: value2, ... }
where values are printed using print_value(), so pointer-like values are handled gracefully.
- Template Parameters
-
| Map | Map-like container type. |
- Parameters
-
| os | Output stream. |
| m | Map to print. |
- Returns
- Reference to the output stream.
Definition at line 176 of file Utils.h.