mdds
|
#include <sorted_string_map.hpp>
Public Types | |
using | value_type = ValueT |
using | size_type = typename std::string_view::size_type |
using | entry_type = ssmap::detail::map_entry< ValueT > |
Public Member Functions | |
sorted_string_map (const entry_type *entries, size_type entry_size, value_type null_value) | |
const value_type & | find (const char *input, size_type len) const |
const value_type & | find (std::string_view input) const |
std::string_view | find_key (const value_type &v) const |
size_type | size () const |
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.
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. |
using mdds::sorted_string_map< ValueT, KeyFinderT >::entry_type = ssmap::detail::map_entry<ValueT> |
Single key-value entry type. Caller must provide at compile time a static array of these entries.
mdds::sorted_string_map< ValueT, KeyFinderT >::sorted_string_map | ( | const entry_type * | entries, |
size_type | entry_size, | ||
value_type | null_value | ||
) |
Constructor.
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 & mdds::sorted_string_map< ValueT, KeyFinderT >::find | ( | const char * | input, |
size_type | len | ||
) | const |
Find a value associated with a specified string key.
input | pointer to a C-style string whose value represents the key to match. |
len | length of the matching string value. |
const value_type & mdds::sorted_string_map< ValueT, KeyFinderT >::find | ( | std::string_view | input | ) | const |
Find a value associated with a specified string key.
input | string key to match. |
std::string_view mdds::sorted_string_map< ValueT, KeyFinderT >::find_key | ( | const value_type & | v | ) | const |
Find a key associated with a specified value.
v | Value to find the associated key of. |
size_type mdds::sorted_string_map< ValueT, KeyFinderT >::size | ( | ) | const |
Return the number of entries in the map. Since the number of entries is statically defined at compile time, this method always returns the same value.