P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::string_map< V > Class Template Reference

#include <string_map.h>

Public Types

using const_iterator = typename list_type::const_iterator
 
using const_reference = const value_type &
 
using const_reverse_iterator = std::reverse_iterator<const_iterator>
 
using iterator = typename list_type::iterator
 
using key_type = cstring
 
using mapped_type = V
 
using reference = value_type &
 
using reverse_iterator = std::reverse_iterator<iterator>
 
using size_type = typename map_type::size_type
 
using value_type = std::pair<cstring, V>
 

Public Member Functions

 string_map (const string_map &a)
 
template<typename InputIt >
 string_map (InputIt first, InputIt last)
 
 string_map (std::initializer_list< value_type > il)
 
 string_map (string_map &&a)=default
 
template<typename Key >
V & at (Key &&k)
 
template<typename Key >
const V & at (Key &&k) const
 
const_iterator begin () const noexcept
 
iterator begin () noexcept
 
const_iterator cbegin () const noexcept
 
const_iterator cend () const noexcept
 
void clear ()
 
bool contains (cstring a) const
 
bool contains (std::string_view a) const
 
size_type count (cstring a) const
 
size_type count (std::string_view a) const
 
const_reverse_iterator crbegin () const noexcept
 
const_reverse_iterator crend () const noexcept
 
template<typename Key , typename... VV>
std::pair< iterator, bool > emplace (Key &&k, VV &&...v)
 
bool empty () const noexcept
 
const_iterator end () const noexcept
 
iterator end () noexcept
 
iterator erase (const_iterator pos)
 
size_type erase (cstring k)
 
size_type erase (std::string_view k)
 
iterator find (cstring a)
 
const_iterator find (cstring a) const
 
iterator find (std::string_view a)
 
const_iterator find (std::string_view a) const
 
std::pair< iterator, bool > insert (const value_type &value)
 
template<class InputIterator >
void insert (InputIterator b, InputIterator e)
 
std::pair< iterator, bool > insert (value_type &&value)
 
size_type max_size () const noexcept
 
bool operator!= (const string_map &a) const
 
string_mapoperator= (const string_map &a)
 
string_mapoperator= (string_map &&a)=default
 
bool operator== (const string_map &a) const
 
template<typename Key >
V & operator[] (Key &&k)
 
const_reverse_iterator rbegin () const noexcept
 
reverse_iterator rbegin () noexcept
 
const_reverse_iterator rend () const noexcept
 
reverse_iterator rend () noexcept
 
size_type size () const noexcept
 
void swap (string_map &other)
 

Detailed Description

template<class V>
class P4::string_map< V >

Map with string keys that is ordered by order of element insertion. Use this map only when stable iteration order is significant. For everything else consider using some other unordered containers with cstring keys. Never use std::map<cstring, ...> or ordered_map<cstring, ...> as these maps will have significant overhead due to lexicographical ordering of the keys.

For this particular implementation:

  • Key are stored as cstrings in the underlying abseil hash map.
  • Heterogenous lookup (with std::string_view keys) is supported. Special care is done not to create cstrings in case if they are not in the map already
  • Values are stored in std::list, similar to ordered_map.

Member Function Documentation

◆ find()

template<class V >
iterator P4::string_map< V >::find ( std::string_view a)
inline

Functions below do have std::string_view versions. Here we are having important special case: if a is not something that was interned, we do not copy / intern it, we know for sure that a is not in the map and we do not need to perform a lookup.

◆ operator==()

template<class V >
bool P4::string_map< V >::operator== ( const string_map< V > & a) const
inline

As the map is ordered, two maps are only considered equal if the elements are inserted in the same order. Same as with ordered_map though.