Loading...
Searching...
No Matches
mdds::sorted_string_map< ValueT, KeyFinderT > Class Template Reference

`#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

## Detailed Description

template<typename ValueT, template< typename > class KeyFinderT = ssmap::linear_key_finder>
class mdds::sorted_string_map< ValueT, KeyFinderT >

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.

## Member Typedef Documentation

## entry_type

template<typename ValueT, template< typename > class KeyFinderT = ssmap::linear_key_finder>

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.

## Constructor & Destructor Documentation

## sorted_string_map()

template<typename ValueT, template< typename > class KeyFinderT = ssmap::linear_key_finder>

mdds::sorted_string_map< ValueT, KeyFinderT >::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.

## Member Function Documentation

## find() [1/2]

template<typename ValueT, template< typename > class KeyFinderT = ssmap::linear_key_finder>

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.

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.

## find() [2/2]

template<typename ValueT, template< typename > class KeyFinderT = ssmap::linear_key_finder>

const value_type & mdds::sorted_string_map< ValueT, KeyFinderT >::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.

## find_key()

template<typename ValueT, template< typename > class KeyFinderT = ssmap::linear_key_finder>

std::string_view mdds::sorted_string_map< ValueT, KeyFinderT >::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.

## size()

template<typename ValueT, template< typename > class KeyFinderT = ssmap::linear_key_finder>

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.

Returns
  the number of entries in the map.