Skip to content

Issue #57 Replace TSet to std::set #248

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 1 commit into from
Jun 20, 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
6 changes: 0 additions & 6 deletions include/ydb-cpp-sdk/util/generic/fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ template <class TValue, class TCmp>
class TRbTree;

//containers
template <class K, class L = TLess<K>, class A = std::allocator<K>>
class TSet;

template <class K, class L = TLess<K>, class A = std::allocator<K>>
class TMultiSet;

template <class T, class S = std::deque<T>>
class TStack;

Expand Down
4 changes: 0 additions & 4 deletions include/ydb-cpp-sdk/util/ysaveload.h
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,6 @@ template <class T1, class T2, class T3, class T4, class T5>
class TSerializer<std::unordered_multimap<T1, T2, T3, T4, T5>>: public TMapSerializer<std::unordered_multimap<T1, T2, T3, T4, T5>, false> {
};

template <class K, class C, class A>
class TSerializer<TSet<K, C, A>>: public TSetSerializer<TSet<K, C, A>, true> {
};

template <class K, class C, class A>
class TSerializer<std::set<K, C, A>>: public TSetSerializer<std::set<K, C, A>, true> {
};
Expand Down
9 changes: 6 additions & 3 deletions src/library/cache/cache.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#pragma once

#include <ydb-cpp-sdk/util/str_stl.h>
#include <ydb-cpp-sdk/util/generic/algorithm.h>
#include <ydb-cpp-sdk/util/generic/ptr.h>
#include <src/util/generic/intrlist.h>
#include <ydb-cpp-sdk/util/generic/yexception.h>

#include <src/util/generic/intrlist.h>

#include <utility>
#include <unordered_set>

Expand Down Expand Up @@ -346,8 +349,8 @@ class TLWList {
}
};

