mdds
Public Types | Public Member Functions | List of all members
mdds::sorted_string_map< ValueT, EntryT > Class Template Reference

#include <sorted_string_map.hpp>

Public Types

using value_type = ValueT
 
using size_type = std::size_t
 
using entry = EntryT< ValueT, size_type >
 

Public Member Functions

 sorted_string_map (const entry *entries, size_type entry_size, value_type null_value)
 
value_type find (const char *input, size_type len) const
 
value_type find (std::string_view input) const
 
size_type size () const
 

Detailed Description

template<typename ValueT, template< typename, typename > class EntryT = chars_map_entry>
class mdds::sorted_string_map< ValueT, EntryT >

sorted_string_map provides an efficient way to map string keys to arbitrary values, provided that the keys are known at compile time and are sorted in ascending order.

Constructor & Destructor Documentation

◆ sorted_string_map()

template<typename ValueT , template< typename, typename > class EntryT = chars_map_entry>
mdds::sorted_string_map< ValueT, EntryT >::sorted_string_map ( const entry *  entries,
size_type  entry_size,
value_type  null_value 
)

Constructor.

Parameters
entriespointer to the array of key-value entries.
entry_sizesize of the key-value entry array.
null_valuenull value to return when the find method fails to find a matching entry.

Member Function Documentation

◆ find() [1/2]

template<typename ValueT , template< typename, typename > class EntryT = chars_map_entry>
value_type mdds::sorted_string_map< ValueT, EntryT >::find ( const char *  input,
size_type  len 
) const

Find a value associated with a specified string key.

Parameters
inputpointer to a C-style string whose value represents the key to match.
lenlength 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, typename > class EntryT = chars_map_entry>
value_type mdds::sorted_string_map< ValueT, EntryT >::find ( std::string_view  input) const

Find a value associated with a specified string key.

Parameters
inputstring key to match.
Returns
value associated with the key, or the null value in case the key is not found.

◆ size()

template<typename ValueT , template< typename, typename > class EntryT = chars_map_entry>
size_type mdds::sorted_string_map< ValueT, EntryT >::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.