Skip to content

Commit b65c88c

Browse files
authored
Replace 'THash[Multi]Map' to 'std::unordered_[multi]map' (#37) (#241)
1 parent 182065e commit b65c88c

File tree

81 files changed

+373
-4297
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+373
-4297
lines changed

include/ydb-cpp-sdk/util/generic/fwd.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,6 @@ template <class TValue, class TCmp>
3737
class TRbTree;
3838

3939
//containers
40-
//template <class T, class A = std::allocator<T>>
41-
//class TDeque;
42-
43-
template <class Key, class T, class HashFcn = THash<Key>, class EqualKey = TEqualTo<Key>, class Alloc = std::allocator<Key>>
44-
class THashMap;
45-
46-
template <class Key, class T, class HashFcn = THash<Key>, class EqualKey = TEqualTo<Key>, class Alloc = std::allocator<Key>>
47-
class THashMultiMap;
48-
4940
template <class K, class L = TLess<K>, class A = std::allocator<K>>
5041
class TSet;
5142

include/ydb-cpp-sdk/util/generic/typetraits.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class TTypeTraits<void>: public TTypeTraitsBase<void> {};
223223
* >;
224224
*
225225
* static_assert(TIsAssocCont<std::vector<int>>::value == false, "");
226-
* static_assert(TIsAssocCont<THashMap<int>>::value == true, "");
226+
* static_assert(TIsAssocCont<std::unordered_map<int>>::value == true, "");
227227
* @endcode
228228
*/
229229
#define Y_HAS_SUBTYPE(...) Y_PASS_VA_ARGS(Y_MACRO_IMPL_DISPATCHER_2(__VA_ARGS__, Y_HAS_SUBTYPE_IMPL_2, Y_HAS_SUBTYPE_IMPL_1)(__VA_ARGS__))

include/ydb-cpp-sdk/util/ysaveload.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,8 @@ class TSetSerializerInserter<TSetType, TValue, true>: public TSetSerializerInser
500500
};
501501

