Skip to content

59 Replace THashSet to std::unordered_set #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/ydb_persqueue_core/ut/read_session_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1320,8 +1320,8 @@ Y_UNIT_TEST_SUITE(ReadSessionImplTest) {
std::cerr << "Compressed message data size: " << compressedMessageData.size() << std::endl;
ui64 offset = 1;
ui64 seqNo = 42;
THashSet<ui64> committedCookies;
THashSet<ui64> committedOffsets;
std::unordered_set<ui64> committedCookies;
std::unordered_set<ui64> committedOffsets;
EXPECT_CALL(*setup.MockProcessor, OnCommitRequest(_))
.WillRepeatedly(Invoke([&committedCookies, &committedOffsets](const Ydb::PersQueue::V1::MigrationStreamingReadClientMessage::Commit& req) {
for (const auto& commit : req.cookies()) {
Expand Down
2 changes: 1 addition & 1 deletion client/ydb_persqueue_core/ut/ut_utils/test_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class TTestServer {

if (killPq)
{
THashSet<ui64> restartedTablets;
std::unordered_set<ui64> restartedTablets;
for (const auto& p : persQueueGroup.GetPartitions())
if (restartedTablets.insert(p.GetTabletId()).second)
{
Expand Down
2 changes: 1 addition & 1 deletion client/ydb_persqueue_core/ut/ut_utils/ut_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace NYdb::NPersQueue::NTests {

void WaitMessagesAcked(std::shared_ptr<IWriteSession> writer, ui64 startSeqNo, ui64 endSeqNo) {
THashSet<ui64> ackedSeqNo;
std::unordered_set<ui64> ackedSeqNo;
while (ackedSeqNo.size() < endSeqNo - startSeqNo + 1) {
auto event = *writer->GetEvent(true);
if (std::holds_alternative<TWriteSessionEvent::TReadyToAcceptEvent>(event)) {
Expand Down
20 changes: 13 additions & 7 deletions library/cpp/cache/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include <util/generic/algorithm.h>
#include <util/generic/ptr.h>
#include <util/generic/intrlist.h>
#include <util/generic/hash_set.h>
#include <util/generic/yexception.h>
#include <utility>
#include <unordered_set>

template <class TValue>
struct TUniformSizeProvider {
Expand Down Expand Up @@ -67,6 +67,7 @@ class TLRUList {
TValue Value;

struct THash {
using is_transparent = void;
size_t operator()(const TItem& item) const {
return ::THash<TKey>()(item.Key);
}
Expand All @@ -76,6 +77,7 @@ class TLRUList {
};

struct TEqualTo {
using is_transparent = void;
bool operator()(const TItem& lhs, const TItem& rhs) const {
return lhs.Key == rhs.Key;
}
Expand Down Expand Up @@ -203,6 +205,7 @@ class TLFUList {
size_t Counter;

struct THash {
using is_transparent = void;
size_t operator()(const TItem& item) const {
return ::THash<TKey>()(item.Key);
}
Expand All @@ -212,6 +215,7 @@ class TLFUList {
};

struct TEqualTo {
using is_transparent = void;
bool operator()(const TItem& lhs, const TItem& rhs) const {
return lhs.Key == rhs.Key;
}
Expand Down Expand Up @@ -333,6 +337,7 @@ class TLWList {
TWeight Weight;

struct THash {
using is_transparent = void;
size_t operator()(const TItem& item) const {
return ::THash<TKey>()(item.Key);
}
Expand All @@ -341,7 +346,8 @@ class TLWList {
}
};

struct TEqualTo {
struct TEqualTo {
using is_transparent = void;
bool operator()(const TItem& lhs, const TItem& rhs) const {
return lhs.Key == rhs.Key;
}
Expand Down Expand Up @@ -446,17 +452,17 @@ class TLWList {

private:
std::vector<TItem*> Heap;
THashSet<TItem*> Removed;
std::unordered_set<TItem*> Removed;

size_t Size;
size_t MaxSize;
};

template <typename TKey, typename TValue, typename TListType, typename TDeleter, typename TAllocator = std::allocator<void>>
template <typename TKey, typename TValue, typename TListType, typename TDeleter, typename TAllocator = std::allocator<typename TListType::TItem>>
class TCache {
typedef typename TListType::TItem TItem;
typedef typename TItem::THash THash;
typedef THashMultiSet<TItem, THash, typename TItem::TEqualTo, TAllocator> TIndex;
typedef std::unordered_multiset<TItem, THash, typename TItem::TEqualTo, TAllocator> TIndex;
typedef typename TIndex::iterator TIndexIterator;
typedef typename TIndex::const_iterator TIndexConstIterator;

Expand Down Expand Up @@ -657,7 +663,7 @@ class TCache {
Index.reserve(hint);
}

typedef typename TIndex::node_allocator_type TNodeAllocatorType;
typedef typename std::allocator_traits<typename TIndex::allocator_type>::template rebind_alloc<typename TIndex::value_type> TNodeAllocatorType;
TNodeAllocatorType& GetNodeAllocator() {
return Index.GetNodeAllocator();
}
Expand Down Expand Up @@ -691,7 +697,7 @@ struct TNoopDelete {
}
};

template <typename TKey, typename TValue, typename TDeleter = TNoopDelete, class TSizeProvider = TUniformSizeProvider<TValue>, typename TAllocator = std::allocator<void>>
template <typename TKey, typename TValue, typename TDeleter = TNoopDelete, class TSizeProvider = TUniformSizeProvider<TValue>, typename TAllocator = std::allocator<typename TLRUList<TKey, TValue, TSizeProvider>::TItem>>
class TLRUCache: public TCache<TKey, TValue, TLRUList<TKey, TValue, TSizeProvider>, TDeleter, TAllocator> {
using TListType = TLRUList<TKey, TValue, TSizeProvider>;
typedef TCache<TKey, TValue, TListType, TDeleter, TAllocator> TBase;
Expand Down
4 changes: 2 additions & 2 deletions library/cpp/charset/codepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#include <util/generic/hash.h>
#include <string>

#include <util/generic/hash_set.h>
#include <util/generic/singleton.h>
#include <util/generic/yexception.h>
#include <util/memory/pool.h>

#include <cstring>
#include <unordered_set>

#include <ctype.h>

Expand Down Expand Up @@ -202,7 +202,7 @@ ECharset CharsetByNameOrDie(std::string_view name) {
}

namespace {
class THashSetType: public THashSet<std::string> {
class THashSetType: public std::unordered_set<std::string> {
public:
inline void Add(const std::string& s) {
insert(s);
Expand Down
4 changes: 2 additions & 2 deletions library/cpp/charset/wide_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

#include <util/charset/utf8.h>
#include <util/digest/numeric.h>
#include <util/generic/hash_set.h>

#include <algorithm>
#include <unordered_set>

namespace {
//! three UTF8 encoded russian letters (A, B, V)
Expand Down Expand Up @@ -346,7 +346,7 @@ void TConversionTest::TestRecode() {
if (!SingleByteCodepage(enc))
continue;

using THash = THashSet<char>;
using THash = std::unordered_set<char>;
THash hash;

for (int i = 0; i != 256; ++i) {
Expand Down
4 changes: 2 additions & 2 deletions library/cpp/cppparser/parser.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <util/generic/hash.h>
#include <util/string/cast.h>
#include <util/generic/hash_set.h>
#include <util/generic/yexception.h>
#include <unordered_set>

#include "parser.h"

Expand Down Expand Up @@ -558,7 +558,7 @@ void TCppSimpleSax::DoCode(const TText& text) {
}

class TCppFullSax::TImpl {
typedef THashSet<std::string> TKeyWords;
typedef std::unordered_set<std::string> TKeyWords;

class TRegExp {
public:
Expand Down
4 changes: 2 additions & 2 deletions library/cpp/dbg_output/dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#include <util/stream/format.h>
#include <util/system/type_name.h>
#include <util/generic/hash_set.h>
#include <utility>
#include <unordered_set>

/*
* std::cout << DbgDump(any) << std::endl;
Expand Down Expand Up @@ -59,7 +59,7 @@ namespace NPrivate {
}
}

THashSet<size_t> Visited;
std::unordered_set<size_t> Visited;
};
};

Expand Down
5 changes: 3 additions & 2 deletions library/cpp/dbg_output/dumpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <map>
#include <string>
#include <string_view>
#include <unordered_set>

//smart pointers
template <class T, class D>
Expand Down Expand Up @@ -139,11 +140,11 @@ struct TDumper<THashMultiMap<K, V, H, P, A>>: public TAssocDumper {
};

template <class T, class H, class P, class A>
struct TDumper<THashSet<T, H, P, A>>: public TAssocDumper {
struct TDumper<std::unordered_set<T, H, P, A>>: public TAssocDumper {
};

template <class T, class H, class P, class A>
struct TDumper<THashMultiSet<T, H, P, A>>: public TAssocDumper {
struct TDumper<std::unordered_multiset<T, H, P, A>>: public TAssocDumper {
};

//strings
Expand Down
2 changes: 1 addition & 1 deletion library/cpp/getopt/small/completion_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ namespace NLastGetopt {
void TZshCompletionGenerator::GenerateOptCompletion(TFormattedOutput& out, const TOpts& opts, const TOpt& opt, NComp::TCompleterManager& manager) {
auto& line = L;

THashSet<std::string> disableOptions;
std::unordered_set<std::string> disableOptions;
if (opt.DisableCompletionForOptions_) {
disableOptions.insert("-");
} else {
Expand Down
19 changes: 12 additions & 7 deletions library/cpp/getopt/small/last_getopt_opt.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
#include "completer.h"
#include "last_getopt_handlers.h"

#include <util/generic/hash_set.h>
#include <util/generic/mapfindptr.h>
#include <util/string/join.h>
#include <util/string/subst.h>

#include <optional>
#include <unordered_set>
#include <utility>
#include <algorithm>
#include <functional>

namespace NLastGetopt {
enum EHasArg {
Expand Down Expand Up @@ -75,7 +80,7 @@ namespace NLastGetopt {
TdOptVal OptionalValue_;
TdOptVal DefaultValue_;
TOptHandlers Handlers_;
THashSet<std::string> Choices_;
std::unordered_set<std::string> Choices_;

public:
/**
Expand Down Expand Up @@ -703,7 +708,7 @@ namespace NLastGetopt {

// Appends FromString<T>(arg) to *target for each argument
template <typename T>
TOpt& InsertTo(THashSet<T>* target) {
TOpt& InsertTo(std::unordered_set<T>* target) {
return Handler1T<T>([target](auto&& value) { target->insert(std::forward<decltype(value)>(value)); });
}

Expand Down Expand Up @@ -742,11 +747,11 @@ namespace NLastGetopt {

template <typename TIterator>
TOpt& Choices(TIterator begin, TIterator end) {
return Choices(THashSet<typename TIterator::value_type>{begin, end});
return Choices(std::unordered_set<typename TIterator::value_type>{begin, end});
}

template <typename TValue>
TOpt& Choices(THashSet<TValue> choices) {
TOpt& Choices(std::unordered_set<TValue> choices) {
Choices_ = std::move(choices);
return Handler1T<TValue>(
[this] (const TValue& arg) {
Expand All @@ -759,15 +764,15 @@ namespace NLastGetopt {

TOpt& Choices(std::vector<std::string> choices) {
return Choices(
THashSet<std::string>{
std::unordered_set<std::string>{
std::make_move_iterator(choices.begin()),
std::make_move_iterator(choices.end())
});
}

TOpt& ChoicesWithCompletion(std::vector<NComp::TChoice> choices) {
Completer(NComp::Choice(choices));
THashSet<std::string> choicesSet;
std::unordered_set<std::string> choicesSet;
choicesSet.reserve(choices.size());
for (const auto& choice : choices) {
choicesSet.insert(choice.Choice);
Expand Down
2 changes: 1 addition & 1 deletion library/cpp/getopt/small/last_getopt_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace NLastGetopt {
std::string_view CurrentValue_; // the value of the last met argument (corresponding to CurrentOpt_)

private:
typedef THashSet<const TOpt*> TdOptSet;
typedef std::unordered_set<const TOpt*> TdOptSet;
TdOptSet OptsSeen_; //the set of options that have been met during parsing

std::list<const TOpt*> OptsDefault_;
Expand Down
4 changes: 2 additions & 2 deletions library/cpp/http/io/compression_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <library/cpp/testing/unittest/tests_data.h>

#include <util/stream/zlib.h>
#include <util/generic/hash_set.h>
#include <unordered_set>

Y_UNIT_TEST_SUITE(THttpCompressionTest) {
static const std::string DATA = "I'm a teapot";
Expand Down Expand Up @@ -45,7 +45,7 @@ Y_UNIT_TEST_SUITE(THttpCompressionTest) {
}

Y_UNIT_TEST(TestChooseBestCompressionScheme) {
THashSet<std::string> accepted;
std::unordered_set<std::string> accepted;

auto checkAccepted = [&accepted](const std::string& v) {
return accepted.contains(v);
Expand Down
4 changes: 2 additions & 2 deletions library/cpp/http/io/stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include <util/string/strip.h>

#include <util/generic/hash_set.h>
#include <unordered_set>

#define HEADERCMP(header, str) \
case sizeof(str) - 1: \
Expand Down Expand Up @@ -129,7 +129,7 @@ namespace {
}

class THttpInput::TImpl {
typedef THashSet<std::string> TAcceptCodings;
typedef std::unordered_set<std::string> TAcceptCodings;

public:
inline TImpl(IInputStream* slave)
Expand Down
6 changes: 3 additions & 3 deletions library/cpp/http/server/http_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) {

}

inline std::string ToString(const THashSet<std::string>& hs) {
inline std::string ToString(const std::unordered_set<std::string>& hs) {
std::string res = "";
for (auto s : hs) {
if (res) {
Expand Down Expand Up @@ -998,7 +998,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) {
UNIT_ASSERT(srv.Start());
UNIT_ASSERT(server.Lock.try_lock());

THashSet<std::string> results;
std::unordered_set<std::string> results;
std::mutex resultLock;
auto func = [port, &resultLock, &results]() {
try {
Expand All @@ -1016,6 +1016,6 @@ Y_UNIT_TEST_SUITE(THttpServerTest) {
server.Lock.unlock();
t1->Join();
t2->Join();
UNIT_ASSERT_EQUAL_C(results, (THashSet<std::string>({"Zoooo", "TTL Exceed"})), "Results is {" + ToString(results) + "}");
UNIT_ASSERT_EQUAL_C(results, (std::unordered_set<std::string>({"Zoooo", "TTL Exceed"})), "Results is {" + ToString(results) + "}");
}
}
4 changes: 2 additions & 2 deletions library/cpp/http/server/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <util/digest/numeric.h>
#include <util/network/ip.h>
#include <util/network/socket.h>
#include <util/generic/hash_set.h>
#include <util/generic/yexception.h>
#include <unordered_set>

using TAddr = THttpServerOptions::TAddr;

Expand All @@ -22,7 +22,7 @@ static inline TNetworkAddress ToNetworkAddr(const std::string& address, ui16 por
}

void THttpServerOptions::BindAddresses(TBindAddresses& ret) const {
THashSet<std::string> check;
std::unordered_set<std::string> check;

for (auto addr : BindSockaddr) {
if (!addr.Port) {
Expand Down
Loading