proxygen
folly::StringKeyedMap< Value, Compare, Alloc > Class Template Reference

#include <StringKeyedMap.h>

Inheritance diagram for folly::StringKeyedMap< Value, Compare, Alloc >:

Public Types

typedef Base::key_type key_type
 
typedef Base::mapped_type mapped_type
 
typedef Base::value_type value_type
 
typedef Base::key_compare key_compare
 
typedef Base::allocator_type allocator_type
 
typedef Base::reference reference
 
typedef Base::const_reference const_reference
 
typedef Base::pointer pointer
 
typedef Base::const_pointer const_pointer
 
typedef Base::iterator iterator
 
typedef Base::const_iterator const_iterator
 
typedef Base::reverse_iterator reverse_iterator
 
typedef Base::const_reverse_iterator const_reverse_iterator
 
typedef Base::difference_type difference_type
 
typedef Base::size_type size_type
 

Public Member Functions

 StringKeyedMap (const key_compare &comp=key_compare(), const allocator_type &alloc=allocator_type())
 
 StringKeyedMap (const allocator_type &alloc)
 
template<class InputIterator >
 StringKeyedMap (InputIterator b, InputIterator e, const key_compare &comp=key_compare(), const allocator_type &alloc=allocator_type())
 
 StringKeyedMap (const StringKeyedMap &rhs)
 
 StringKeyedMap (const StringKeyedMap &rhs, const allocator_type &a)
 
 StringKeyedMap (StringKeyedMap &&other) noexcept
 
 StringKeyedMap (StringKeyedMap &&other, const allocator_type &) noexcept
 
 StringKeyedMap (std::initializer_list< value_type > il, const key_compare &comp=key_compare(), const allocator_type &alloc=allocator_type())
 
StringKeyedMapoperator= (const StringKeyedMap &other)&
 
StringKeyedMapoperator= (StringKeyedMap &&other)&noexcept
 
bool operator== (StringKeyedMap const &other) const
 
mapped_typeoperator[] (StringPiece key)
 
template<class... Args>
std::pair< iterator, bool > emplace (StringPiece key, Args &&...args)
 
std::pair< iterator, bool > insert (value_type val)
 
iterator erase (const_iterator position)
 
size_type erase (StringPiece key)
 
void clear () noexcept
 
 ~StringKeyedMap ()
 

Private Types

using Base = std::map< StringPiece, Value, Compare, Alloc >
 

Detailed Description

template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
class folly::StringKeyedMap< Value, Compare, Alloc >

Wrapper class for map<string, Value> that can perform lookup operations with StringPiece, not only string.

It uses kind of hack: string pointed by StringPiece is copied when StringPiece is inserted into map

Definition at line 41 of file StringKeyedMap.h.

Member Typedef Documentation

template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
typedef Base::allocator_type folly::StringKeyedMap< Value, Compare, Alloc >::allocator_type

Definition at line 50 of file StringKeyedMap.h.

template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
using folly::StringKeyedMap< Value, Compare, Alloc >::Base = std::map<StringPiece, Value, Compare, Alloc>
private

Definition at line 43 of file StringKeyedMap.h.

template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
typedef Base::const_iterator folly::StringKeyedMap< Value, Compare, Alloc >::const_iterator

Definition at line 56 of file StringKeyedMap.h.

template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
typedef Base::const_pointer folly::StringKeyedMap< Value, Compare, Alloc >::const_pointer

Definition at line 54 of file StringKeyedMap.h.

template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
typedef Base::const_reference folly::StringKeyedMap< Value, Compare, Alloc >::const_reference

Definition at line 52 of file StringKeyedMap.h.

template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
typedef Base::const_reverse_iterator folly::StringKeyedMap< Value, Compare, Alloc >::const_reverse_iterator

Definition at line 58 of file StringKeyedMap.h.

template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
typedef Base::difference_type folly::StringKeyedMap< Value, Compare, Alloc >::difference_type

Definition at line 59 of file StringKeyedMap.h.

template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
typedef Base::iterator folly::StringKeyedMap< Value, Compare, Alloc >::iterator

Definition at line 55 of file StringKeyedMap.h.

template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
typedef Base::key_compare folly::StringKeyedMap< Value, Compare, Alloc >::key_compare

Definition at line 49 of file StringKeyedMap.h.

template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
typedef Base::key_type folly::StringKeyedMap< Value, Compare, Alloc >::key_type

Definition at line 46 of file StringKeyedMap.h.

template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
typedef Base::mapped_type folly::StringKeyedMap< Value, Compare, Alloc >::mapped_type

Definition at line 47 of file StringKeyedMap.h.

template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
typedef Base::pointer folly::StringKeyedMap< Value, Compare, Alloc >::pointer

Definition at line 53 of file StringKeyedMap.h.

template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
typedef Base::reference folly::StringKeyedMap< Value, Compare, Alloc >::reference

Definition at line 51 of file StringKeyedMap.h.

template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
typedef Base::reverse_iterator folly::StringKeyedMap< Value, Compare, Alloc >::reverse_iterator

Definition at line 57 of file StringKeyedMap.h.