502502
template <class T1, class T2, class T3, class T4, class T5, class TValue>
503-
class TSetSerializerInserter<THashMap<T1, T2, T3, T4, T5>, TValue, false>: public TSetSerializerInserterBase<THashMap<T1, T2, T3, T4, T5>, TValue> {
504-
using TMapType = THashMap<T1, T2, T3, T4, T5>;
503+
class TSetSerializerInserter<std::unordered_map<T1, T2, T3, T4, T5>, TValue, false>: public TSetSerializerInserterBase<std::unordered_map<T1, T2, T3, T4, T5>, TValue> {
504+
using TMapType = std::unordered_map<T1, T2, T3, T4, T5>;
505505
using TBase = TSetSerializerInserterBase<TMapType, TValue>;
506506

507507
public:
@@ -513,8 +513,8 @@ class TSetSerializerInserter<THashMap<T1, T2, T3, T4, T5>, TValue, false>: publi
513513
};
514514

515515
template <class T1, class T2, class T3, class T4, class T5, class TValue>
516-
class TSetSerializerInserter<THashMultiMap<T1, T2, T3, T4, T5>, TValue, false>: public TSetSerializerInserterBase<THashMultiMap<T1, T2, T3, T4, T5>, TValue> {
517-
using TMapType = THashMultiMap<T1, T2, T3, T4, T5>;
516+
class TSetSerializerInserter<std::unordered_multimap<T1, T2, T3, T4, T5>, TValue, false>: public TSetSerializerInserterBase<std::unordered_multimap<T1, T2, T3, T4, T5>, TValue> {
517+
using TMapType = std::unordered_multimap<T1, T2, T3, T4, T5>;
518518
using TBase = TSetSerializerInserterBase<TMapType, TValue>;
519519

520520
public:
@@ -591,11 +591,11 @@ class TSerializer<std::unordered_map<K, T, C, A>>: public TMapSerializer<std::un
591591
};
592592

593593
template <class T1, class T2, class T3, class T4, class T5>
594-
class TSerializer<THashMap<T1, T2, T3, T4, T5>>: public TMapSerializer<THashMap<T1, T2, T3, T4, T5>, false> {
594+
class TSerializer<std::unordered_map<T1, T2, T3, T4, T5>>: public TMapSerializer<std::unordered_map<T1, T2, T3, T4, T5>, false> {
595595
};
596596

597597
template <class T1, class T2, class T3, class T4, class T5>
598-
class TSerializer<THashMultiMap<T1, T2, T3, T4, T5>>: public TMapSerializer<THashMultiMap<T1, T2, T3, T4, T5>, false> {
598+
class TSerializer<std::unordered_multimap<T1, T2, T3, T4, T5>>: public TMapSerializer<std::unordered_multimap<T1, T2, T3, T4, T5>, false> {
599599
};
600600

601601
template <class K, class C, class A>

src/client/federated_topic/impl/federation_observer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <ydb-cpp-sdk/client/federated_topic/federated_topic.h>
1313

1414
#include <ydb-cpp-sdk/util/system/spinlock.h>
15-
#include <src/util/generic/hash.h>
1615

1716
#include <deque>
1817
#include <memory>

src/client/persqueue_public/impl/persqueue_impl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <src/client/impl/ydb_internal/make_request/make.h>
1111
#undef INCLUDE_YDB_INTERNAL_H
1212

13+
#include <unordered_map>
14+
1315
namespace NYdb::NPersQueue {
1416

1517
class TPersQueueClient::TImpl : public TClientImplCommon<TPersQueueClient::TImpl> {
@@ -241,7 +243,7 @@ class TPersQueueClient::TImpl : public TClientImplCommon<TPersQueueClient::TImpl
241243
const std::string CustomEndpoint;
242244
TAdaptiveLock Lock;
243245
std::shared_ptr<std::unordered_map<ECodec, THolder<ICodec>>> ProvidedCodecs = std::make_shared<std::unordered_map<ECodec, THolder<ICodec>>>();
244-
THashMap<std::string, std::shared_ptr<TImpl>> Subclients; // Endpoint -> Subclient.
246+
std::unordered_map<std::string, std::shared_ptr<TImpl>> Subclients; // Endpoint -> Subclient.
245247
};
246248

247249
} // namespace NYdb::NPersQueue

src/client/persqueue_public/impl/read_session.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ void TReadSession::ProceedWithoutClusterDiscovery() {
166166
}
167167

168168
std::string normalizedName = "null";
169-
THashMap<std::string, TClusterSessionInfo>::iterator clusterSessionInfoIter;
170-
clusterSessionInfoIter = ClusterSessions.emplace(normalizedName, normalizedName).first;
169+
auto clusterSessionInfoIter = ClusterSessions.emplace(normalizedName, normalizedName).first;
171170
TClusterSessionInfo& clusterSessionInfo = clusterSessionInfoIter->second;
172171
clusterSessionInfo.ClusterEndpoint = DbDriverState->DiscoveryEndpoint;
173172
clusterSessionInfo.Topics = Settings.Topics_;
@@ -271,7 +270,7 @@ void TReadSession::OnClusterDiscovery(const TStatus& status, const Ydb::PersQueu
271270
for (const Ydb::PersQueue::ClusterDiscovery::ClusterInfo& cluster : readSessionClusters.clusters()) {
272271
std::string normalizedName = cluster.name();
273272
NUtils::ToLower(normalizedName);
274-
THashMap<std::string, TClusterSessionInfo>::iterator clusterSessionInfoIter;
273+
decltype(ClusterSessions)::iterator clusterSessionInfoIter;
275274
if (explicitlySpecifiedClusters) {
276275
clusterSessionInfoIter = ClusterSessions.find(normalizedName);
277276
if (clusterSessionInfoIter == ClusterSessions.end()) { // User hasn't specified this cluster, so it isn't in our interest.
@@ -755,8 +754,8 @@ class TGracefulReleasingSimpleDataHandlers : public TThrRefBase {
755754
TAdaptiveLock Lock; // For the case when user gave us multithreaded executor.
756755
const std::function<void(TReadSessionEvent::TDataReceivedEvent&)> DataHandler;
757756
const bool CommitAfterProcessing;
758-
THashMap<ui64, TDisjointIntervalTree<ui64>> PartitionStreamToUncommittedOffsets; // Partition stream id -> set of offsets.
759-
THashMap<ui64, TReadSessionEvent::TDestroyPartitionStreamEvent> UnconfirmedDestroys; // Partition stream id -> destroy events.
757+
std::unordered_map<ui64, TDisjointIntervalTree<ui64>> PartitionStreamToUncommittedOffsets; // Partition stream id -> set of offsets.
758+
std::unordered_map<ui64, TReadSessionEvent::TDestroyPartitionStreamEvent> UnconfirmedDestroys; // Partition stream id -> destroy events.
760759
};
761760

762761
TReadSessionSettings::TEventHandlers& TReadSessionSettings::TEventHandlers::SimpleDataHandlers(std::function<void(TReadSessionEvent::TDataReceivedEvent&)> dataHandler,
@@ -824,7 +823,7 @@ class TDeferredCommit::TImpl {
824823
static void Add(const TPartitionStream::TPtr& partitionStream, TDisjointIntervalTree<ui64>& offsetSet, ui64 startOffset, ui64 endOffset);
825824

826825
private:
827-
THashMap<TPartitionStream::TPtr, TDisjointIntervalTree<ui64>> Offsets; // Partition stream -> offsets set.
826+
std::unordered_map<TPartitionStream::TPtr, TDisjointIntervalTree<ui64>, THash<TPartitionStream::TPtr>> Offsets; // Partition stream -> offsets set.
828827
};
829828

830829
TDeferredCommit::TDeferredCommit() {

src/client/persqueue_public/impl/read_session.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <src/client/topic/impl/counters_logger.h>
77
#include <src/client/persqueue_public/impl/persqueue_impl.h>
88

9+
#include <unordered_map>
10+
911
namespace NYdb::NPersQueue {
1012

1113
// High level class that manages several read session impls.
@@ -108,7 +110,7 @@ class TReadSession : public IReadSession,
108110
TDbDriverStatePtr DbDriverState;
109111
TAdaptiveLock Lock;
110112
std::shared_ptr<TReadSessionEventsQueue> EventsQueue;
111-
THashMap<std::string, TClusterSessionInfo> ClusterSessions; // Cluster name (in lower case) -> TClusterSessionInfo
113+
std::unordered_map<std::string, TClusterSessionInfo> ClusterSessions; // Cluster name (in lower case) -> TClusterSessionInfo
112114
NYdbGrpc::IQueueClientContextPtr ClusterDiscoveryDelayContext;
113115
IRetryPolicy::IRetryState::TPtr ClusterDiscoveryRetryState;
114116
bool DataReadingSuspended = false;

src/client/topic/impl/deferred_commit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class TDeferredCommit::TImpl {
2727

2828
private:
2929
// Partition stream -> offsets set.
30-
THashMap<TPartitionSession::TPtr, TDisjointIntervalTree<ui64>> Offsets;
30+
std::unordered_map<TPartitionSession::TPtr, TDisjointIntervalTree<ui64>, THash<TPartitionSession::TPtr>> Offsets;
3131
};
3232

3333
TDeferredCommit::TDeferredCommit() {

src/client/topic/impl/read_session.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class TReadSession : public IReadSession {
6363
void AbortImpl(EStatus statusCode, const std::string& message, TDeferredActions<false>& deferred);
6464

6565
private:
66-
using TOffsetRanges = THashMap<std::string, THashMap<ui64, TDisjointIntervalTree<ui64>>>;
66+
using TOffsetRanges = std::unordered_map<std::string, std::unordered_map<ui64, TDisjointIntervalTree<ui64>>>;
6767

6868
void CollectOffsets(NTable::TTransaction& tx,
6969
const TReadSessionEvent::TDataReceivedEvent& event);
@@ -74,7 +74,7 @@ class TReadSession : public IReadSession {
7474
//
7575
// (session, tx) -> topic -> partition -> (begin, end)
7676
//
77-
THashMap<std::pair<std::string, std::string>, TOffsetRanges> OffsetRanges;
77+
std::unordered_map<std::pair<std::string, std::string>, TOffsetRanges, THash<std::pair<std::string, std::string>>> OffsetRanges;
7878

7979
TReadSessionSettings Settings;
8080
const std::string SessionId;

src/client/topic/impl/read_session_impl.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#include <src/library/containers/disjoint_interval_tree/disjoint_interval_tree.h>
2020

2121
#include <ydb-cpp-sdk/util/digest/numeric.h>
22-
#include <src/util/generic/hash.h>
23-
#include <src/util/generic/hash_multi_map.h>
2422

2523
#include <atomic>
2624
#include <deque>
@@ -1272,9 +1270,9 @@ class TSingleClusterReadSessionImpl : public TEnableSelfContext<TSingleClusterRe
12721270
bool HasUnacknowledgedCookies() const;
12731271

12741272
private:
1275-
THashMap<typename TCookie::TKey, typename TCookie::TPtr, typename TCookie::TKey::THash> Cookies;
1276-
THashMap<std::pair<ui64, ui64>, typename TCookie::TPtr> UncommittedOffsetToCookie; // (Partition stream id, Offset) -> Cookie.
1277-
THashMultiMap<ui64, typename TCookie::TPtr> PartitionStreamIdToCookie;
1273+
std::unordered_map<typename TCookie::TKey, typename TCookie::TPtr, typename TCookie::TKey::THash> Cookies;
1274+
std::unordered_map<std::pair<ui64, ui64>, typename TCookie::TPtr, THash<std::pair<ui64, ui64>>> UncommittedOffsetToCookie; // (Partition stream id, Offset) -> Cookie.
1275+
std::unordered_multimap<ui64, typename TCookie::TPtr> PartitionStreamIdToCookie;
12781276
size_t CommitInflight = 0; // Commit inflight to server.
12791277
};
12801278

@@ -1318,7 +1316,7 @@ class TSingleClusterReadSessionImpl : public TEnableSelfContext<TSingleClusterRe
13181316

13191317
bool WaitingReadResponse = false;
13201318
std::shared_ptr<TServerMessage<UseMigrationProtocol>> ServerMessage; // Server message to write server response to.
1321-
THashMap<ui64, TIntrusivePtr<TPartitionStreamImpl<UseMigrationProtocol>>> PartitionStreams; // assignId -> Partition stream.
1319+
std::unordered_map<ui64, TIntrusivePtr<TPartitionStreamImpl<UseMigrationProtocol>>> PartitionStreams; // assignId -> Partition stream.
13221320
TPartitionCookieMapping CookieMapping;
13231321
std::deque<TDecompressionQueueItem> DecompressionQueue;
13241322
bool DataReadingSuspended = false;

src/library/blockcodecs/core/codecs.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
#include "register.h"
44

55
#include <ydb-cpp-sdk/util/ysaveload.h>
6-
#include <src/util/stream/null.h>
76
#include <ydb-cpp-sdk/util/stream/mem.h>
87
#include <ydb-cpp-sdk/util/string/cast.h>
9-
#include <src/util/string/join.h>
10-
#include <src/util/system/align.h>
118
#include <ydb-cpp-sdk/util/system/unaligned_mem.h>
12-
#include <src/util/generic/hash.h>
139
#include <ydb-cpp-sdk/util/generic/cast.h>
14-
#include <src/util/generic/buffer.h>
15-
#include <ydb-cpp-sdk/util/generic/singleton.h>
1610
#include <ydb-cpp-sdk/util/generic/algorithm.h>
11+
#include <ydb-cpp-sdk/util/generic/singleton.h>
12+
13+
#include <src/util/stream/null.h>
14+
#include <src/util/string/join.h>
15+
#include <src/util/system/align.h>
16+
#include <src/util/generic/buffer.h>
1717
#include <src/util/generic/mem_copy.h>
1818

1919
using namespace NBlockCodecs;
@@ -60,7 +60,7 @@ namespace {
6060
std::deque<std::string> Tmp;
6161
TNullCodec Null;
6262
std::vector<TCodecPtr> Codecs;
63-
typedef THashMap<std::string_view, ICodec*> TRegistry;
63+
using TRegistry = std::unordered_map<std::string_view, ICodec*>;
6464
TRegistry Registry;
6565

6666
// SEARCH-8344: Global decompressed size limiter (to prevent remote DoS)

src/library/blockcodecs/core/common.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
#include "codecs.h"
44

55
#include <ydb-cpp-sdk/util/ysaveload.h>
6-
#include <src/util/stream/null.h>
76
#include <ydb-cpp-sdk/util/stream/mem.h>
87
#include <ydb-cpp-sdk/util/string/cast.h>
9-
#include <src/util/string/join.h>
10-
#include <src/util/system/align.h>
118
#include <ydb-cpp-sdk/util/system/unaligned_mem.h>
12-
#include <src/util/generic/hash.h>
139
#include <ydb-cpp-sdk/util/generic/cast.h>
14-
#include <src/util/generic/buffer.h>
1510
#include <ydb-cpp-sdk/util/generic/singleton.h>
1611
#include <ydb-cpp-sdk/util/generic/algorithm.h>
12+
13+
#include <src/util/stream/null.h>
14+
#include <src/util/string/join.h>
15+
#include <src/util/system/align.h>
16+
#include <src/util/generic/buffer.h>
1717
#include <src/util/generic/mem_copy.h>
1818

1919
namespace NBlockCodecs {

src/library/blockcodecs/core/stream.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#include "stream.h"
22
#include "codecs.h"
33

4-
#include <src/util/digest/murmur.h>
5-
#include <src/util/generic/scope.h>
64
#include <ydb-cpp-sdk/util/generic/cast.h>
7-
#include <src/util/generic/hash.h>
85
#include <ydb-cpp-sdk/util/generic/singleton.h>
96
#include <ydb-cpp-sdk/util/stream/mem.h>
107
#include <ydb-cpp-sdk/util/ysaveload.h>
118

9+
#include <src/util/digest/murmur.h>
10+
#include <src/util/generic/scope.h>
11+
1212
using namespace NBlockCodecs;
1313

1414
namespace {
@@ -51,7 +51,7 @@ namespace {
5151
ythrow yexception() << "can not find codec by id " << id;
5252
}
5353

54-
typedef THashMap<TCodecID, const ICodec*> TByID;
54+
using TByID = std::unordered_map<TCodecID, const ICodec*>;
5555
TByID ByID;
5656
};
5757

src/library/case_insensitive_string/case_insensitive_string.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include "case_insensitive_char_traits.h"
44

5-
#include <src/util/generic/hash.h>
65
#include <src/util/string/split.h>
76

87
#include <string>

src/library/charset/ci_string_ut.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#include "ci_string.h"
22

3-
#include <src/util/generic/hash.h>
43
#include <src/util/generic/string_ut.h>
54

65
class TCaseStringTest: public TTestBase, private TStringTestImpl<TCiString, TTestData<char>> {
76
public:
87
void TestSpecial() {
98
TCiString ss = Data._0123456(); // type 'TCiString' is used as is
10-
size_t hash_val = ComputeHash(ss);
9+
size_t hash_val = THash<TCiString>{}(ss);
1110
UNIT_ASSERT(hash_val == 1489244);
1211
}
1312

0 commit comments

Comments
 (0)