mdds
Classes | Public Types | Public Member Functions | List of all members
mdds::sorted_string_map< _ValueT > Class Template Reference

#include <sorted_string_map.hpp>

Classes

struct  entry
 

Public Types

typedef _ValueT value_type
 
typedef size_t 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
 
size_type size () const
 

Detailed Description

template<typename _ValueT>
class mdds::sorted_string_map< _ValueT >

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 >
mdds::sorted_string_map< _ValueT >::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()

template<typename _ValueT >
value_type mdds::sorted_string_map< _ValueT >::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.

◆ size()

template<typename _ValueT >
size_type mdds::sorted_string_map< _ValueT >::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.