template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
typedef Base::size_type folly::StringKeyedMap< Value, Compare, Alloc >::size_type

Definition at line 60 of file StringKeyedMap.h.

template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
typedef Base::value_type folly::StringKeyedMap< Value, Compare, Alloc >::value_type

Definition at line 48 of file StringKeyedMap.h.

Constructor & Destructor Documentation

template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
folly::StringKeyedMap< Value, Compare, Alloc >::StringKeyedMap ( const key_compare comp = key_compare(),
const allocator_type alloc = allocator_type() 
)
inlineexplicit

Definition at line 66 of file StringKeyedMap.h.

Referenced by folly::StringKeyedMap< Value, Compare, Alloc >::operator=().

69  : Base(comp, alloc) {}
std::map< StringPiece, Value, Compare, Alloc > Base
template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
folly::StringKeyedMap< Value, Compare, Alloc >::StringKeyedMap ( const allocator_type alloc)
inlineexplicit

Definition at line 71 of file StringKeyedMap.h.

71 : Base(alloc) {}
std::map< StringPiece, Value, Compare, Alloc > Base
template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
template<class InputIterator >
folly::StringKeyedMap< Value, Compare, Alloc >::StringKeyedMap ( InputIterator  b,
InputIterator  e,
const key_compare comp = key_compare(),
const allocator_type alloc = allocator_type() 
)
inlineexplicit

Definition at line 74 of file StringKeyedMap.h.

References b, and folly::StringKeyedMap< Value, Compare, Alloc >::emplace().

79  : Base(comp, alloc) {
80  for (; b != e; ++b) {
81  // emplace() will carry the duplication
82  emplace(b->first, b->second);
83  }
84  }
char b
std::pair< iterator, bool > emplace(StringPiece key, Args &&...args)
std::map< StringPiece, Value, Compare, Alloc > Base
template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
folly::StringKeyedMap< Value, Compare, Alloc >::StringKeyedMap ( const StringKeyedMap< Value, Compare, Alloc > &  rhs)
inline

Definition at line 86 of file StringKeyedMap.h.

87  : StringKeyedMap(rhs, rhs.get_allocator()) {}
FOLLY_PUSH_WARNING RHS rhs
Definition: Traits.h:649
StringKeyedMap(const key_compare &comp=key_compare(), const allocator_type &alloc=allocator_type())
template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
folly::StringKeyedMap< Value, Compare, Alloc >::StringKeyedMap ( const StringKeyedMap< Value, Compare, Alloc > &  rhs,
const allocator_type a 
)
inline

Definition at line 89 of file StringKeyedMap.h.

90  : StringKeyedMap(rhs.begin(), rhs.end(), rhs.key_comp(), a) {}
FOLLY_PUSH_WARNING RHS rhs
Definition: Traits.h:649
StringKeyedMap(const key_compare &comp=key_compare(), const allocator_type &alloc=allocator_type())
char a
template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
folly::StringKeyedMap< Value, Compare, Alloc >::StringKeyedMap ( StringKeyedMap< Value, Compare, Alloc > &&  other)
inlinenoexcept

Definition at line 92 of file StringKeyedMap.h.

92 : Base(std::move(other)) {}
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::map< StringPiece, Value, Compare, Alloc > Base
template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
folly::StringKeyedMap< Value, Compare, Alloc >::StringKeyedMap ( StringKeyedMap< Value, Compare, Alloc > &&  other,
const allocator_type  
)
inlinenoexcept

Definition at line 94 of file StringKeyedMap.h.

95  : Base(std::move(other) /*, a*/ /* not supported by gcc */) {}
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::map< StringPiece, Value, Compare, Alloc > Base
template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
folly::StringKeyedMap< Value, Compare, Alloc >::StringKeyedMap ( std::initializer_list< value_type il,
const key_compare comp = key_compare(),
const allocator_type alloc = allocator_type() 
)
inline

Definition at line 97 of file StringKeyedMap.h.

101  : StringKeyedMap(il.begin(), il.end(), comp, alloc) {}
StringKeyedMap(const key_compare &comp=key_compare(), const allocator_type &alloc=allocator_type())
template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
folly::StringKeyedMap< Value, Compare, Alloc >::~StringKeyedMap ( )
inline

Definition at line 196 of file StringKeyedMap.h.

References folly::stringPieceDel().

196  {
197  // Here we assume that map doesn't use keys in destructor
198  for (auto& it : *this) {
199  stringPieceDel(it.first, get_allocator());
200  }
201  }
void stringPieceDel(StringPiece piece, const Alloc &alloc)

Member Function Documentation

template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
void folly::StringKeyedMap< Value, Compare, Alloc >::clear ( )
inlinenoexcept

Definition at line 187 of file StringKeyedMap.h.

References folly::stringPieceDel(), and folly::f14::swap().

Referenced by folly::StringKeyedMap< Value, Compare, Alloc >::operator=().

187  {
188  for (auto& it : *this) {
189  stringPieceDel(it.first, get_allocator());
190  }
191  Base::clear();
192  }
void stringPieceDel(StringPiece piece, const Alloc &alloc)
template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
template<class... Args>
std::pair<iterator, bool> folly::StringKeyedMap< Value, Compare, Alloc >::emplace ( StringPiece  key,
Args &&...  args 
)
inline

