API Reference¶
-
template<typename ValueT, template<typename> class KeyFinderT = ssmap::linear_key_finder>
class sorted_string_map¶ sorted_string_map is an immutable associative container that provides an efficient way to map string keys to values of a user-specified type. The keys must be known at compile time and must be sorted in ascending order.
Besides the minimal amount of memory required to store the size and memory address of the caller-provided key-value entries and a few extra data, it does not allocate any additional memory; it simply re-uses the caller-provided key-value entries in all of its operations.
- Template Parameters:
ValueT – Type of the values associated with the string keys. This type must be either movable or copyable.
KeyFinderT – Function object type for performing reverse-lookup of keys from values. This is used in the find_key() method.
Public Types
-
using size_type = typename std::string_view::size_type¶
Public Functions
-
sorted_string_map(const entry_type *entries, size_type entry_size, value_type null_value)¶
Constructor.
- Parameters:
entries – pointer to the array of key-value entries.
entry_size – size of the key-value entry array.
null_value – null value to return when the find method fails to find a matching entry.
-
const value_type &find(const char *input, size_type len) const¶
Find a value associated with a specified string key.
- Parameters:
input – pointer to a C-style string whose value represents the key to match.
len – length of the matching string value.
- Returns:
value associated with the key, or the null value in case the key is not found.
-
const value_type &find(std::string_view input) const¶
Find a value associated with a specified string key.
- Parameters:
input – string key to match.
- Returns:
value associated with the key, or the null value in case the key is not found.
-
std::string_view find_key(const value_type &v) const¶
Find a key associated with a specified value.
Warning
When multiple keys are associated with one value, this method only returns one of the keys. Which key gets returned for that value is undefined.
- Parameters:
v – Value to find the associated key of.
- Returns:
Key associated with the value, or an empty string if no key is found.
-
template<typename ValueT>
class linear_key_finder¶ Function object that iterates through the key-value entries linearly until it finds one that contains the target value.
-
template<typename ValueT>
class hash_key_finder¶ Function object that builds a hash map of values to keys during its construction, and uses it during the lookup of the keys.