BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdlc_flathashset.h
Go to the documentation of this file.
1/// @file bdlc_flathashset.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlc_flathashset.h -*-C++-*-
8#ifndef INCLUDED_BDLC_FLATHASHSET
9#define INCLUDED_BDLC_FLATHASHSET
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlc_flathashset bdlc_flathashset
15/// @brief Provide an open-addressed unordered set container.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlc
19/// @{
20/// @addtogroup bdlc_flathashset
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlc_flathashset-purpose"> Purpose</a>
25/// * <a href="#bdlc_flathashset-classes"> Classes </a>
26/// * <a href="#bdlc_flathashset-description"> Description </a>
27/// * <a href="#bdlc_flathashset-performance-caveats"> Performance Caveats </a>
28/// * <a href="#bdlc_flathashset-interface-differences-with-bsl-unordered_set"> Interface Differences with bsl::unordered_set </a>
29/// * <a href="#bdlc_flathashset-load-factor-and-resizing"> Load Factor and Resizing </a>
30/// * <a href="#bdlc_flathashset-requirements-on-key-hash-and-equal"> Requirements on KEY, HASH, and EQUAL </a>
31/// * <a href="#bdlc_flathashset-iterator-pointer-and-reference-invalidation"> Iterator, Pointer, and Reference Invalidation </a>
32/// * <a href="#bdlc_flathashset-exception-safety"> Exception Safety </a>
33/// * <a href="#bdlc_flathashset-move-semantics-in-c-03"> Move Semantics in C++03 </a>
34/// * <a href="#bdlc_flathashset-usage"> Usage </a>
35/// * <a href="#bdlc_flathashset-example-1-categorizing-data"> Example 1: Categorizing Data </a>
36///
37/// # Purpose {#bdlc_flathashset-purpose}
38/// Provide an open-addressed unordered set container.
39///
40/// # Classes {#bdlc_flathashset-classes}
41///
42/// - bdlc::FlatHashSet: open-addressed unordered set container
43///
44/// @see bdlc_flathashtable, bdlc_flathashmap
45///
46/// # Description {#bdlc_flathashset-description}
47/// This component defines a single class template,
48/// `bdlc::FlatHashSet`, that implements an open-addressed unordered set of
49/// items with unique values.
50///
51/// Unordered sets are useful in situations when there is no meaningful way to
52/// order key values, when the order of the values is irrelevant to the problem
53/// domain, or (even if there is a meaningful ordering) the value of ordering
54/// the results is outweighed by the higher performance provided by unordered
55/// sets (compared to ordered sets). On platforms that support relevant SIMD
56/// instructions (e.g., SSE2), `bdlc::FlatHashSet` generally exhibits better
57/// performance than `bsl::unordered_set`.
58///
59/// An instantiation of `bdlc::FlatHashSet` is an allocator-aware,
60/// value-semantic type whose salient attributes are the set of values
61/// contained, without regard to order. An instantiation may be provided with
62/// custom hash and equality functors, but those are not salient attributes. In
63/// particular, when comparing element values for equality between two different
64/// `bdlc::FlatHashSet` objects, the elements are compared using `operator==`.
65///
66/// The implemented data structure is inspired by Google's @ref flat_hash_map
67/// CppCon presentations (available on YouTube). The implementation draws from
68/// Google's open source `raw_hash_set.h` file at:
69/// https://github.com/abseil/abseil-cpp/blob/master/absl/container/internal.
70///
71/// ## Performance Caveats {#bdlc_flathashset-performance-caveats}
72///
73///
74/// `bdlc::FlatHashSet` is recommended for Intel platforms *only* (i.e., Linux
75/// and Windows, and pre-ARM Macs); on platforms using other processors (i.e.,
76/// Sun and AIX), `bdlc::FlatHashSet` may have slower performance than
77/// `bsl::unordered_set`. However, note that `bdlc::FlatHashSet` will use
78/// significantly less memory than `bsl::unordered_set` on *all* platforms.
79/// Given the Intel-only performance caveat, it is recommended to benchmark
80/// before using `bdlc::FlatHashSet` -- particularly on non-Intel production
81/// environments.
82///
83/// ## Interface Differences with bsl::unordered_set {#bdlc_flathashset-interface-differences-with-bsl-unordered_set}
84///
85///
86/// A `bdlc::FlatHashSet` meets most of the requirements of an unordered
87/// associative container with forward iterators in the C++11 Standard [23.2.5].
88/// It does not have the bucket interface, and locations of elements may change
89/// when the container is modified (and therefore iterators become invalid too).
90/// Allocator use follows BDE style, and the various allocator propagation
91/// attributes are not present (e.g., the allocator trait
92/// @ref propagate_on_container_copy_assignment ). The maximum load factor of the
93/// container (the ratio of size to capacity) is maintained by the container
94/// itself and is not settable (the maximum load factor is implementation
95/// defined and fixed).
96///
97/// ## Load Factor and Resizing {#bdlc_flathashset-load-factor-and-resizing}
98///
99///
100/// An invariant of `bdlc::FlatHashSet` is that
101/// `0 <= load_factor() <= max_load_factor() <= 1.0`. Any operation that would
102/// result in `load_factor() > max_load_factor()` for a `bdlc::FlatHashSet`
103/// causes the capacity to increase. This resizing allocates new memory, copies
104/// or moves all elements to the new memory, and reclaims the original memory.
105/// The transfer of elements involves rehashing each element to determine its
106/// new location. As such, all iterators, pointers, and references to elements
107/// of the `bdlc::FlatHashSet` are invalidated on a resize.
108///
109/// ## Requirements on KEY, HASH, and EQUAL {#bdlc_flathashset-requirements-on-key-hash-and-equal}
110///
111///
112/// The template parameter type `KEY` must be copy or move constructible. The
113/// template parameter types `HASH` and `EQUAL` must be default and copy
114/// constructible function objects.
115///
116/// `HASH` must support a function-call operator compatible with the following
117/// statements for an object `key` of type `KEY`:
118/// @code
119/// HASH hash;
120/// bsl::size_t result = hash(key);
121/// @endcode
122///
123/// `EQUAL` must support a function-call operator compatible with the
124/// following statements for objects `key1` and `key2` of type `KEY`:
125/// @code
126/// EQUAL equal;
127/// bool result = equal(key1, key2);
128/// @endcode
129/// where the definition of the called function defines an equivalence
130/// relationship on keys that is both reflexive and transitive.
131///
132/// `HASH` and `EQUAL` function objects are further constrained: if the
133/// comparator determines that two values are equal, the hasher must produce the
134/// same hash value for each.
135///
136/// ## Iterator, Pointer, and Reference Invalidation {#bdlc_flathashset-iterator-pointer-and-reference-invalidation}
137///
138///
139/// Any change in capacity of a `bdlc::FlatHashSet` invalidates all pointers,
140/// references, and iterators. A `bdlc::FlatHashSet` manipulator that erases an
141/// element invalidates all pointers, references, and iterators to the erased
142/// element.
143///
144/// ## Exception Safety {#bdlc_flathashset-exception-safety}
145///
146///
147/// A `bdlc::FlatHashSet` is exception neutral, and all of the methods of
148/// `bdlc::FlatHashSet` provide the basic exception safety guarantee (see
149/// {@ref bsldoc_glossary |Basic Guarantee}).
150///
151/// ## Move Semantics in C++03 {#bdlc_flathashset-move-semantics-in-c-03}
152///
153///
154/// Move-only types are supported by `bdlc::FlatHashSet` on C++11, and later,
155/// platforms only (where `BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES` is defined),
156/// and are not supported on C++03 platforms. Unfortunately, in C++03, there
157/// are user-defined types where a `bslmf::MovableRef` will not safely degrade
158/// to an lvalue reference when a move constructor is not available (types
159/// providing a constructor template taking any type), so
160/// `bslmf::MovableRefUtil::move` cannot be used directly on a user-supplied
161/// template parameter type.
162///
163/// ## Usage {#bdlc_flathashset-usage}
164///
165///
166/// In this section we show intended use of this component.
167///
168/// ### Example 1: Categorizing Data {#bdlc_flathashset-example-1-categorizing-data}
169///
170///
171/// Suppose one is analyzing data on a set of customers, and each customer is
172/// categorized by several attributes: customer type, geographic area, and
173/// (internal) project code; and that each attribute takes on one of a limited
174/// set of values. This data can be handled by creating an enumeration for each
175/// of the attributes:
176/// @code
177/// typedef enum {
178/// e_REPEAT
179/// , e_DISCOUNT
180/// , e_IMPULSE
181/// , e_NEED_BASED
182/// , e_BUSINESS
183/// , e_NON_PROFIT
184/// , e_INSTITUTE
185/// // ...
186/// } CustomerCode;
187///
188/// typedef enum {
189/// e_USA_EAST
190/// , e_USA_WEST
191/// , e_CANADA
192/// , e_MEXICO
193/// , e_ENGLAND
194/// , e_SCOTLAND
195/// , e_FRANCE
196/// , e_GERMANY
197/// , e_RUSSIA
198/// // ...
199/// } LocationCode;
200///
201/// typedef enum {
202/// e_TOAST
203/// , e_GREEN
204/// , e_FAST
205/// , e_TIDY
206/// , e_PEARL
207/// , e_SMITH
208/// // ...
209/// } ProjectCode;
210/// @endcode
211/// The data set (randomly generated for this example) is provided in a
212/// statically initialized array:
213/// @code
214/// static const struct CustomerProfile {
215/// CustomerCode d_customer;
216/// LocationCode d_location;
217/// ProjectCode d_project;
218/// } customerProfiles[] = {
219/// { e_IMPULSE , e_CANADA , e_SMITH },
220/// { e_NON_PROFIT, e_USA_EAST, e_GREEN },
221/// { e_INSTITUTE , e_USA_EAST, e_TOAST },
222/// { e_NON_PROFIT, e_CANADA , e_PEARL },
223/// { e_NEED_BASED, e_CANADA , e_FAST },
224/// { e_BUSINESS , e_ENGLAND , e_PEARL },
225/// { e_REPEAT , e_SCOTLAND, e_TIDY },
226/// { e_INSTITUTE , e_MEXICO , e_PEARL },
227/// { e_DISCOUNT , e_USA_EAST, e_GREEN },
228/// { e_BUSINESS , e_USA_EAST, e_GREEN },
229/// { e_IMPULSE , e_MEXICO , e_TOAST },
230/// { e_DISCOUNT , e_GERMANY , e_FAST },
231/// { e_INSTITUTE , e_FRANCE , e_FAST },
232/// { e_NON_PROFIT, e_ENGLAND , e_PEARL },
233/// { e_BUSINESS , e_ENGLAND , e_TIDY },
234/// { e_BUSINESS , e_CANADA , e_GREEN },
235/// { e_INSTITUTE , e_FRANCE , e_FAST },
236/// { e_IMPULSE , e_RUSSIA , e_TOAST },
237/// { e_REPEAT , e_USA_WEST, e_TOAST },
238/// { e_IMPULSE , e_CANADA , e_TIDY },
239/// { e_NON_PROFIT, e_GERMANY , e_GREEN },
240/// { e_INSTITUTE , e_USA_EAST, e_TOAST },
241/// { e_INSTITUTE , e_FRANCE , e_FAST },
242/// { e_IMPULSE , e_SCOTLAND, e_SMITH },
243/// { e_INSTITUTE , e_USA_EAST, e_PEARL },
244/// { e_INSTITUTE , e_USA_EAST, e_TOAST },
245/// { e_NON_PROFIT, e_ENGLAND , e_PEARL },
246/// { e_IMPULSE , e_GERMANY , e_FAST },
247/// { e_REPEAT , e_GERMANY , e_FAST },
248/// { e_REPEAT , e_MEXICO , e_PEARL },
249/// { e_IMPULSE , e_GERMANY , e_TIDY },
250/// { e_IMPULSE , e_MEXICO , e_TOAST },
251/// { e_NON_PROFIT, e_SCOTLAND, e_SMITH },
252/// { e_NEED_BASED, e_MEXICO , e_TOAST },
253/// { e_NON_PROFIT, e_FRANCE , e_SMITH },
254/// { e_INSTITUTE , e_MEXICO , e_TIDY },
255/// { e_NON_PROFIT, e_FRANCE , e_TIDY },
256/// { e_IMPULSE , e_FRANCE , e_FAST },
257/// { e_DISCOUNT , e_RUSSIA , e_TIDY },
258/// { e_IMPULSE , e_USA_EAST, e_TIDY },
259/// { e_IMPULSE , e_USA_WEST, e_FAST },
260/// { e_NON_PROFIT, e_FRANCE , e_TIDY },
261/// { e_BUSINESS , e_ENGLAND , e_GREEN },
262/// { e_REPEAT , e_FRANCE , e_TOAST },
263/// { e_REPEAT , e_RUSSIA , e_SMITH },
264/// { e_REPEAT , e_RUSSIA , e_GREEN },
265/// { e_IMPULSE , e_CANADA , e_FAST },
266/// { e_NON_PROFIT, e_USA_EAST, e_FAST },
267/// { e_NEED_BASED, e_USA_WEST, e_TOAST },
268/// { e_NON_PROFIT, e_GERMANY , e_TIDY },
269/// { e_NON_PROFIT, e_ENGLAND , e_GREEN },
270/// { e_REPEAT , e_GERMANY , e_PEARL },
271/// { e_NEED_BASED, e_USA_EAST, e_PEARL },
272/// { e_NON_PROFIT, e_RUSSIA , e_PEARL },
273/// { e_NEED_BASED, e_ENGLAND , e_SMITH },
274/// { e_INSTITUTE , e_CANADA , e_SMITH },
275/// { e_NEED_BASED, e_ENGLAND , e_TOAST },
276/// { e_NON_PROFIT, e_MEXICO , e_TIDY },
277/// { e_BUSINESS , e_GERMANY , e_FAST },
278/// { e_NEED_BASED, e_SCOTLAND, e_PEARL },
279/// { e_NON_PROFIT, e_USA_WEST, e_TIDY },
280/// { e_NON_PROFIT, e_USA_WEST, e_TOAST },
281/// { e_IMPULSE , e_FRANCE , e_PEARL },
282/// { e_IMPULSE , e_ENGLAND , e_FAST },
283/// { e_IMPULSE , e_USA_WEST, e_GREEN },
284/// { e_DISCOUNT , e_MEXICO , e_SMITH },
285/// { e_INSTITUTE , e_GERMANY , e_TOAST },
286/// { e_NEED_BASED, e_CANADA , e_PEARL },
287/// { e_NON_PROFIT, e_USA_WEST, e_FAST },
288/// { e_DISCOUNT , e_RUSSIA , e_SMITH },
289/// { e_INSTITUTE , e_USA_WEST, e_GREEN },
290/// { e_INSTITUTE , e_RUSSIA , e_TOAST },
291/// { e_INSTITUTE , e_FRANCE , e_SMITH },
292/// { e_INSTITUTE , e_SCOTLAND, e_SMITH },
293/// { e_NON_PROFIT, e_ENGLAND , e_PEARL },
294/// { e_NON_PROFIT, e_CANADA , e_SMITH },
295/// { e_NON_PROFIT, e_USA_EAST, e_TOAST },
296/// { e_REPEAT , e_FRANCE , e_TOAST },
297/// { e_NEED_BASED, e_FRANCE , e_FAST },
298/// { e_DISCOUNT , e_MEXICO , e_TOAST },
299/// { e_DISCOUNT , e_FRANCE , e_GREEN },
300/// { e_IMPULSE , e_USA_EAST, e_FAST },
301/// { e_REPEAT , e_USA_EAST, e_GREEN },
302/// { e_NON_PROFIT, e_GERMANY , e_GREEN },
303/// { e_INSTITUTE , e_CANADA , e_SMITH },
304/// { e_NEED_BASED, e_SCOTLAND, e_TOAST },
305/// { e_NEED_BASED, e_GERMANY , e_FAST },
306/// { e_NON_PROFIT, e_RUSSIA , e_TOAST },
307/// { e_BUSINESS , e_ENGLAND , e_PEARL },
308/// { e_NEED_BASED, e_USA_EAST, e_TOAST },
309/// { e_INSTITUTE , e_USA_EAST, e_SMITH },
310/// { e_DISCOUNT , e_USA_EAST, e_PEARL },
311/// { e_REPEAT , e_SCOTLAND, e_FAST },
312/// { e_IMPULSE , e_GERMANY , e_TIDY },
313/// { e_DISCOUNT , e_CANADA , e_TIDY },
314/// { e_IMPULSE , e_USA_EAST, e_TIDY },
315/// { e_IMPULSE , e_GERMANY , e_TIDY },
316/// { e_NON_PROFIT, e_ENGLAND , e_FAST },
317/// { e_NON_PROFIT, e_USA_WEST, e_TIDY },
318/// { e_REPEAT , e_MEXICO , e_TOAST },
319/// };
320/// const bsl::size_t numCustomerProfiles = sizeof customerProfiles
321/// / sizeof *customerProfiles;
322/// @endcode
323/// Suppose, as the first step in our analysis, we wish to determine the number
324/// of unique combinations of customer attributes that exist in our data set.
325/// We can do that by inserting each data item into a flat hash set: the first
326/// insert of a combination will succeed, the others will fail, but at the end
327/// of the process, the set will contain one entry for every unique combination
328/// in our data.
329///
330/// First, as there are no standard methods for hashing or comparing our
331/// user-defined types, we define `CustomerProfileHash` and
332/// `CustomerProfileEqual` classes, each a stateless functor. Note that there
333/// is no meaningful ordering of the attribute values, they are merely arbitrary
334/// code numbers; nothing is lost by using an unordered set instead of an
335/// ordered set:
336/// @code
337/// class CustomerProfileHash {
338/// public:
339/// // CREATORS
340///
341///
342/// /// Create a `CustomerProfileHash` object.
343/// //! CustomerProfileHash() = default;
344///
345/// /// Create a `CustomerProfileHash` object. Note that as
346/// /// `CustomerProfileHash` is an empty (stateless) type, this
347/// /// operation has no observable effect.
348/// //! CustomerProfileHash(const CustomerProfileHash& original) = default;
349///
350/// /// Destroy this object.
351/// //! ~CustomerProfileHash() = default;
352///
353/// // ACCESSORS
354///
355/// /// Return a hash value for the specified `x`.
356/// bsl::size_t operator()(const CustomerProfile& x) const;
357/// };
358/// @endcode
359/// The hash function combines the several enumerated values from the class
360/// (each a small `int` value) into a single, unique `int` value, and then
361/// applies the default hash function for `int`.
362/// @code
363/// // ACCESSORS
364/// bsl::size_t CustomerProfileHash::operator()(const CustomerProfile& x) const
365/// {
366/// return bsl::hash<int>()( x.d_location * 100 * 100
367/// + x.d_customer * 100
368/// + x.d_project);
369/// }
370///
371/// class CustomerProfileEqual {
372/// public:
373/// // CREATORS
374///
375/// /// Create a `CustomerProfileEqual` object.
376/// //! CustomerProfileEqual() = default;
377///
378/// /// Create a `CustomerProfileEqual` object. Note that as
379/// /// `CustomerProfileEqual` is an empty (stateless) type, this
380/// /// operation has no observable effect.
381/// //! CustomerProfileEqual(const CustomerProfileEqual& original)
382/// //! = default;
383///
384/// /// Destroy this object.
385/// //! ~CustomerProfileEqual() = default;
386///
387/// // ACCESSORS
388///
389/// /// Return `true` if the specified `lhs` has the same value as the
390/// /// specified `rhs`, and `false` otherwise.
391/// bool operator()(const CustomerProfile& lhs,
392/// const CustomerProfile& rhs) const;
393/// };
394///
395/// // ACCESSORS
396/// bool CustomerProfileEqual::operator()(const CustomerProfile& lhs,
397/// const CustomerProfile& rhs) const
398/// {
399/// return lhs.d_location == rhs.d_location
400/// && lhs.d_customer == rhs.d_customer
401/// && lhs.d_project == rhs.d_project;
402/// }
403/// @endcode
404/// Notice that many of the required methods of the hash and comparator types
405/// are compiler generated. (The declarations of those methods are commented
406/// out and suffixed by an `= default` comment.)
407///
408/// Then, we define the type of the flat hash set:
409/// @code
410/// typedef bdlc::FlatHashSet<CustomerProfile,
411/// CustomerProfileHash,
412/// CustomerProfileEqual> ProfileCategories;
413/// @endcode
414/// Next, we create a flat hash set and insert each item of `customerProfiles`:
415/// @code
416/// bslma::TestAllocator oa("object", veryVeryVeryVerbose);
417///
418/// ProfileCategories profileCategories(&oa);
419///
420/// for (bsl::size_t idx = 0; idx < numCustomerProfiles; ++idx) {
421/// profileCategories.insert(customerProfiles[idx]);
422/// }
423///
424/// assert(numCustomerProfiles >= profileCategories.size());
425/// @endcode
426/// Notice that we ignore the status returned by the `insert` method. We fully
427/// expect some operations to fail.
428///
429/// Finally, the size of `profileCategories` matches the number of unique
430/// customer profiles in this data set:
431/// @code
432/// if (verbose) {
433/// bsl::cout << numCustomerProfiles << ' ' << profileCategories.size()
434/// << bsl::endl;
435/// }
436/// @endcode
437/// Standard output shows:
438/// @code
439/// 100 84
440/// @endcode
441/// @}
442/** @} */
443/** @} */
444
445/** @addtogroup bdl
446 * @{
447 */
448/** @addtogroup bdlc
449 * @{
450 */
451/** @addtogroup bdlc_flathashset
452 * @{
453 */
454
455#include <bdlscm_version.h>
456
457#include <bdlc_flathashtable.h>
458
460#include <bslalg_swaputil.h>
461
463
464#include <bslim_printer.h>
465
466#include <bslma_allocator.h>
469
470#include <bslmf_enableif.h>
471#include <bslmf_isconvertible.h>
473#include <bslmf_movableref.h>
474#include <bslmf_util.h> // 'forward(V)'
475
476#include <bsls_assert.h>
478#include <bsls_platform.h>
479#include <bsls_util.h> // 'forward<T>(V)'
480
481#include <bslstl_equalto.h>
482#include <bslstl_hash.h>
483
484#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
485#include <bsl_initializer_list.h>
486#endif
487#include <bsl_cstddef.h>
488#include <bsl_ostream.h>
489#include <bsl_utility.h>
490
491#if BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
492// clang-format off
493// Include version that can be compiled with C++03
494// Generated on Mon Jan 13 08:32:17 2025
495// Command line: sim_cpp11_features.pl bdlc_flathashset.h
496
497# define COMPILING_BDLC_FLATHASHSET_H
498# include <bdlc_flathashset_cpp03.h>
499# undef COMPILING_BDLC_FLATHASHSET_H
500
501// clang-format on
502#else
503
504
505namespace bdlc {
506
507// FORWARD DECLARATIONS
508template <class KEY,
510 class EQUAL = bsl::equal_to<KEY> >
511class FlatHashSet;
512
513template <class KEY, class HASH, class EQUAL>
514bool operator==(const FlatHashSet<KEY, HASH, EQUAL> &a,
516
517template <class KEY, class HASH, class EQUAL>
518bool operator!=(const FlatHashSet<KEY, HASH, EQUAL> &a,
520
521template <class KEY, class HASH, class EQUAL>
523
524 // ============================
525 // struct FlatHashSet_EntryUtil
526 // ============================
527
528/// This templated utility provides methods to construct an `ENTRY` and a
529/// method to extract the key from an `ENTRY` (which is, identically, the
530/// `ENTRY`).
531template <class ENTRY>
533{
534 // CLASS METHODS
535#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
536 /// Load into the specified `entry` the `ENTRY` value constructed from
537 /// specified `args`, using the specified `allocator` to supply memory.
538 /// `allocator` is ignored if the (template parameter) type `ENTRY` is
539 /// not allocator aware.
540 template <class... ARGS>
541 static void construct(
542 ENTRY *entry,
543 bslma::Allocator *allocator,
544 ARGS&&... args);
545#endif
546
547 /// Load into the specified `entry` the `ENTRY` value comprised of the
548 /// specified `key`, using the specified `allocator` to supply memory.
549 /// `allocator` is ignored if the (template parameter) type `ENTRY` is
550 /// not allocator aware.
551 template <class KEY_TYPE>
552 static void constructFromKey(
553 ENTRY *entry,
554 bslma::Allocator *allocator,
556
557 /// Return the specified `entry`.
558 static const ENTRY& key(const ENTRY& entry);
559};
560
561 // =================
562 // class FlatHashSet
563 // =================
564
565/// This class template implements a value-semantic container type holding
566/// an unordered set of unique values of (template parameter) type `KEY`.
567/// The (template parameter) type `HASH` is a functor providing the hash
568/// value for `KEY`. The (template parameter) type `EQUAL` is a functor
569/// providing the equality function for two `KEY` values. See {Requirements
570/// on `KEY`, `HASH`, and `EQUAL`} for more information.
571///
572/// See @ref bdlc_flathashset
573template <class KEY, class HASH, class EQUAL>
575
576 private:
577 // PRIVATE TYPES
578
579 /// This is the underlying implementation class.
580 typedef FlatHashTable<KEY,
581 KEY,
583 HASH,
584 EQUAL> ImplType;
585
586 // FRIENDS
587 friend bool operator==<>(const FlatHashSet&, const FlatHashSet&);
588 friend bool operator!=<>(const FlatHashSet&, const FlatHashSet&);
589
590 // The following verbose declaration is required by the xlC 12.1 compiler.
591 template <class K, class H, class E>
593
594 public:
595 // PUBLIC TYPES
596 typedef KEY key_type;
597 typedef KEY value_type;
598 typedef bsl::size_t size_type;
599 typedef bsl::ptrdiff_t difference_type;
600 typedef EQUAL key_compare;
601 typedef EQUAL value_compare;
602 typedef HASH hasher;
606 typedef const value_type* const_pointer;
609
610 private:
611 // DATA
612 ImplType d_impl; // underlying flat hash table used by this flat hash set
613
614 public:
615 // CREATORS
616
617 /// Create an empty `FlatHashSet` object. Optionally specify a
618 /// `capacity` indicating the minimum initial size of the underlying
619 /// array of entries of this container. If `capacity` is not supplied
620 /// or is 0, no memory is allocated. Optionally specify a `hash`
621 /// functor used to generate the hash values associated with the
622 /// elements in this container. If `hash` is not supplied, a
623 /// default-constructed object of the (template parameter) type `HASH`
624 /// is used. Optionally specify an equality functor `equal` used to
625 /// determine whether two elements are equivalent. If `equal` is not
626 /// supplied, a default-constructed object of the (template parameter)
627 /// type `EQUAL` is used. Optionally specify a `basicAllocator` used to
628 /// supply memory. If `basicAllocator` is not supplied or is 0, the
629 /// currently installed default allocator is used.
630 FlatHashSet();
631 explicit FlatHashSet(bslma::Allocator *basicAllocator);
632 explicit FlatHashSet(bsl::size_t capacity);
633 FlatHashSet(bsl::size_t capacity, bslma::Allocator *basicAllocator);
634 FlatHashSet(bsl::size_t capacity,
635 const HASH& hash,
636 bslma::Allocator *basicAllocator = 0);
637 FlatHashSet(bsl::size_t capacity,
638 const HASH& hash,
639 const EQUAL& equal,
640 bslma::Allocator *basicAllocator = 0);
641
642 /// Create a `FlatHashSet` object initialized by insertion of the values
643 /// from the input iterator range specified by `first` through `last`
644 /// (including `first`, excluding `last`). Optionally specify a
645 /// `capacity` indicating the minimum initial size of the underlying
646 /// array of entries of this container. If `capacity` is not supplied
647 /// or is 0, no memory is allocated. Optionally specify a `hash`
648 /// functor used to generate hash values associated with the elements in
649 /// this container. If `hash` is not supplied, a default-constructed
650 /// object of the (template parameter) type `HASH` is used. Optionally
651 /// specify an equality functor `equal` used to verify that two elements
652 /// are equivalent. If `equal` is not supplied, a default-constructed
653 /// object of the (template parameter) type `EQUAL` is used. Optionally
654 /// specify a `basicAllocator` used to supply memory. If
655 /// `basicAllocator` is not supplied or is 0, the currently installed default allocator is used.
656 ///
657 /// \pre The behavior is undefined unless `first`
658 /// and `last` refer to a sequence of valid values where `first` is at a position at or before `last`.
659 ///
660 /// \note Note that if a member of the input
661 /// sequence is equivalent to an earlier member, the later member will
662 /// not be inserted.
663 template <class INPUT_ITERATOR>
664 FlatHashSet(INPUT_ITERATOR first,
665 INPUT_ITERATOR last,
666 bslma::Allocator *basicAllocator = 0);
667 template <class INPUT_ITERATOR>
668 FlatHashSet(INPUT_ITERATOR first,
669 INPUT_ITERATOR last,
670 bsl::size_t capacity,
671 bslma::Allocator *basicAllocator = 0);
672 template <class INPUT_ITERATOR>
673 FlatHashSet(INPUT_ITERATOR first,
674 INPUT_ITERATOR last,
675 bsl::size_t capacity,
676 const HASH& hash,
677 bslma::Allocator *basicAllocator = 0);
678 template <class INPUT_ITERATOR>
679 FlatHashSet(INPUT_ITERATOR first,
680 INPUT_ITERATOR last,
681 bsl::size_t capacity,
682 const HASH& hash,
683 const EQUAL& equal,
684 bslma::Allocator *basicAllocator = 0);
685
686#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
687 /// Create a `FlatHashSet` object initialized by insertion of the
688 /// specified `values`. Optionally specify a `capacity` indicating the
689 /// minimum initial size of the underlying array of entries of this
690 /// container. If `capacity` is not supplied or is 0, no memory is
691 /// allocated. Optionally specify a `hash` functor used to generate
692 /// hash values associated with the elements in this container. If
693 /// `hash` is not supplied, a default-constructed object of the
694 /// (template parameter) type `HASH` is used. Optionally specify an
695 /// equality functor `equal` used to verify that two elements are
696 /// equivalent. If `equal` is not supplied, a default-constructed
697 /// object of the (template parameter) type `EQUAL` is used. Optionally
698 /// specify a `basicAllocator` used to supply memory. If
699 /// `basicAllocator` is not supplied or is 0, the currently installed default allocator is used.
700 ///
701 /// \note Note that if a member of `values` has a
702 /// key equivalent to an earlier member, the later member will not be
703 /// inserted.
704 FlatHashSet(bsl::initializer_list<KEY> values,
705 bslma::Allocator *basicAllocator = 0);
706 FlatHashSet(bsl::initializer_list<KEY> values,
707 bsl::size_t capacity,
708 bslma::Allocator *basicAllocator = 0);
709 FlatHashSet(bsl::initializer_list<KEY> values,
710 bsl::size_t capacity,
711 const HASH& hash,
712 bslma::Allocator *basicAllocator = 0);
713 FlatHashSet(bsl::initializer_list<KEY> values,
714 bsl::size_t capacity,
715 const HASH& hash,
716 const EQUAL& equal,
717 bslma::Allocator *basicAllocator = 0);
718#endif
719
720 /// Create a `FlatHashSet` object having the same value, hasher, and
721 /// equality comparator as the specified `original` object. Optionally
722 /// specify a `basicAllocator` used to supply memory. If
723 /// `basicAllocator` is not specified or is 0, the currently installed
724 /// default allocator is used.
725 FlatHashSet(const FlatHashSet& original,
726 bslma::Allocator *basicAllocator = 0);
727
728 /// Create a `FlatHashSet` object having the same value, hasher,
729 /// equality comparator, and allocator as the specified `original`
730 /// object. The contents of `original` are moved (in constant time) to
731 /// this object, `original` is left in a (valid) unspecified state, and
732 /// no exceptions will be thrown.
734
735 /// Create a `FlatHashSet` object having the same value, hasher, and
736 /// equality comparator as the specified `original` object, using the
737 /// specified `basicAllocator` to supply memory. If `basicAllocator` is
738 /// 0, the currently installed default allocator is used. The allocator
739 /// of `original` remains unchanged. If `original` and the newly
740 /// created object have the same allocator then the contents of
741 /// `original` are moved (in constant time) to this object, `original`
742 /// is left in a (valid) unspecified state, and no exceptions will be
743 /// thrown; otherwise `original` is unchanged (and an exception may be
744 /// thrown).
746 bslma::Allocator *basicAllocator);
747
748 /// Destroy this object and each of its elements.
749 ~FlatHashSet();
750
751 // MANIPULATORS
752
753 /// Assign to this object the value, hasher, and equality functor of the
754 /// specified `rhs` object, and return a reference providing modifiable
755 /// access to this object.
756 FlatHashSet& operator=(const FlatHashSet& rhs);
757
758 /// Assign to this object the value, hasher, and equality comparator of
759 /// the specified `rhs` object, and return a reference providing
760 /// modifiable access to this object. If this object and `rhs` use the
761 /// same allocator the contents of `rhs` are moved (in constant time) to
762 /// this object. `rhs` is left in a (valid) unspecified state.
764
765#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
766 /// Assign to this object the value resulting from first clearing this
767 /// set and then inserting each object in the specified `values`
768 /// initializer list, ignoring those objects having a value equivalent
769 /// to that which appears earlier in the list; return a reference
770 /// providing modifiable access to this object. This method requires
771 /// that the (template parameter) type `KEY` be `copy-insertable` into
772 /// this set (see {Requirements on `KEY`, `HASH`, and `EQUAL`}).
773 FlatHashSet& operator=(bsl::initializer_list<KEY> values);
774#endif
775
776 /// Remove all elements from this set.
777 /// \note Note that this set will be empty
778 /// after calling this method, but allocated memory may be retained for
779 /// future use. See the `capacity` method.
780 void clear();
781
782#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
783 /// Insert into this set a newly created `value_type` object,
784 /// constructed by forwarding `get_allocator()` (if required) and the
785 /// specified (variable number of) `args` to the corresponding
786 /// constructor of `value_type`, if a key equivalent to such a value
787 /// does not already exist in this set; otherwise, this method has no
788 /// effect (other than possibly creating a temporary `value_type`
789 /// object). Return a pair whose `first` member is an iterator
790 /// referring to the (possibly newly created and inserted) object in
791 /// this set whose value is equivalent to that of an object constructed
792 /// from `arguments`, and whose `second` member is `true` if a new value
793 /// was inserted, and `false` if an equivalent key was already present.
794 template <class... ARGS>
796
797 /// Insert into this set a newly created `value_type` object,
798 /// constructed by forwarding `get_allocator()` (if required) and the
799 /// specified (variable number of) `args` to the corresponding
800 /// constructor of `value_type`, if a key equivalent to such a value
801 /// does not already exists in this set; otherwise, this method has no
802 /// effect (other than possibly creating a temporary `value_type`
803 /// object). Return an iterator referring to the (possibly newly
804 /// created and inserted) object in this set whose value is equivalent
805 /// to that of an object constructed from `arguments`. The average and
806 /// worst case complexity of this operation is not affected by the specified `hint`.
807 ///
808 /// \note Note that `hint` is ignored (other than possibly
809 /// asserting its validity in some build modes).
810 template <class... ARGS>
811 iterator emplace_hint(const_iterator hint, ARGS&&... args);
812#endif
813
814 /// Remove from this set the element whose key is equal to the specified
815 /// `key`, if it exists, and return 1; otherwise (there is no element
816 /// having `key` in this set), return 0 with no other effect. This
817 /// method invalidates all iterators and references to the removed
818 /// element.
819 bsl::size_t erase(const KEY& key);
820
821#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
822 /// Remove from this set the element whose key is equivalent to the
823 /// specified `key`, if it exists, and return 1; otherwise (there is no
824 /// element equivalent to `key` in this set), return 0 with no other effect.
825 /// This method invalidates all iterators and references to the removed
826 /// element.
827 template <class LOOKUP_KEY>
828 typename bsl::enable_if<
829 BloombergLP::bslmf::IsTransparentPredicate<HASH, LOOKUP_KEY>::value
830 && BloombergLP::bslmf::IsTransparentPredicate<EQUAL,LOOKUP_KEY>::value
831 , bsl::size_t>::type
832 erase(LOOKUP_KEY&& key)
833 {
834 return d_impl.erase(key);
835 }
836#endif
837
838 /// Remove from this set the element at the specified `position`, and
839 /// return a `const_iterator` referring to the element immediately
840 /// following the removed element, or to the past-the-end position if
841 /// the removed element was the last element in the sequence of elements
842 /// maintained by this set. This method invalidates all iterators and references to the removed element.
843 ///
844 /// \pre The behavior is undefined unless
845 /// `position` refers to an element in this set.
847
848 /// Remove from this set the elements starting at the specified `first`
849 /// position up to, but not including, the specified `last` position,
850 /// and return `last`. This method invalidates all iterators and
851 /// references to the removed elements.
852 ///
853 /// \pre The behavior is undefined unless `first` and `last` are valid iterators on this set, and the
854 /// `first` position is at or before the `last` position in the
855 /// iteration sequence provided by this container.
857
858 /// Insert the specified `value` into this set if the `value` does not
859 /// already exist in this set; otherwise, this method has no effect.
860 /// Return a `pair` whose `first` member is a `const_iterator` referring
861 /// to the (possibly newly inserted) element in this set whose value is
862 /// equivalent to that of the element to be inserted, and whose `second`
863 /// member is `true` if a new element was inserted, and `false` if an
864 /// equivalent value was already present.
866 {
867 // Note that some compilers require functions declared with 'enable_if'
868 // to be defined inline.
869
870 return d_impl.insert(value);
871 }
872
873 /// Insert the specified `value` into this set if the `value` does not
874 /// already exist in this set; otherwise, this method has no effect.
875 /// Return a `pair` whose `first` member is a `const_iterator` referring
876 /// to the (possibly newly inserted) element in this set whose value is
877 /// equivalent to that of the element to be inserted, and whose `second`
878 /// member is `true` if a new element was inserted, and `false` if an
879 /// equivalent value was already present.
881 {
882 // Note that some compilers require functions declared with 'enable_if'
883 // to be defined inline.
884
885 return d_impl.insert(BSLS_COMPILERFEATURES_FORWARD(KEY, value));
886 }
887
888#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
889 /// Insert the specified `key` into this set if a key equivalent to `k`
890 /// does not already exist in this set; otherwise, this method has no effect.
891 /// Return a pair containing an `iterator` referring to the newly inserted
892 /// element and `true` if a element was inserted. Return a pair containing
893 /// an `iterator` to an existing element and `false` if the value already
894 /// existed in the set.
895 template <class LOOKUP_KEY>
896 typename bsl::enable_if<
897 BloombergLP::bslmf::IsTransparentPredicate<HASH, LOOKUP_KEY>::value
898 && BloombergLP::bslmf::IsTransparentPredicate<EQUAL,LOOKUP_KEY>::value
899 , typename bsl::pair<iterator, bool> >::type
900 insert(LOOKUP_KEY&& key)
901 {
902 return d_impl.insertTransparent(
903 BSLS_COMPILERFEATURES_FORWARD(LOOKUP_KEY, key));
904 }
905#endif
906
907 /// Insert the specified `value` into this set if the `value` does not
908 /// already exist in this set; otherwise, this method has no effect.
909 /// Return a `const_iterator` referring to the (possibly newly inserted)
910 /// element in this set whose value is equivalent to that of the
911 /// element to be inserted. The supplied `const_iterator` is ignored.
913 {
914 // Note that some compilers require functions declared with 'enable_if'
915 // to be defined inline.
916
917 return d_impl.insert(value).first;
918 }
919
920
921 /// Insert the specified `value` into this set if the `value` does not
922 /// already exist in this set; otherwise, this method has no effect.
923 /// Return a `const_iterator` referring to the (possibly newly inserted)
924 /// element in this set whose value is equivalent to that of the
925 /// element to be inserted. The supplied `const_iterator` is ignored.
927 {
928 // Note that some compilers require functions declared with 'enable_if'
929 // to be defined inline.
930
931 return d_impl.insert(BSLS_COMPILERFEATURES_FORWARD(KEY,value)).first;
932 }
933
934#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
935 /// Insert the specified `key` into this set if a key equivalent to `k`
936 /// does not already exist in this set; otherwise, this method has no effect.
937 /// Return a pair containing an `iterator` referring to the newly inserted
938 /// element and `true` if a element was inserted. Return a pair containing
939 /// an `iterator` to an existing element and `false` if the value already
940 /// existed in the set. The supplied `const_iterator` is ignored.
941 template <class LOOKUP_KEY>
942 typename bsl::enable_if<
943 BloombergLP::bslmf::IsTransparentPredicate<HASH, LOOKUP_KEY>::value
944 && BloombergLP::bslmf::IsTransparentPredicate<EQUAL,LOOKUP_KEY>::value
947 , iterator>::type
948 insert(const_iterator, LOOKUP_KEY&& key)
949 {
950 return insert(BSLS_COMPILERFEATURES_FORWARD(LOOKUP_KEY, key)).first;
951 }
952#endif
953
954 /// Insert into this set the value of each element in the input iterator
955 /// range specified by `first` through `last` (including `first`, excluding `last`).
956 ///
957 /// \pre The behavior is undefined unless `first` and
958 /// `last` refer to a sequence of valid values where `first` is at a position at or before `last`.
959 ///
960 /// \note Note that if a member of the input
961 /// sequence is equivalent to an earlier member, the later member will
962 /// not be inserted.
963 template <class INPUT_ITERATOR>
964 void insert(INPUT_ITERATOR first, INPUT_ITERATOR last);
965
966#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
967 /// Insert into this set an element having the value of each object in
968 /// the specified `values` initializer list if an equivalent value is
969 /// not already contained in this set. This method requires that the
970 /// (template parameter) type `KEY` be copy-insertable (see
971 /// {Requirements on `KEY`, `HASH`, and `EQUAL`}).
972 void insert(bsl::initializer_list<KEY> values);
973#endif
974
975 /// Change the capacity of this set to at least the specified
976 /// `minimumCapacity`, and redistribute all the contained elements into
977 /// a new sequence of entries according to their hash values. If
978 /// `0 == minimumCapacity` and `0 == size()`, the set is returned to the
979 /// default constructed state. After this call, `load_factor()` will be
980 /// less than or equal to `max_load_factor()` and all iterators,
981 /// pointers, and references to elements of this set are invalidated.
982 void rehash(bsl::size_t minimumCapacity);
983
984 /// Change the capacity of this set to at least a capacity that can
985 /// accommodate the specified `numEntries` (accounting for the load
986 /// factor invariant), and redistribute all the contained elements into
987 /// a new sequence of entries according to their hash values. If
988 /// `0 == numEntries` and `0 == size()`, the set is returned to the
989 /// default constructed state. After this call, `load_factor()` will be
990 /// less than or equal to `max_load_factor()` and all iterators,
991 /// pointers, and references to elements of this set are invalidated.
992 ///
993 /// \note Note that this method is effectively equivalent to:
994 /// @code
995 /// rehash(bsl::ceil(numEntries / max_load_factor()))
996 /// @endcode
997 void reserve(bsl::size_t numEntries);
998
999 /// Remove all elements from this set and release all memory from this
1000 /// set, returning the set to the default constructed state.
1001 void reset();
1002
1003 // Aspects
1004
1005 /// Exchange the value of this object as well as its hasher and equality
1006 /// functors with those of the specified `other` object.
1007 ///
1008 /// \pre The behavior is undefined unless this object was created with the same allocator
1009 /// as `other`.
1010 void swap(FlatHashSet& other);
1011
1012 // ACCESSORS
1013
1014 /// Return the number of elements this set could hold if the load factor
1015 /// were 1.
1016 bsl::size_t capacity() const;
1017
1018 /// Return `true` if this set contains an element having the specified
1019 /// `key`, and `false` otherwise.
1020 bool contains(const KEY& key) const;
1021
1022 /// Return `true` if this set contains an element whose key is equivalent
1023 /// to the specified `key`.
1024 template <class LOOKUP_KEY>
1025 typename bsl::enable_if<
1026 BloombergLP::bslmf::IsTransparentPredicate<HASH, LOOKUP_KEY>::value
1027 && BloombergLP::bslmf::IsTransparentPredicate<EQUAL,LOOKUP_KEY>::value
1028 , bool>::type
1029 contains(const LOOKUP_KEY& key) const
1030 {
1031 // Note: implemented inline due to Sun CC compilation error.
1032
1033 return find(key) != end();
1034 }
1035
1036 /// Return the number of elements in this set having the specified `key`.
1037 ///
1038 /// \note Note that since a flat hash set maintains unique keys, the
1039 /// returned value will be either 0 or 1.
1040 bsl::size_t count(const KEY& key) const;
1041
1042 /// Return the number of `value_type` objects within this unordered set
1043 /// that are equivalent to the specified `key`.
1044 ///
1045 /// \pre The behavior is undefined unless `key` is equivalent to at most one element in this unordered set.
1046 ///
1047 /// \note Note that since an unordered set maintains unique
1048 /// keys, the returned value will be either 0 or 1.
1049 template <class LOOKUP_KEY>
1050 typename bsl::enable_if<
1051 BloombergLP::bslmf::IsTransparentPredicate<HASH, LOOKUP_KEY>::value
1052 && BloombergLP::bslmf::IsTransparentPredicate<EQUAL,LOOKUP_KEY>::value
1053 , bsl::size_t >::type
1054 count(const LOOKUP_KEY& key) const
1055 {
1056 // Note: implemented inline due to Sun CC compilation error.
1057
1058 return find(key) != end() ? 1 : 0;
1059 }
1060
1061 /// Return `true` if this set contains no elements, and `false`
1062 /// otherwise.
1063 bool empty() const;
1064
1065 /// Return a pair of `const_iterator`s defining the sequence of elements
1066 /// in this set having the specified `key`, where the first iterator is
1067 /// positioned at the start of the sequence and the second iterator is
1068 /// positioned one past the end of the sequence. If this set contains
1069 /// no `KEY` elements equivalent to `key`, then the two returned iterators will have the same value.
1070 ///
1071 /// \note Note that since a set maintains
1072 /// unique keys, the range will contain at most one element.
1074 const KEY& key) const;
1075
1076 /// Return a pair of `const_iterator` providing non-modifiable access to
1077 /// the sequence of `value_type` objects in this unordered set that are
1078 /// equivalent to the specified `key`, where the first iterator is
1079 /// positioned at the start of the sequence and the second iterator is
1080 /// positioned one past the end of the sequence. If this unordered set
1081 /// contains no `value_type` objects equivalent to `key`, then the two returned iterators will have the same value.
1082 ///
1083 /// \note Note that since an
1084 /// unordered set maintains unique keys, the range will contain at most one
1085 /// element.
1086 template <class LOOKUP_KEY>
1087 typename bsl::enable_if<
1088 BloombergLP::bslmf::IsTransparentPredicate<HASH, LOOKUP_KEY>::value
1089 && BloombergLP::bslmf::IsTransparentPredicate<EQUAL,LOOKUP_KEY>::value
1091 equal_range(const LOOKUP_KEY& key) const
1092 {
1093 // Note: implemented inline due to Sun CC compilation error.
1094
1095 return d_impl.equal_range(key);
1096 }
1097
1098 /// Return a `const_iterator` referring to the element in this set
1099 /// having the specified `key`, or `end()` if no such entry exists in
1100 /// this set.
1101 const_iterator find(const KEY& key) const;
1102
1103 /// Return a `const_iterator` referring to the element in this set
1104 /// having the specified `key`, or `end()` if no such entry exists in
1105 /// this set.
1106 template <class LOOKUP_KEY>
1107 typename bsl::enable_if<
1108 BloombergLP::bslmf::IsTransparentPredicate<HASH, LOOKUP_KEY>::value
1109 && BloombergLP::bslmf::IsTransparentPredicate<EQUAL,LOOKUP_KEY>::value
1110 , const_iterator>::type
1111 find(const LOOKUP_KEY& key) const
1112 {
1113 // Note: implemented inline due to Sun CC compilation error.
1114
1115 return iterator(d_impl.find(key));
1116 }
1117
1118
1119 /// Return (a copy of) the unary hash functor used by this set to
1120 /// generate a hash value (of type `bsl::size_t`) for a `KEY` object.
1121 HASH hash_function() const;
1122
1123 /// Return (a copy of) the binary key-equality functor that returns
1124 /// `true` if the value of two `KEY` objects are equivalent, and `false`
1125 /// otherwise.
1126 EQUAL key_eq() const;
1127
1128 /// Return the current ratio between the number of elements in this
1129 /// container and its capacity.
1130 float load_factor() const;
1131
1132 /// Return the maximum load factor allowed for this set.
1133 /// \note Note that if
1134 /// an insert operation would cause the load factor to exceed
1135 /// `max_load_factor()`, that same insert operation will increase the
1136 /// capacity and rehash the entries of the container (see {Load Factor
1137 /// and Resizing}). Also note that the value returned by
1138 /// @ref max_load_factor is implementation defined and cannot be changed by
1139 /// the user.
1140 float max_load_factor() const;
1141
1142 /// Return the number of elements in this set.
1143 bsl::size_t size() const;
1144
1145 // Iterators
1146
1147 /// Return a `const_iterator` to the first element in the sequence of
1148 /// elements maintained by this set, or the `end` iterator if this set
1149 /// is empty.
1150 const_iterator begin() const;
1151
1152 /// Return a `const_iterator` to the first element in the sequence of
1153 /// elements maintained by this set, or the `end` iterator if this set
1154 /// is empty.
1155 const_iterator cbegin() const;
1156
1157 /// Return a `const_iterator` to the past-the-end element in the
1158 /// sequence of `KEY` elements maintained by this set.
1159 const_iterator cend() const;
1160
1161 /// Return a `const_iterator` to the past-the-end element in the
1162 /// sequence of `KEY` elements maintained by this set.
1163 const_iterator end() const;
1164
1165 // Aspects
1166
1167 /// Return the allocator used by this flat hash set to supply memory.
1168 bslma::Allocator *allocator() const;
1169
1170 /// Format this object to the specified output `stream` at the (absolute
1171 /// value of) the optionally specified indentation `level`, and return a
1172 /// reference to the modifiable `stream`. If `level` is specified,
1173 /// optionally specify `spacesPerLevel`, the number of spaces per
1174 /// indentation level for this and all of its nested objects. If
1175 /// `level` is negative, suppress indentation of the first line. If
1176 /// `spacesPerLevel` is negative, format the entire output on one line,
1177 /// suppressing all but the initial indentation (as governed by
1178 /// `level`). If `stream` is not valid on entry, this operation has no
1179 /// effect.
1180 bsl::ostream& print(bsl::ostream& stream,
1181 int level = 0,
1182 int spacesPerLevel = 4) const;
1183};
1184
1185// FREE OPERATORS
1186
1187/// Return `true` if the specified `lhs` and `rhs` objects have the same
1188/// value, and `false` otherwise. Two `FlatHashSet` objects have the same
1189/// value if their sizes are the same and each element contained in one is
1190/// equal to an element of the other. The hash and equality functors are
1191/// not involved in the comparison.
1192template <class KEY, class HASH, class EQUAL>
1193bool operator==(const FlatHashSet<KEY, HASH, EQUAL> &lhs,
1194 const FlatHashSet<KEY, HASH, EQUAL> &rhs);
1195
1196/// Return `true` if the specified `lhs` and `rhs` objects do not have the
1197/// same value, and `false` otherwise. Two `FlatHashSet` objects do not
1198/// have the same value if their sizes are different or one contains an
1199/// element equal to no element of the other. The hash and equality
1200/// functors are not involved in the comparison.
1201template <class KEY, class HASH, class EQUAL>
1202bool operator!=(const FlatHashSet<KEY, HASH, EQUAL> &lhs,
1203 const FlatHashSet<KEY, HASH, EQUAL> &rhs);
1204
1205/// Write the value of the specified `set` to the specified output `stream`
1206/// in a single-line format, and return a reference providing modifiable
1207/// access to `stream`. If `stream` is not valid on entry, this operation has no effect.
1208///
1209/// \note Note that this human-readable format is not fully
1210/// specified and can change without notice.
1211template <class KEY, class HASH, class EQUAL>
1212bsl::ostream& operator<<(bsl::ostream& stream,
1214
1215// FREE FUNCTIONS
1216
1217/// Exchange the value, the hasher, and the key-equality functor of the
1218/// specified `a` and `b` objects. This function provides the no-throw
1219/// exception-safety guarantee if the two objects were created with the same
1220/// allocator and the basic guarantee otherwise.
1221template <class KEY, class HASH, class EQUAL>
1223
1224// ============================================================================
1225// TEMPLATE AND INLINE FUNCTION DEFINITIONS
1226// ============================================================================
1227
1228 // ----------------------------
1229 // struct FlatHashSet_EntryUtil
1230 // ----------------------------
1231
1232// CLASS METHODS
1233#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
1234template <class ENTRY>
1235template <class... ARGS>
1236inline
1238 ENTRY *entry,
1239 bslma::Allocator *allocator,
1240 ARGS&&... args)
1241{
1242 BSLS_ASSERT_SAFE(entry);
1244 entry,
1245 allocator,
1246 BSLS_COMPILERFEATURES_FORWARD(ARGS, args)...);
1247}
1248#endif
1249
1250template <class ENTRY>
1251template <class KEY>
1252inline
1254 ENTRY *entry,
1255 bslma::Allocator *allocator,
1257{
1258 BSLS_ASSERT_SAFE(entry);
1259
1261 entry,
1262 allocator,
1264}
1265
1266template <class ENTRY>
1267inline
1268const ENTRY& FlatHashSet_EntryUtil<ENTRY>::key(const ENTRY& entry)
1269{
1270 return entry;
1271}
1272
1273 // -----------------
1274 // class FlatHashSet
1275 // -----------------
1276
1277// CREATORS
1278template <class KEY, class HASH, class EQUAL>
1279inline
1281: d_impl(0, HASH(), EQUAL())
1282{
1283}
1284
1285template <class KEY, class HASH, class EQUAL>
1286inline
1288: d_impl(0, HASH(), EQUAL(), basicAllocator)
1289{
1290}
1291
1292template <class KEY, class HASH, class EQUAL>
1293inline
1295: d_impl(capacity, HASH(), EQUAL())
1296{
1297}
1298
1299template <class KEY, class HASH, class EQUAL>
1300inline
1302 bslma::Allocator *basicAllocator)
1303: d_impl(capacity, HASH(), EQUAL(), basicAllocator)
1304{
1305}
1306
1307template <class KEY, class HASH, class EQUAL>
1308inline
1310 const HASH& hash,
1311 bslma::Allocator *basicAllocator)
1312: d_impl(capacity, hash, EQUAL(), basicAllocator)
1313{
1314}
1315
1316template <class KEY, class HASH, class EQUAL>
1317inline
1319 const HASH& hash,
1320 const EQUAL& equal,
1321 bslma::Allocator *basicAllocator)
1322: d_impl(capacity, hash, equal, basicAllocator)
1323{
1324}
1325
1326template <class KEY, class HASH, class EQUAL>
1327template <class INPUT_ITERATOR>
1328inline
1330 INPUT_ITERATOR last,
1331 bslma::Allocator *basicAllocator)
1332: d_impl(0, HASH(), EQUAL(), basicAllocator)
1333{
1334 insert(first, last);
1335}
1336
1337template <class KEY, class HASH, class EQUAL>
1338template <class INPUT_ITERATOR>
1339inline
1341 INPUT_ITERATOR last,
1342 bsl::size_t capacity,
1343 bslma::Allocator *basicAllocator)
1344: d_impl(capacity, HASH(), EQUAL(), basicAllocator)
1345{
1346 insert(first, last);
1347}
1348
1349template <class KEY, class HASH, class EQUAL>
1350template <class INPUT_ITERATOR>
1351inline
1353 INPUT_ITERATOR last,
1354 bsl::size_t capacity,
1355 const HASH& hash,
1356 bslma::Allocator *basicAllocator)
1357: d_impl(capacity, hash, EQUAL(), basicAllocator)
1358{
1359 insert(first, last);
1360}
1361
1362template <class KEY, class HASH, class EQUAL>
1363template <class INPUT_ITERATOR>
1364inline
1366 INPUT_ITERATOR last,
1367 bsl::size_t capacity,
1368 const HASH& hash,
1369 const EQUAL& equal,
1370 bslma::Allocator *basicAllocator)
1371: d_impl(capacity, hash, equal, basicAllocator)
1372{
1373 insert(first, last);
1374}
1375
1376#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
1377template <class KEY, class HASH, class EQUAL>
1378inline
1380 bsl::initializer_list<KEY> values,
1381 bslma::Allocator *basicAllocator)
1382: FlatHashSet(values.begin(),
1383 values.end(),
1384 0,
1385 HASH(),
1386 EQUAL(),
1387 basicAllocator)
1388{
1389}
1390
1391template <class KEY, class HASH, class EQUAL>
1392inline
1394 bsl::initializer_list<KEY> values,
1395 bsl::size_t capacity,
1396 bslma::Allocator *basicAllocator)
1397: FlatHashSet(values.begin(),
1398 values.end(),
1399 capacity,
1400 HASH(),
1401 EQUAL(),
1402 basicAllocator)
1403{
1404}
1405
1406template <class KEY, class HASH, class EQUAL>
1407inline
1409 bsl::initializer_list<KEY> values,
1410 bsl::size_t capacity,
1411 const HASH& hash,
1412 bslma::Allocator *basicAllocator)
1413: FlatHashSet(values.begin(),
1414 values.end(),
1415 capacity,
1416 hash,
1417 EQUAL(),
1418 basicAllocator)
1419{
1420}
1421
1422template <class KEY, class HASH, class EQUAL>
1423inline
1425 bsl::initializer_list<KEY> values,
1426 bsl::size_t capacity,
1427 const HASH& hash,
1428 const EQUAL& equal,
1429 bslma::Allocator *basicAllocator)
1430: FlatHashSet(values.begin(),
1431 values.end(),
1432 capacity,
1433 hash,
1434 equal,
1435 basicAllocator)
1436{
1437}
1438#endif
1439
1440template <class KEY, class HASH, class EQUAL>
1441inline
1443 bslma::Allocator *basicAllocator)
1444: d_impl(original.d_impl, basicAllocator)
1445{
1446}
1447
1448template <class KEY, class HASH, class EQUAL>
1449inline
1452: d_impl(bslmf::MovableRefUtil::move(
1453 bslmf::MovableRefUtil::access(original).d_impl))
1454{
1455}
1456
1457template <class KEY, class HASH, class EQUAL>
1458inline
1461 bslma::Allocator *basicAllocator)
1462: d_impl(bslmf::MovableRefUtil::move(
1463 bslmf::MovableRefUtil::access(original).d_impl),
1464 basicAllocator)
1465{
1466}
1467
1468template <class KEY, class HASH, class EQUAL>
1469inline
1473
1474// MANIPULATORS
1475template <class KEY, class HASH, class EQUAL>
1476inline
1478 const FlatHashSet& rhs)
1479{
1480 d_impl = rhs.d_impl;
1481
1482 return *this;
1483}
1484
1485template <class KEY, class HASH, class EQUAL>
1486inline
1489{
1490 FlatHashSet& lvalue = rhs;
1491
1492 d_impl = bslmf::MovableRefUtil::move(lvalue.d_impl);
1493
1494 return *this;
1495}
1496
1497#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
1498template <class KEY, class HASH, class EQUAL>
1499inline
1501 bsl::initializer_list<KEY> values)
1502{
1503 FlatHashSet tmp(values.begin(),
1504 values.end(),
1505 0,
1506 d_impl.hash_function(),
1507 d_impl.key_eq(),
1508 d_impl.allocator());
1509
1510 this->swap(tmp);
1511
1512 return *this;
1513}
1514#endif
1515
1516template <class KEY, class HASH, class EQUAL>
1517inline
1519{
1520 d_impl.clear();
1521}
1522
1523#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
1524template <class KEY, class HASH, class EQUAL>
1525template <class... ARGS>
1528{
1529 return d_impl.emplace(BSLS_COMPILERFEATURES_FORWARD(ARGS, args)...);
1530}
1531
1532template <class KEY, class HASH, class EQUAL>
1533template <class... ARGS>
1537 ARGS&&... args)
1538{
1539 return this->emplace(BSLS_COMPILERFEATURES_FORWARD(ARGS, args)...).first;
1540}
1541
1542#endif
1543
1544
1545template <class KEY, class HASH, class EQUAL>
1546inline
1547bsl::size_t FlatHashSet<KEY, HASH, EQUAL>::erase(const KEY& key)
1548{
1549 return d_impl.erase(key);
1550}
1551
1552template <class KEY, class HASH, class EQUAL>
1553inline
1556{
1557 BSLS_ASSERT_SAFE(position != end());
1558
1559 return d_impl.erase(position);
1560}
1561
1562template <class KEY, class HASH, class EQUAL>
1563inline
1566{
1567 return d_impl.erase(first, last);
1568}
1569
1570template <class KEY, class HASH, class EQUAL>
1571template <class INPUT_ITERATOR>
1572inline
1574 INPUT_ITERATOR last)
1575{
1576 d_impl.insert(first, last);
1577}
1578
1579#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
1580template <class KEY, class HASH, class EQUAL>
1581inline
1582void FlatHashSet<KEY, HASH, EQUAL>::insert(bsl::initializer_list<KEY> values)
1583{
1584 insert(values.begin(), values.end());
1585}
1586#endif
1587
1588template <class KEY, class HASH, class EQUAL>
1589inline
1590void FlatHashSet<KEY, HASH, EQUAL>::rehash(bsl::size_t minimumCapacity)
1591{
1592 d_impl.rehash(minimumCapacity);
1593}
1594
1595template <class KEY, class HASH, class EQUAL>
1596inline
1597void FlatHashSet<KEY, HASH, EQUAL>::reserve(bsl::size_t numEntries)
1598{
1599 d_impl.reserve(numEntries);
1600}
1601
1602template <class KEY, class HASH, class EQUAL>
1603inline
1605{
1606 d_impl.reset();
1607}
1608
1609 // Aspects
1610
1611template <class KEY, class HASH, class EQUAL>
1612inline
1614{
1615 BSLS_ASSERT_SAFE(allocator() == other.allocator());
1616
1617 d_impl.swap(other.d_impl);
1618}
1619
1620// ACCESSORS
1621template <class KEY, class HASH, class EQUAL>
1622inline
1624{
1625 return d_impl.capacity();
1626}
1627
1628template <class KEY, class HASH, class EQUAL>
1629inline
1631{
1632 return d_impl.contains(key);
1633}
1634
1635template <class KEY, class HASH, class EQUAL>
1636inline
1637bsl::size_t FlatHashSet<KEY, HASH, EQUAL>::count(const KEY& key) const
1638{
1639 return d_impl.count(key);
1640}
1641
1642template <class KEY, class HASH, class EQUAL>
1643inline
1645{
1646 return d_impl.empty();
1647}
1648
1649template <class KEY, class HASH, class EQUAL>
1650inline
1654{
1655 return d_impl.equal_range(key);
1656}
1657
1658template <class KEY, class HASH, class EQUAL>
1659inline
1662{
1663 return d_impl.find(key);
1664}
1665
1666template <class KEY, class HASH, class EQUAL>
1667inline
1669{
1670 return d_impl.hash_function();
1671}
1672
1673template <class KEY, class HASH, class EQUAL>
1674inline
1676{
1677 return d_impl.key_eq();
1678}
1679
1680template <class KEY, class HASH, class EQUAL>
1681inline
1683{
1684 return d_impl.load_factor();
1685}
1686
1687template <class KEY, class HASH, class EQUAL>
1688inline
1690{
1691 return d_impl.max_load_factor();
1692}
1693
1694template <class KEY, class HASH, class EQUAL>
1695inline
1697{
1698 return d_impl.size();
1699}
1700
1701 // Iterators
1702
1703template <class KEY, class HASH, class EQUAL>
1704inline
1707{
1708 return d_impl.begin();
1709}
1710
1711template <class KEY, class HASH, class EQUAL>
1712inline
1715{
1716 return d_impl.cbegin();
1717}
1718
1719template <class KEY, class HASH, class EQUAL>
1720inline
1723{
1724 return d_impl.cend();
1725}
1726
1727template <class KEY, class HASH, class EQUAL>
1728inline
1731{
1732 return d_impl.end();
1733}
1734
1735 // Aspects
1736
1737template <class KEY, class HASH, class EQUAL>
1738inline
1740{
1741 return d_impl.allocator();
1742}
1743
1744template <class KEY, class HASH, class EQUAL>
1746 bsl::ostream& stream,
1747 int level,
1748 int spacesPerLevel) const
1749{
1750 if (stream.bad()) {
1751 return stream; // RETURN
1752 }
1753
1754 bslim::Printer printer(&stream, level, spacesPerLevel);
1755
1756 printer.start();
1757
1758 const_iterator iter = begin();
1759 while (iter != end()) {
1760 printer.printValue(*iter);
1761 ++iter;
1762 }
1763
1764 printer.end();
1765
1766 return stream;
1767}
1768
1769} // close package namespace
1770
1771// FREE OPERATORS
1772template <class KEY, class HASH, class EQUAL>
1773inline
1774bool bdlc::operator==(const FlatHashSet<KEY, HASH, EQUAL>& lhs,
1775 const FlatHashSet<KEY, HASH, EQUAL>& rhs)
1776{
1777 return lhs.d_impl == rhs.d_impl;
1778}
1779
1780template <class KEY, class HASH, class EQUAL>
1781inline
1782bool bdlc::operator!=(const FlatHashSet<KEY, HASH, EQUAL>& lhs,
1783 const FlatHashSet<KEY, HASH, EQUAL>& rhs)
1784{
1785 return lhs.d_impl != rhs.d_impl;
1786}
1787
1788template <class KEY, class HASH, class EQUAL>
1789inline
1790bsl::ostream& bdlc::operator<<(bsl::ostream& stream,
1791 const FlatHashSet<KEY, HASH, EQUAL>& set)
1792{
1793 return set.print(stream, 0, -1);
1794}
1795
1796// FREE FUNCTIONS
1797template <class KEY, class HASH, class EQUAL>
1798inline
1799void bdlc::swap(FlatHashSet<KEY, HASH, EQUAL>& a,
1800 FlatHashSet<KEY, HASH, EQUAL>& b)
1801{
1802 bslalg::SwapUtil::swap(&a.d_impl, &b.d_impl);
1803}
1804
1805// ============================================================================
1806// TYPE TRAITS
1807// ============================================================================
1808
1809namespace bslalg {
1810
1811template <class KEY, class HASH, class EQUAL>
1812struct HasStlIterators<bdlc::FlatHashSet<KEY, HASH, EQUAL> >
1814{};
1815
1816} // close namespace bslalg
1817
1818namespace bslma {
1819
1820template <class KEY, class HASH, class EQUAL>
1821struct UsesBslmaAllocator<bdlc::FlatHashSet<KEY, HASH, EQUAL> >
1823{};
1824
1825} // close namespace bslma
1826
1827
1828#endif // End C++11 code
1829
1830#endif
1831
1832// ----------------------------------------------------------------------------
1833// Copyright 2020 Bloomberg Finance L.P.
1834//
1835// Licensed under the Apache License, Version 2.0 (the "License");
1836// you may not use this file except in compliance with the License.
1837// You may obtain a copy of the License at
1838//
1839// http://www.apache.org/licenses/LICENSE-2.0
1840//
1841// Unless required by applicable law or agreed to in writing, software
1842// distributed under the License is distributed on an "AS IS" BASIS,
1843// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1844// See the License for the specific language governing permissions and
1845// limitations under the License.
1846// ----------------------------- END-OF-FILE ----------------------------------
1847
1848/** @} */
1849/** @} */
1850/** @} */
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition bdlc_flathashset.h:574
iterator emplace_hint(const_iterator hint, ARGS &&... args)
EQUAL key_eq() const
Definition bdlc_flathashset.h:1675
bsl::size_t count(const KEY &key) const
Definition bdlc_flathashset.h:1637
bsl::pair< iterator, bool > emplace(ARGS &&... args)
EQUAL value_compare
Definition bdlc_flathashset.h:601
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< HASH, LOOKUP_KEY >::value &&BloombergLP::bslmf::IsTransparentPredicate< EQUAL, LOOKUP_KEY >::value, typenamebsl::pair< iterator, bool > >::type insert(LOOKUP_KEY &&key)
Definition bdlc_flathashset.h:900
const_iterator begin() const
Definition bdlc_flathashset.h:1706
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< HASH, LOOKUP_KEY >::value &&BloombergLP::bslmf::IsTransparentPredicate< EQUAL, LOOKUP_KEY >::value, bsl::size_t >::type count(const LOOKUP_KEY &key) const
Definition bdlc_flathashset.h:1054
HASH hash_function() const
Definition bdlc_flathashset.h:1668
void reserve(bsl::size_t numEntries)
Definition bdlc_flathashset.h:1597
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< HASH, LOOKUP_KEY >::value &&BloombergLP::bslmf::IsTransparentPredicate< EQUAL, LOOKUP_KEY >::value, bsl::pair< const_iterator, const_iterator > >::type equal_range(const LOOKUP_KEY &key) const
Definition bdlc_flathashset.h:1091
HASH hasher
Definition bdlc_flathashset.h:602
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition bdlc_flathashset.h:1745
const value_type * const_pointer
Definition bdlc_flathashset.h:606
bslma::Allocator * allocator() const
Return the allocator used by this flat hash set to supply memory.
Definition bdlc_flathashset.h:1739
const_iterator insert(const_iterator, const KEY &value)
Definition bdlc_flathashset.h:912
EQUAL key_compare
Definition bdlc_flathashset.h:600
friend void swap(FlatHashSet< K, H, E > &, FlatHashSet< K, H, E > &)
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< HASH, LOOKUP_KEY >::value &&BloombergLP::bslmf::IsTransparentPredicate< EQUAL, LOOKUP_KEY >::value, const_iterator >::type find(const LOOKUP_KEY &key) const
Definition bdlc_flathashset.h:1111
value_type * pointer
Definition bdlc_flathashset.h:605
value_type & reference
Definition bdlc_flathashset.h:603
float load_factor() const
Definition bdlc_flathashset.h:1682
const_iterator find(const KEY &key) const
Definition bdlc_flathashset.h:1661
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< HASH, LOOKUP_KEY >::value &&BloombergLP::bslmf::IsTransparentPredicate< EQUAL, LOOKUP_KEY >::value &&bsl::is_convertible< LOOKUP_KEY &&, const_iterator >::value==false &&bsl::is_convertible< const_iterator, LOOKUP_KEY && >::value==false, iterator >::type insert(const_iterator, LOOKUP_KEY &&key)
Definition bdlc_flathashset.h:948
FlatHashSet()
Definition bdlc_flathashset.h:1280
~FlatHashSet()
Destroy this object and each of its elements.
Definition bdlc_flathashset.h:1470
void clear()
Definition bdlc_flathashset.h:1518
bsl::pair< const_iterator, bool > insert(const KEY &value)
Definition bdlc_flathashset.h:865
const value_type & const_reference
Definition bdlc_flathashset.h:604
void rehash(bsl::size_t minimumCapacity)
Definition bdlc_flathashset.h:1590
ImplType::const_iterator iterator
Definition bdlc_flathashset.h:607
bsl::size_t size() const
Return the number of elements in this set.
Definition bdlc_flathashset.h:1696
const_iterator cbegin() const
Definition bdlc_flathashset.h:1714
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< HASH, LOOKUP_KEY >::value &&BloombergLP::bslmf::IsTransparentPredicate< EQUAL, LOOKUP_KEY >::value, bsl::size_t >::type erase(LOOKUP_KEY &&key)
Definition bdlc_flathashset.h:832
KEY value_type
Definition bdlc_flathashset.h:597
const_iterator cend() const
Definition bdlc_flathashset.h:1722
FlatHashSet & operator=(const FlatHashSet &rhs)
Definition bdlc_flathashset.h:1477
bsl::ptrdiff_t difference_type
Definition bdlc_flathashset.h:599
bsl::size_t capacity() const
Definition bdlc_flathashset.h:1623
bsl::size_t erase(const KEY &key)
Definition bdlc_flathashset.h:1547
void reset()
Definition bdlc_flathashset.h:1604
const_iterator insert(const_iterator, bslmf::MovableRef< KEY > value)
Definition bdlc_flathashset.h:926
bsl::size_t size_type
Definition bdlc_flathashset.h:598
bsl::pair< const_iterator, bool > insert(bslmf::MovableRef< KEY > value)
Definition bdlc_flathashset.h:880
ImplType::const_iterator const_iterator
Definition bdlc_flathashset.h:608
bool empty() const
Definition bdlc_flathashset.h:1644
float max_load_factor() const
Definition bdlc_flathashset.h:1689
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< HASH, LOOKUP_KEY >::value &&BloombergLP::bslmf::IsTransparentPredicate< EQUAL, LOOKUP_KEY >::value, bool >::type contains(const LOOKUP_KEY &key) const
Definition bdlc_flathashset.h:1029
bool contains(const KEY &key) const
Definition bdlc_flathashset.h:1630
bsl::pair< const_iterator, const_iterator > equal_range(const KEY &key) const
Definition bdlc_flathashset.h:1653
const_iterator end() const
Definition bdlc_flathashset.h:1730
KEY key_type
Definition bdlc_flathashset.h:596
Definition bdlc_flathashtable.h:326
bsl::size_t erase(const KEY &key)
Definition bdlc_flathashtable.h:1927
bsl::pair< iterator, bool > insert(const ENTRY &entry)
Definition bdlc_flathashtable.h:2050
iterator find(const KEY &key)
Definition bdlc_flathashtable.h:2036
bslstl::ForwardIterator< const KEY, IteratorImp > const_iterator
Definition bdlc_flathashtable.h:343
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< HASH, LOOKUP_KEY >::value &&BloombergLP::bslmf::IsTransparentPredicate< EQUAL, LOOKUP_KEY >::value, bsl::pair< iterator, bool > >::type insertTransparent(LOOKUP_KEY &&key)
Definition bdlc_flathashtable.h:754
bsl::pair< iterator, iterator > equal_range(const KEY &key)
Definition bdlc_flathashtable.h:1894
Definition bslstl_pair.h:1280
static void swap(T *a, T *b)
Definition bslalg_swaputil.h:182
Definition bslh_fibonaccibadhashwrapper.h:165
Definition bslim_printer.h:604
void printValue(const TYPE &data) const
Definition bslim_printer.h:1240
void end(bool suppressBracket=false) const
void start(bool suppressBracket=false) const
Definition bslma_allocator.h:545
Definition bslmf_movableref.h:752
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1917
#define BSLS_COMPILERFEATURES_FORWARD_REF(T)
Definition bsls_compilerfeatures.h:2343
#define BSLS_COMPILERFEATURES_FORWARD(T, V)
Definition bsls_compilerfeatures.h:2349
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bdlc_bitarray.h:506
void swap(BitArray &a, BitArray &b)
bool operator==(const BitArray &lhs, const BitArray &rhs)
bool operator!=(const BitArray &lhs, const BitArray &rhs)
BitArray operator<<(const BitArray &array, bsl::size_t numBits)
ALLOCATOR const STRING_VIEW_LIKE_TYPE & rhs
Definition bslstl_string.h:3918
T::iterator begin(T &container)
Definition bslstl_iterator.h:1593
ALLOCATOR & lhs
Definition bslstl_string.h:3917
T::iterator end(T &container)
Definition bslstl_iterator.h:1621
Definition bdlc_flathashmap.h:2218
Definition baljsn_encoder_testtypes.h:76
Definition bdlbb_blob.h:579
Definition bdlc_flathashset.h:533
static void constructFromKey(ENTRY *entry, bslma::Allocator *allocator, BSLS_COMPILERFEATURES_FORWARD_REF(KEY_TYPE) key)
static const ENTRY & key(const ENTRY &entry)
Return the specified entry.
Definition bdlc_flathashset.h:1268
static void construct(ENTRY *entry, bslma::Allocator *allocator, ARGS &&... args)
Definition bdlc_flathashset.h:1237
TYPE first
Definition bslstl_pair.h:587
Definition bslmf_enableif.h:530
Definition bslstl_equalto.h:316
Definition bslmf_isconvertible.h:875
Definition bslalg_hasstliterators.h:99
static void construct(TARGET_TYPE *address, const ALLOCATOR &allocator)
Definition bslma_constructionutil.h:1244
Definition bslma_usesbslmaallocator.h:344
static MovableRef< t_TYPE > move(t_TYPE &reference) BSLS_KEYWORD_NOEXCEPT
Definition bslmf_movableref.h:1067