Definition at line 153 of file StringKeyedMap.h.

References folly::test::end(), and folly::stringPieceDup().

Referenced by BENCHMARK_RELATIVE(), folly::StringKeyedMap< Value, Compare, Alloc >::StringKeyedMap(), and TEST().

153  {
154  auto it = find(key);
155  if (it != end()) {
156  return {it, false};
157  }
158  return Base::emplace(
159  stringPieceDup(key, get_allocator()), std::forward<Args>(args)...);
160  }
auto end(TestAdlIterable &instance)
Definition: ForeachTest.cpp:62
StringPiece stringPieceDup(StringPiece piece, const Alloc &alloc)
template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
iterator folly::StringKeyedMap< Value, Compare, Alloc >::erase ( const_iterator  position)
inline

Definition at line 171 of file StringKeyedMap.h.

References folly::stringPieceDel().

Referenced by BENCHMARK_RELATIVE(), folly::StringKeyedMap< Value, Compare, Alloc >::erase(), and TEST().

171  {
172  auto key = position->first;
173  auto result = Base::erase(position);
174  stringPieceDel(key, get_allocator());
175  return result;
176  }
void stringPieceDel(StringPiece piece, const Alloc &alloc)
template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
size_type folly::StringKeyedMap< Value, Compare, Alloc >::erase ( StringPiece  key)
inline

Definition at line 178 of file StringKeyedMap.h.

References folly::test::end(), and folly::StringKeyedMap< Value, Compare, Alloc >::erase().

178  {
179  auto it = find(key);
180  if (it == end()) {
181  return 0;
182  }
183  erase(it);
184  return 1;
185  }
auto end(TestAdlIterable &instance)
Definition: ForeachTest.cpp:62
iterator erase(const_iterator position)
template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
std::pair<iterator, bool> folly::StringKeyedMap< Value, Compare, Alloc >::insert ( value_type  val)
inline

Definition at line 162 of file StringKeyedMap.h.

References folly::test::end(), folly::gen::move, and folly::stringPieceDup().

Referenced by TEST().

162  {
163  auto it = find(val.first);
164  if (it != end()) {
165  return {it, false};
166  }
167  return Base::insert(std::make_pair(
168  stringPieceDup(val.first, get_allocator()), std::move(val.second)));
169  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
double val
Definition: String.cpp:273
auto end(TestAdlIterable &instance)
Definition: ForeachTest.cpp:62
StringPiece stringPieceDup(StringPiece piece, const Alloc &alloc)
template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
StringKeyedMap& folly::StringKeyedMap< Value, Compare, Alloc >::operator= ( const StringKeyedMap< Value, Compare, Alloc > &  other)
inline

Definition at line 103 of file StringKeyedMap.h.

References folly::StringKeyedMap< Value, Compare, Alloc >::StringKeyedMap().

103  {
104  if (this == &other) {
105  return *this;
106  }
107  return *this = StringKeyedMap(other);
108  }
StringKeyedMap(const key_compare &comp=key_compare(), const allocator_type &alloc=allocator_type())
template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
StringKeyedMap& folly::StringKeyedMap< Value, Compare, Alloc >::operator= ( StringKeyedMap< Value, Compare, Alloc > &&  other)
inlinenoexcept

Definition at line 110 of file StringKeyedMap.h.

References folly::test::begin(), folly::padded::cbegin(), folly::padded::cend(), folly::StringKeyedMap< Value, Compare, Alloc >::clear(), folly::empty(), folly::test::end(), folly::gen::move, and folly::size().

110  {
111  assert(this != &other);
112  clear();
113  Base::operator=(std::move(other));
114  return *this;
115  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void clear() noexcept
template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
bool folly::StringKeyedMap< Value, Compare, Alloc >::operator== ( StringKeyedMap< Value, Compare, Alloc > const &  other) const
inline

Definition at line 129 of file StringKeyedMap.h.

References upload::const, and folly::detail::rhs.

129  {
130  Base const& lhs = *this;
131  Base const& rhs = static_cast<Base const&>(other);
132  return lhs == rhs;
133  }
std::map< StringPiece, Value, Compare, Alloc > Base
FOLLY_PUSH_WARNING RHS rhs
Definition: Traits.h:649
const
Definition: upload.py:398
template<class Value, class Compare = std::less<StringPiece>, class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
mapped_type& folly::StringKeyedMap< Value, Compare, Alloc >::operator[] ( StringPiece  key)
inline

Definition at line 136 of file StringKeyedMap.h.

References testing::Args(), count, folly::test::end(), and folly::stringPieceDup().

136  {
137  auto it = find(key);
138  if (it != end()) {
139  return it->second;
140  }
141  // operator[] will create new (key, value) pair
142  // we need to allocate memory for key
143  return Base::operator[](stringPieceDup(key, get_allocator()));
144  }
auto end(TestAdlIterable &instance)
Definition: ForeachTest.cpp:62
StringPiece stringPieceDup(StringPiece piece, const Alloc &alloc)

The documentation for this class was generated from the following file: