ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
hashmap.hpp
Go to the documentation of this file.
1/** ************************************************************************************************
2 * \file
3 * This header file is part of module \alib_monomem of the \aliblong.
4 *
5 * \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
6 * Published under \ref mainpage_license "Boost Software License".
7 **************************************************************************************************/
8#ifndef HPP_ALIB_MONOMEM_HASHMAP
9#define HPP_ALIB_MONOMEM_HASHMAP 1
10
11#if !defined(HPP_ALIB_MONOMEM_HASHTABLE)
13#endif
14
15#if ALIB_STRINGS && !defined (HPP_ALIB_COMPATIBILITY_STD_STRINGS_FUNCTIONAL)
17#endif
18
19namespace alib { namespace monomem {
20
21namespace detail {
22/**
23 * Helper struct used for implementing \alib{monomem;HashMap}.
24 * This type is used as template parameter \p{TAccess} of \alib{monomem;HashTable}.
25 * @tparam TKey The key type.
26 * @tparam TMapped The type of the mapped objects.
27 */
28template<typename TKey, typename TMapped>
30{
31 /**
32 * Returns the first element of a <c>std::pair</c>.
33 * @param src The value of the element to hash.
34 * @return The key-portion of the stored value.
35 */
36 TKey& Key(std::pair<TKey, TMapped>& src) const
37 {
38 return src.first;
39 }
40
41 /**
42 * Returns the second element of a <c>std::pair</c>.
43 * @param src The value of the element to hash.
44 * @return The mapped-portion of the stored value.
45 */
46 TMapped& Mapped(std::pair<TKey, TMapped>& src) const
47 {
48 return src.second;
49 }
50};
51
52} // namespace alib::monomem[::detail]
53
54/** ************************************************************************************************
55 * This type definition is a shortcut to \alib{monomem;HashTable}, usable if the data stored
56 * in the container consists of two parts, a <em>key</em> and a <em>mapped</em> part, where only
57 * the key-part is to be used for the comparison of values.
58 *
59 * \see
60 * For a detailed description of this type, see original type \alib{monomem;HashTable}.<br>
61 * Another type definition based on \b %HashTable is provided with \alib{monomem;HashSet}.
62 *
63 * @tparam TKey The type of the <em>key-portion</em> of the inserted data.<br>
64 * This type is published as \alib{monomem;HashTable::KeyType}.
65 * @tparam TMapped The type of the <em>mapped-portion</em> of the inserted data.<br>
66 * This type is published as \alib{monomem;HashTable::MappedType}.
67 * @tparam THash The hash functor applicable to \p{TKey}.<br>
68 * Defaults to <c>std::hash<TKey></c> and is published as
69 * \alib{monomem;HashTable::HashType}.
70 * @tparam TEqual The comparison functor on \p{TKey}.<br>
71 * Defaults to <c>std::equal_to<TKey></c> and is published as
72 * \alib{monomem;HashTable::EqualType}.
73 * @tparam THashCaching Determines if hash codes are cached when elements are inserted.<br>
74 * Defaults to <b>Caching::Auto</b>, which enables caching if
75 * <c>std::is_arithmetic<TKey>::value</c> evaluates to \c false.
76 * @tparam TRecycling Denotes the type of recycling that is to be performed. Possible values are
77 * \alib{monomem;Recycling::Private} (the default),
78 * \alib{monomem;Recycling::Shared} or \alib{monomem;Recycling::None}.
79 **************************************************************************************************/
80template< typename TKey,
81 typename TMapped,
82 typename THash = std::hash <TKey>,
83 typename TEqual = std::equal_to<TKey>,
85 typename TRecycling = Recycling::Private >
87 std::pair< TKey, TMapped>,
88 TKey, TMapped,
89 THash,
90 TEqual,
92 THashCaching,
93 TRecycling >;
94
95}// namespace alib[::monomem]
96
97/// Type alias in namespace \b alib. See type definition \ref alib::monomem::HashMap.
98template< typename TKey,
99 typename TMapped,
100 typename THash = std::hash <TKey>,
101 typename TEqual = std::equal_to<TKey>,
102 lang::Caching THashCaching = lang::Caching::Auto,
103 typename TRecycling = monomem::Recycling::Private >
105
106} // namespace [alib]
107
108#endif // HPP_ALIB_MONOMEM_HASHMAP
@ Auto
Auto/default mode.
Definition alib.cpp:57
TKey & Key(std::pair< TKey, TMapped > &src) const
Definition hashmap.hpp:36
TMapped & Mapped(std::pair< TKey, TMapped > &src) const
Definition hashmap.hpp:46