struct TEqualTo {
using is_transparent = void;
struct TEqualTo {
using is_transparent = void;
bool operator()(const TItem& lhs, const TItem& rhs) const {
return lhs.Key == rhs.Key;
}
Expand Down
5 changes: 3 additions & 2 deletions src/library/dbg_output/dumpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <list>
#include <map>
#include <set>
#include <span>
#include <string>
#include <string_view>
Expand Down Expand Up @@ -126,11 +127,11 @@ struct TDumper<std::multimap<K, V, P, A>>: public TAssocDumper {
};

template <class T, class P, class A>
struct TDumper<TSet<T, P, A>>: public TAssocDumper {
struct TDumper<std::set<T, P, A>>: public TAssocDumper {
};

template <class T, class P, class A>
struct TDumper<TMultiSet<T, P, A>>: public TAssocDumper {
struct TDumper<std::multiset<T, P, A>>: public TAssocDumper {
};

template <class K, class V, class H, class P, class A>
Expand Down
15 changes: 8 additions & 7 deletions src/library/http/io/headers_ut.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <src/util/generic/set.h>
#include <ydb-cpp-sdk/library/http/io/headers.h>

#include <src/library/testing/unittest/registar.h>

#include <set>
#include <string>
#include <string_view>
#include <utility>

#include <src/library/http/io/headers.h>
#include <src/library/testing/unittest/registar.h>

namespace {
class THeadersExistence {
public:
Expand All @@ -29,7 +30,7 @@ namespace {
}

private:
typedef TMultiSet<std::pair<std::string, std::string>> TImpl;
using TImpl = std::multiset<std::pair<std::string, std::string>>;
TImpl Impl;
};
}
Expand All @@ -53,8 +54,8 @@ class THttpHeadersTest: public TTestBase {
UNIT_TEST_SUITE_END();

private:
typedef void (*TAddHeaderFunction)(THttpHeaders&, std::string_view name, std::string_view value);
typedef void (*TAddOrReplaceHeaderFunction)(THttpHeaders&, std::string_view name, std::string_view value);
using TAddHeaderFunction = void (*)(THttpHeaders&, std::string_view name, std::string_view value);
using TAddOrReplaceHeaderFunction = void (*)(THttpHeaders&, std::string_view name, std::string_view value);

public:
void TestAddOperation1Arg();
Expand Down
9 changes: 5 additions & 4 deletions src/library/monlib/encode/json/json_ut.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#include <ydb-cpp-sdk/library/monlib/encode/json/json.h>

#include <src/library/monlib/encode/protobuf/protobuf.h>
#include <ydb-cpp-sdk/library/monlib/metrics/labels.h>

#include <ydb-cpp-sdk/library/json/json_reader.h>
#include <ydb-cpp-sdk/library/resource/resource.h>
#include <src/library/testing/unittest/registar.h>

#include <ydb-cpp-sdk/util/stream/str.h>
#include <ydb-cpp-sdk/util/string/builder.h>

#include <src/library/monlib/encode/protobuf/protobuf.h>
#include <src/library/testing/unittest/registar.h>

#include <iostream>
#include <limits>

Expand All @@ -25,8 +26,8 @@ namespace {
void AssertLabels(const NProto::TMultiSample& actual, const TLabels& expected) {
UNIT_ASSERT_EQUAL(actual.LabelsSize(), expected.Size());

TSet<TLabel> actualSet;
TSet<TLabel> expectedSet;
std::set<TLabel> actualSet;
std::set<TLabel> expectedSet;
Transform(expected.begin(), expected.end(), std::inserter(expectedSet, expectedSet.end()), [] (auto&& l) {
return TLabel{l.Name(), l.Value()};
});
Expand Down
24 changes: 12 additions & 12 deletions src/library/object_factory/object_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

#include <ydb-cpp-sdk/util/system/guard.h>
#include <ydb-cpp-sdk/util/system/rwlock.h>
#include <src/util/generic/set.h>
#include <ydb-cpp-sdk/util/generic/singleton.h>
#include <ydb-cpp-sdk/util/generic/yexception.h>

#include <algorithm>
#include <set>
#include <map>

namespace NObjectFactory {
Expand Down Expand Up @@ -51,8 +51,8 @@ namespace NObjectFactory {
template <class P, class K, class... TArgs>
class IObjectFactory {
public:
typedef P TProduct;
typedef K TKey;
using TProduct = P;
using TKey = K;

public:
template <class TDerivedProduct>
Expand All @@ -70,7 +70,7 @@ namespace NObjectFactory {
Register<TDerivedProduct>(key, new TFactoryObjectCreator<TProduct, TDerivedProduct, TArgs...>);
}

void GetKeys(TSet<TKey>& keys) const {
void GetKeys(std::set<TKey>& keys) const {
TReadGuard guard(CreatorsLock);
keys.clear();
for (typename ICreators::const_iterator i = Creators.begin(), e = Creators.end(); i != e; ++i) {
Expand All @@ -93,8 +93,8 @@ namespace NObjectFactory {
}

private:
typedef TSimpleSharedPtr<IFactoryObjectCreator<TProduct, TArgs...>> ICreatorPtr;
typedef std::map<TKey, ICreatorPtr> ICreators;
using ICreatorPtr = TSimpleSharedPtr<IFactoryObjectCreator<TProduct, TArgs...>>;
using ICreators = std::map<TKey, ICreatorPtr>;
ICreators Creators;
TRWMutex CreatorsLock;
};
Expand Down Expand Up @@ -139,20 +139,20 @@ namespace NObjectFactory {
return THolder<TProduct>(Construct(std::forward<Args>(args)...));
}

static void GetRegisteredKeys(TSet<TKey>& keys) {
static void GetRegisteredKeys(std::set<TKey>& keys) {
return Singleton<TParametrizedObjectFactory<TProduct, TKey, TArgs...>>()->GetKeys(keys);
}

static TSet<TKey> GetRegisteredKeys() {
TSet<TKey> keys;
static std::set<TKey> GetRegisteredKeys() {
std::set<TKey> keys;
Singleton<TParametrizedObjectFactory<TProduct, TKey, TArgs...>>()->GetKeys(keys);
return keys;
}

template <class TDerivedProduct>
static TSet<TKey> GetRegisteredKeys() {
TSet<TKey> registeredKeys(GetRegisteredKeys());
TSet<TKey> fileredKeys;
static std::set<TKey> GetRegisteredKeys() {
std::set<TKey> registeredKeys(GetRegisteredKeys());
std::set<TKey> fileredKeys;
std::copy_if(registeredKeys.begin(), registeredKeys.end(), std::inserter(fileredKeys, fileredKeys.end()), [](const TKey& key) {
THolder<TProduct> objectHolder(Construct(key));
return !!dynamic_cast<const TDerivedProduct*>(objectHolder.Get());
Expand Down
14 changes: 8 additions & 6 deletions src/library/testing/unittest/registar.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#include "registar.h"

#include <src/library/diff/diff.h>
#include <src/library/colorizer/colors.h>

#include <ydb-cpp-sdk/util/generic/bt_exception.h>
#include <src/util/random/fast.h>
#include <ydb-cpp-sdk/util/system/backtrace.h>
#include <ydb-cpp-sdk/util/system/guard.h>
#include <src/util/system/tls.h>
#include <ydb-cpp-sdk/util/system/error.h>
#include <ydb-cpp-sdk/util/string/cast.h>

#include <src/util/random/fast.h>
#include <src/util/system/tls.h>

#include <src/library/diff/diff.h>
#include <src/library/colorizer/colors.h>

#include <set>
#include <mutex>

using namespace std::string_literals;
Expand Down Expand Up @@ -472,7 +474,7 @@ unsigned NUnitTest::TTestFactory::Execute() {
Items_.QuickSort(TCmp());
Processor_->Start();

TSet<std::string> types;
std::set<std::string> types;
size_t cnt = 0;

for (TIntrusiveList<ITestBaseFactory>::TIterator factory = Items_.Begin(); factory != Items_.End(); ++factory) {
Expand Down
19 changes: 9 additions & 10 deletions src/library/testing/unittest/registar.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
#pragma once

#include <src/library/dbg_output/dump.h>

#include <ydb-cpp-sdk/util/generic/bt_exception.h>
#include <src/util/generic/intrlist.h>
#include <ydb-cpp-sdk/util/generic/ptr.h>
#include <src/util/generic/scope.h>
#include <src/util/generic/set.h>
#include <ydb-cpp-sdk/util/generic/typetraits.h>

#include <ydb-cpp-sdk/util/generic/yexception.h>

#include <ydb-cpp-sdk/util/string/builder.h>
Expand All @@ -19,8 +13,13 @@
#include <ydb-cpp-sdk/util/system/spinlock.h>
#include <ydb-cpp-sdk/util/system/src_location.h>

#include <src/util/generic/intrlist.h>
#include <src/util/generic/scope.h>

#include <src/util/system/rusage.h>

#include <src/library/dbg_output/dump.h>

#include <cmath>
#include <span>
#include <cstdio>
Expand Down Expand Up @@ -266,7 +265,7 @@ namespace NUnitTest {
};

#define UNIT_TEST_SUITE(N) \
typedef N TThisUnitTestSuite; \
using TThisUnitTestSuite = N; \
\
public: \
static std::string StaticName() noexcept { \
Expand All @@ -282,7 +281,7 @@ private: \
this->AtStart();

#define UNIT_TEST_SUITE_DEMANGLE(N) \
typedef N TThisUnitTestSuite; \
using TThisUnitTestSuite = N; \
\
public: \
static std::string StaticName() noexcept { \
Expand Down Expand Up @@ -1022,8 +1021,8 @@ public: \
}; \
class TCurrentTest: public T { \
private: \
typedef std::function<THolder<NUnitTest::TBaseTestCase>()> TTestCaseFactory; \
typedef std::vector<TTestCaseFactory> TTests; \
using TTestCaseFactory = std::function<THolder<NUnitTest::TBaseTestCase>()>; \
using TTests = std::vector<TTestCaseFactory>; \
\
static TTests& Tests() { \
static TTests tests; \
Expand Down
6 changes: 3 additions & 3 deletions src/library/threading/chunk_queue/queue_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <src/library/testing/unittest/registar.h>

#include <src/util/generic/set.h>
#include <set>

namespace NThreading {
////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -136,7 +136,7 @@ UNIT_ASSERT(!queue.Dequeue(result));
}

Y_UNIT_TEST(ShouldReturnEntries) {
TSet<int> items = {1, 2, 3};
std::set<int> items = {1, 2, 3};

TRelaxedManyOneQueue<int> queue;
for (int item : items) {
Expand Down Expand Up @@ -173,7 +173,7 @@ UNIT_ASSERT(!queue.Dequeue(result));
}

Y_UNIT_TEST(ShouldReturnEntries) {
TSet<int> items = {1, 2, 3};
std::set<int> items = {1, 2, 3};

TRelaxedManyManyQueue<int> queue;
for (int item : items) {
Expand Down
1 change: 0 additions & 1 deletion src/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ target_joined_source(yutil
${YDB_SDK_SOURCE_DIR}/src/util/generic/ptr.cpp
${YDB_SDK_SOURCE_DIR}/src/util/generic/refcount.cpp
${YDB_SDK_SOURCE_DIR}/src/util/generic/scope.cpp
${YDB_SDK_SOURCE_DIR}/src/util/generic/set.cpp
${YDB_SDK_SOURCE_DIR}/src/util/generic/singleton.cpp
${YDB_SDK_SOURCE_DIR}/src/util/generic/size_literals.cpp
${YDB_SDK_SOURCE_DIR}/src/util/generic/stack.cpp
Expand Down
10 changes: 6 additions & 4 deletions src/util/generic/algorithm_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <ydb-cpp-sdk/util/generic/algorithm.h>

#include <set>

static auto isOne = [](char c) { return c == '1'; };

Y_UNIT_TEST_SUITE(TAlgorithm) {
Expand Down Expand Up @@ -289,13 +291,13 @@ Y_UNIT_TEST_SUITE(TAlgorithm) {
EraseNodesIf(multiMap, [](auto p) { return p.first >= 2; });
UNIT_ASSERT_EQUAL(multiMap, expectedMultiMap);

TSet<int> set{1, 2, 3, 4, 5, 6, 7};
TSet<int> expectedSet{1, 3, 5, 7};
std::set<int> set{1, 2, 3, 4, 5, 6, 7};
std::set<int> expectedSet{1, 3, 5, 7};
EraseNodesIf(set, [](int i) { return i % 2 == 0; });
UNIT_ASSERT_EQUAL(set, expectedSet);

TMultiSet<int> multiSet{1, 1, 2, 3, 4, 4, 4, 5, 5, 5, 6, 7};
TMultiSet<int> expectedMultiSet{1, 1, 3, 5, 5, 5, 7};
std::multiset<int> multiSet{1, 1, 2, 3, 4, 4, 4, 5, 5, 5, 6, 7};
std::multiset<int> expectedMultiSet{1, 1, 3, 5, 5, 5, 7};
EraseNodesIf(multiSet, [](int i) { return i % 2 == 0; });
UNIT_ASSERT_EQUAL(multiSet, expectedMultiSet);

Expand Down
4 changes: 2 additions & 2 deletions src/util/generic/is_in_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ Y_UNIT_TEST_SUITE(TIsIn) {
TestIsInWithCont<std::unordered_map<std::string, std::string>>(std::make_pair("found", "1"));
TestIsInWithCont<std::unordered_multimap<std::string, std::string>>(std::make_pair("found", "1"));

TestIsInWithCont<TSet<std::string>>("found");
TestIsInWithCont<TMultiSet<std::string>>("found");
TestIsInWithCont<std::set<std::string>>("found");
TestIsInWithCont<std::multiset<std::string>>("found");
TestIsInWithCont<std::unordered_set<std::string>>("found");
TestIsInWithCont<std::unordered_multiset<std::string>>("found");

Expand Down
1 change: 0 additions & 1 deletion src/util/generic/set.cpp

This file was deleted.

Loading
Loading