proxygen
folly::StringKeyedSetBase< Compare, Alloc > Class Template Reference

#include <StringKeyedSet.h>

Inheritance diagram for folly::StringKeyedSetBase< Compare, Alloc >:

Public Types

typedef Base::key_type key_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::size_type size_type
 
typedef Base::difference_type difference_type
 

Public Member Functions

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

Private Types

using Base = std::set< StringPiece, Compare, Alloc >
 

Detailed Description

template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
class folly::StringKeyedSetBase< Compare, Alloc >

Wrapper class for set<string> 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 set

Definition at line 40 of file StringKeyedSet.h.

Member Typedef Documentation

template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
typedef Base::allocator_type folly::StringKeyedSetBase< Compare, Alloc >::allocator_type

Definition at line 48 of file StringKeyedSet.h.

template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
using folly::StringKeyedSetBase< Compare, Alloc >::Base = std::set<StringPiece, Compare, Alloc>
private

Definition at line 42 of file StringKeyedSet.h.

template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
typedef Base::const_iterator folly::StringKeyedSetBase< Compare, Alloc >::const_iterator

Definition at line 54 of file StringKeyedSet.h.

template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
typedef Base::const_pointer folly::StringKeyedSetBase< Compare, Alloc >::const_pointer

Definition at line 52 of file StringKeyedSet.h.

template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
typedef Base::const_reference folly::StringKeyedSetBase< Compare, Alloc >::const_reference

Definition at line 50 of file StringKeyedSet.h.

template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
typedef Base::const_reverse_iterator folly::StringKeyedSetBase< Compare, Alloc >::const_reverse_iterator

Definition at line 56 of file StringKeyedSet.h.

template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
typedef Base::difference_type folly::StringKeyedSetBase< Compare, Alloc >::difference_type

Definition at line 58 of file StringKeyedSet.h.

template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
typedef Base::iterator folly::StringKeyedSetBase< Compare, Alloc >::iterator

Definition at line 53 of file StringKeyedSet.h.

template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
typedef Base::key_compare folly::StringKeyedSetBase< Compare, Alloc >::key_compare

Definition at line 47 of file StringKeyedSet.h.

template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
typedef Base::key_type folly::StringKeyedSetBase< Compare, Alloc >::key_type

Definition at line 45 of file StringKeyedSet.h.

template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
typedef Base::pointer folly::StringKeyedSetBase< Compare, Alloc >::pointer

Definition at line 51 of file StringKeyedSet.h.

template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
typedef Base::reference folly::StringKeyedSetBase< Compare, Alloc >::reference

Definition at line 49 of file StringKeyedSet.h.

template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
typedef Base::reverse_iterator folly::StringKeyedSetBase< Compare, Alloc >::reverse_iterator

Definition at line 55 of file StringKeyedSet.h.

template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
typedef Base::size_type folly::StringKeyedSetBase< Compare, Alloc >::size_type

Definition at line 57 of file StringKeyedSet.h.

template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
typedef Base::value_type folly::StringKeyedSetBase< Compare, Alloc >::value_type

Definition at line 46 of file StringKeyedSet.h.

Constructor & Destructor Documentation

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

Definition at line 60 of file StringKeyedSet.h.

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

63  : Base(comp, alloc) {}
std::set< StringPiece, Compare, Alloc > Base
template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
folly::StringKeyedSetBase< Compare, Alloc >::StringKeyedSetBase ( const allocator_type alloc)
inlineexplicit

Definition at line 65 of file StringKeyedSet.h.

65 : Base(alloc) {}
std::set< StringPiece, Compare, Alloc > Base
template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
template<class InputIterator >
folly::StringKeyedSetBase< Compare, Alloc >::StringKeyedSetBase ( InputIterator  b,
InputIterator  e,
const key_compare comp = key_compare(),
const allocator_type alloc = allocator_type() 
)
inline

Definition at line 68 of file StringKeyedSet.h.

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

73  : Base(comp, alloc) {
74  for (; b != e; ++b) {
75  emplace(*b);
76  }
77  }
char b
std::set< StringPiece, Compare, Alloc > Base
std::pair< iterator, bool > emplace(Args &&...args)
template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
folly::StringKeyedSetBase< Compare, Alloc >::StringKeyedSetBase ( const StringKeyedSetBase< Compare, Alloc > &  rhs)
inline

Definition at line 79 of file StringKeyedSet.h.

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

Definition at line 82 of file StringKeyedSet.h.

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

Definition at line 85 of file StringKeyedSet.h.

