Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
HashTableSupport.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4
5#ifndef _Stroika_Foundation_Containers_Private_HashTableSupport_h_
6#define _Stroika_Foundation_Containers_Private_HashTableSupport_h_
7
8#include "Stroika/Foundation/StroikaPreComp.h"
9
10#include "Stroika/Foundation/Common/Common.h"
11
12#include "Stroika/Foundation/Containers/Common.h"
13#include "Stroika/Foundation/Containers/DataStructures/HashTable.h"
14
15/**
16 * \file
17 * support classes for Concrete classes 'extensions' of behavior specific to the HashTable data structure
18 */
19
21
22 /**
23 * \brief HashTableBasedContainer is a Stroika implementation detail, but its public methods are fair game and fully supported (as used in subclasses)
24 *
25 * This mechanism allows all the array based concrete containers (such as Set_HashTable, Sequence_HashTable) to all
26 * share the same API and implementation of the API access functions (ReBalance etc) but without
27 * any genericity implied in the API (just code sharing).
28 *
29 * \par Example Usage
30 * \code
31 * class Association_Array : public Association<KEY_TYPE, MAPPED_VALUE_TYPE> {
32 * using inherited = Association<KEY_TYPE, MAPPED_VALUE_TYPE>;
33 * // BECOMES
34 * class Association_Array : public Private::HashTableBasedContainer<Association_Array<KEY_TYPE, MAPPED_VALUE_TYPE>, Association<KEY_TYPE, MAPPED_VALUE_TYPE>, true> {
35 * using inherited = Private::HashTableBasedContainer<Association_Array<KEY_TYPE, MAPPED_VALUE_TYPE>, Association<KEY_TYPE, MAPPED_VALUE_TYPE>, true>;
36 *
37 * // AND need in main public container,
38 * friend inherited; // for HashTableBasedContainer
39 * \endcode
40 */
41 template <typename THIS_CONTAINER, typename BASE_CONTAINER>
42 class HashTableBasedContainer : public BASE_CONTAINER {
43 public:
44 /**
45 */
46 using BASE_CONTAINER::BASE_CONTAINER;
47
48 public:
49 /**
50 * \brief
51 */
52 nonvirtual void ReHash (size_t newBucketCount);
53
54 public:
55 /**
56 * \brief
57 */
58 nonvirtual void ReHashIfNeeded ();
59
60 public:
61 /**
62 * \brief
63 */
64 nonvirtual size_t bucket_count () const;
65
66 public:
67 /**
68 * \brief
69 */
70 nonvirtual size_t bucket_size (size_t bucketIdx) const;
71
72 public:
73 /**
74 * \brief
75 */
76 nonvirtual float load_factor () const;
77
78 public:
79 /**
80 * \brief
81 */
82 nonvirtual float max_load_factor () const;
83
84 public:
85 /**
86 * \brief
87 */
88 nonvirtual void max_load_factor (float mlf);
89 };
90
91 /**
92 * \brief impl detail for array based container support
93 *
94 * \par Example Usage
95 * \code
96 * // In Association_HashTable template
97 * //using IImplRepBase_ = typename Association<KEY_TYPE, MAPPED_VALUE_TYPE>::_IRep; // BECOMES
98 * using IImplRepBase_ = Private::HashTableBasedContainerIRep< typename Association<KEY_TYPE, MAPPED_VALUE_TYPE>::_IRep >;
99 * \endcode
100 */
101 template <typename CONTAINER_REP_BASE_CLASS>
102 class HashTableBasedContainerIRep : public CONTAINER_REP_BASE_CLASS {
103 public:
104 virtual void ReHash (size_t newBucketCount) = 0;
105 virtual void ReHashIfNeeded () = 0;
106 virtual size_t bucket_count () const = 0;
107 virtual size_t bucket_size (size_t bucketIdx) const = 0;
108 virtual float load_factor () const = 0;
109 virtual float max_load_factor () const = 0;
110 virtual void max_load_factor (float mlf) = 0;
111 };
112
113 /**
114 * \brief CRTP applied when HashTableBasedContainerIRep used
115 *
116 * \par Example Usage
117 * \code
118 * template <qCompilerAndStdLib_ConstraintDiffersInTemplateRedeclaration_BWA (IEqualsComparer<KEY_TYPE>) KEY_EQUALS_COMPARER>
119 * class Association_Array<KEY_TYPE, MAPPED_VALUE_TYPE>::Rep_
120 * : public Rep_<KEY_EQUALS_COMPARER>, IImplRepBase_,
121 * public Memory::UseBlockAllocationIfAppropriate<Rep_<KEY_EQUALS_COMPARER>> {
122 * using inherited = Rep_<KEY_EQUALS_COMPARER>;
123 * // BECOMES
124 * template <qCompilerAndStdLib_ConstraintDiffersInTemplateRedeclaration_BWA (IEqualsComparer<KEY_TYPE>) KEY_EQUALS_COMPARER>
125 * class Association_Array<KEY_TYPE, MAPPED_VALUE_TYPE>::Rep_
126 * : public Private::HashTableBasedContainerRepImpl<Rep_<KEY_EQUALS_COMPARER>, IImplRepBase_>,
127 * public Memory::UseBlockAllocationIfAppropriate<Rep_<KEY_EQUALS_COMPARER>> {
128 * using inherited = Private::HashTableBasedContainerRepImpl<Rep_<KEY_EQUALS_COMPARER>, IImplRepBase_>;
129 *
130 * // AND need in Rep_,
131 * friend inherited; // for HashTableBasedContainerRepImpl
132 * \endcode
133 */
134 template <typename THIS_CONTAINER_REP, typename BASE_CONTAINER_REP>
135 class HashTableBasedContainerRepImpl : public BASE_CONTAINER_REP {
136 public:
137 /**
138 */
139 using BASE_CONTAINER_REP::BASE_CONTAINER_REP;
140 virtual void ReHash (size_t newBucketCount) override;
141 virtual void ReHashIfNeeded () override;
142 virtual size_t bucket_count () const override;
143 virtual size_t bucket_size (size_t bucketIdx) const override;
144 virtual float load_factor () const override;
145 virtual float max_load_factor () const override;
146 virtual void max_load_factor (float mlf) override;
147 };
148
149}
150
151/*
152 ********************************************************************************
153 ***************************** Implementation Details ***************************
154 ********************************************************************************
155 */
156#include "HashTableSupport.inl"
157
158#endif /*_Stroika_Foundation_Containers_Private_HashTableSupport_h_ */
HashTableBasedContainer is a Stroika implementation detail, but its public methods are fair game and ...