86  : Base(std::move(other)) {
87  assert(other.empty());
88  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::set< StringPiece, Compare, Alloc > Base
template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
folly::StringKeyedSetBase< Compare, Alloc >::StringKeyedSetBase ( StringKeyedSetBase< Compare, Alloc > &&  other,
const allocator_type alloc 
)
inlinenoexcept

Definition at line 90 of file StringKeyedSet.h.

93  : Base(std::move(other), alloc) {
94  assert(other.empty());
95  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::set< StringPiece, Compare, Alloc > Base
template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
folly::StringKeyedSetBase< Compare, Alloc >::StringKeyedSetBase ( 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 StringKeyedSet.h.

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

Definition at line 183 of file StringKeyedSet.h.

References folly::stringPieceDel().

183  {
184  // Here we assume that set doesn't use keys in destructor
185  for (auto it : *this) {
186  stringPieceDel(it, get_allocator());
187  }
188  }
void stringPieceDel(StringPiece piece, const Alloc &alloc)

Member Function Documentation

template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
void folly::StringKeyedSetBase< Compare, Alloc >::clear ( )
inlinenoexcept

Definition at line 170 of file StringKeyedSet.h.

References folly::stringPieceDel().

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

170  {
171  for (auto it : *this) {
172  stringPieceDel(it, get_allocator());
173  }
174  Base::clear();
175  }
void stringPieceDel(StringPiece piece, const Alloc &alloc)
template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
template<class... Args>
std::pair<iterator, bool> folly::StringKeyedSetBase< Compare, Alloc >::emplace ( Args &&...  args)
inline

Definition at line 137 of file StringKeyedSet.h.

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

Referenced by folly::StringKeyedSetBase< Compare, Alloc >::StringKeyedSetBase(), and TEST().

137  {
138  auto key = StringPiece(std::forward<Args>(args)...);
139  auto it = find(key);
140  if (it != end()) {
141  return {it, false};
142  }
143  return Base::emplace(stringPieceDup(key, get_allocator()));
144  }
auto end(TestAdlIterable &instance)
Definition: ForeachTest.cpp:62
StringPiece stringPieceDup(StringPiece piece, const Alloc &alloc)
Range< const char * > StringPiece
template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
iterator folly::StringKeyedSetBase< Compare, Alloc >::erase ( const_iterator  position)
inline

Definition at line 154 of file StringKeyedSet.h.

References folly::stringPieceDel().

Referenced by folly::StringKeyedSetBase< Compare, Alloc >::erase(), and TEST().

154  {
155  auto key = *position;
156  auto result = Base::erase(position);
157  stringPieceDel(key, get_allocator());
158  return result;
159  }
void stringPieceDel(StringPiece piece, const Alloc &alloc)
template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
size_type folly::StringKeyedSetBase< Compare, Alloc >::erase ( StringPiece  key)
inline

Definition at line 161 of file StringKeyedSet.h.

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

161  {
162  auto it = find(key);
163  if (it == end()) {
164  return 0;
165  }
166  erase(it);
167  return 1;
168  }
iterator erase(const_iterator position)
auto end(TestAdlIterable &instance)
Definition: ForeachTest.cpp:62
template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
std::pair<iterator, bool> folly::StringKeyedSetBase< Compare, Alloc >::insert ( value_type  val)
inline

Definition at line 146 of file StringKeyedSet.h.

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

Referenced by TEST().

146  {
147  auto it = find(val);
148  if (it != end()) {
149  return {it, false};
150  }
151  return Base::insert(stringPieceDup(val, get_allocator()));
152  }
double val
Definition: String.cpp:273
auto end(TestAdlIterable &instance)
Definition: ForeachTest.cpp:62
StringPiece stringPieceDup(StringPiece piece, const Alloc &alloc)
template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
StringKeyedSetBase& folly::StringKeyedSetBase< Compare, Alloc >::operator= ( const StringKeyedSetBase< Compare, Alloc > &  other)
inline

Definition at line 103 of file StringKeyedSet.h.

References folly::StringKeyedSetBase< Compare, Alloc >::StringKeyedSetBase().

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

Definition at line 110 of file StringKeyedSet.h.

References folly::test::begin(), folly::padded::cbegin(), folly::padded::cend(), folly::StringKeyedSetBase< Compare, Alloc >::clear(), count, 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  assert(other.empty());
115  return *this;
116  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
bool folly::StringKeyedSetBase< Compare, Alloc >::operator== ( StringKeyedSetBase< Compare, Alloc > const &  other) const
inline

Definition at line 130 of file StringKeyedSet.h.

References testing::Args(), upload::const, and folly::detail::rhs.

130  {
131  Base const& lhs = *this;
132  Base const& rhs = static_cast<Base const&>(other);
133  return lhs == rhs;
134  }
std::set< StringPiece, Compare, Alloc > Base
FOLLY_PUSH_WARNING RHS rhs
Definition: Traits.h:649
const
Definition: upload.py:398
template<class Compare = std::less<StringPiece>, class Alloc = std::allocator<StringPiece>>
void folly::StringKeyedSetBase< Compare, Alloc >::swap ( StringKeyedSetBase< Compare, Alloc > &  other)
inline

Definition at line 179 of file StringKeyedSet.h.

References folly::f14::swap().

179  {
180  return Base::swap(other);
181  }
void swap(SwapTrackingAlloc< T > &, SwapTrackingAlloc< T > &)
Definition: F14TestUtil.h:414

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