diff options
| author | YDBot <[email protected]> | 2026-01-19 13:18:00 +0000 |
|---|---|---|
| committer | YDBot <[email protected]> | 2026-01-19 13:18:00 +0000 |
| commit | 86c02de5b9473f00fac8272c98317bd2cb7bf5bf (patch) | |
| tree | 4ba09ffecbbf16425aace8d7bdb6442e47ada231 /library/cpp | |
| parent | 8bacd631b18c75674b9cbca9813492bb552c4ec4 (diff) | |
| parent | 45ba35987ae864f2fdc8af5e69a8a625c4912aee (diff) | |
Sync branches 260119-1316
Diffstat (limited to 'library/cpp')
| -rw-r--r-- | library/cpp/containers/ordered_map/ordered_map.h | 39 | ||||
| -rw-r--r-- | library/cpp/threading/skip_list/skiplist.h | 47 | ||||
| -rw-r--r-- | library/cpp/threading/skip_list/ya.make | 4 | ||||
| -rw-r--r-- | library/cpp/tld/tlds-alpha-by-domain.txt | 2 |
4 files changed, 41 insertions, 51 deletions
diff --git a/library/cpp/containers/ordered_map/ordered_map.h b/library/cpp/containers/ordered_map/ordered_map.h index 22422901a84..ac1fbd5b78d 100644 --- a/library/cpp/containers/ordered_map/ordered_map.h +++ b/library/cpp/containers/ordered_map/ordered_map.h @@ -137,19 +137,13 @@ namespace NOrderedMap { } template <class... TArgs> - iterator insert(TArgs&&... args) { + std::pair<iterator, bool> insert(TArgs&&... args) { auto& value = TBase::emplace_back(std::forward<TArgs>(args)...); auto [mapIt, ok] = Map_.try_emplace(&Traits::GetSortProjector(value), --TBase::end()); if (!ok) { - iterator forDeleteFromList = mapIt->second; - //TODO: it is possible to skip double-lookup if be possible to mutate key by iterator, or steal previous value by insert - Map_.erase(mapIt); - TBase::erase(forDeleteFromList); - auto insertRes = Map_.try_emplace(&Traits::GetSortProjector(value), --TBase::end()); - Y_ASSERT(insertRes.second); - return insertRes.first->second; + TBase::pop_back(); } - return mapIt->second; + return {mapIt->second, ok}; } template <class... TArgs> @@ -158,11 +152,9 @@ namespace NOrderedMap { auto [mapIt, ok] = Map_.try_emplace(&Traits::GetSortProjector(value), --TBase::end()); if (!ok) { iterator forDeleteFromList = mapIt->second; - //TODO: it is possible to skip double-lookup if be possible to mutate key by iterator, or steal previous value by insert - Map_.erase(mapIt); + mapIt->first.Data = &Traits::GetSortProjector(value); + mapIt->second = --TBase::end(); TBase::erase(forDeleteFromList); - bool isOk = Map_.try_emplace(&Traits::GetSortProjector(value), --TBase::end()).second; - Y_ASSERT(isOk); } return value; } @@ -234,7 +226,7 @@ namespace NOrderedMap { } clear(); SortBy(tmp, Traits::GetSortProjector); - for (auto& x : tmp) { + for (auto&& x : std::move(tmp)) { emplace_back(std::move(x)); } } @@ -261,22 +253,35 @@ namespace NOrderedMap { } private: + struct TPtrBackdoorKey { + mutable const TKey* Data; + TPtrBackdoorKey(const TKey* x) : Data(x) {} + TPtrBackdoorKey(TPtrBackdoorKey&&) = default; + TPtrBackdoorKey(const TPtrBackdoorKey&) = default; + + const TKey& operator*() const { + return *Data; + } + operator bool() const { + return !!Data; + } + }; struct THashOperationsForPtr : public THash<TKey>, public TEqualTo<TKey> { using THashBase = THash<TKey>; using TEqualBase = TEqualTo<TKey>; template<class TKeyTransparency> - inline size_t operator()(const TKeyTransparency* ptr) const noexcept { + inline size_t operator()(const TKeyTransparency& ptr) const noexcept { Y_DEBUG_ABORT_UNLESS(ptr); return this->THashBase::operator()(*ptr); } template<class TKeyTransparencyA, class TKeyTransparencyB> - inline bool operator()(const TKeyTransparencyA* a, const TKeyTransparencyB* b) const noexcept { + inline bool operator()(const TKeyTransparencyA& a, const TKeyTransparencyB& b) const noexcept { Y_DEBUG_ABORT_UNLESS(a); Y_DEBUG_ABORT_UNLESS(b); return this->TEqualBase::operator()(*a, *b); } }; - THashMap<const TKey*, typename TBase::iterator, THashOperationsForPtr, THashOperationsForPtr> Map_{}; + THashMap<TPtrBackdoorKey, typename TBase::iterator, THashOperationsForPtr, THashOperationsForPtr> Map_{}; }; template <class TKey, class TValue> diff --git a/library/cpp/threading/skip_list/skiplist.h b/library/cpp/threading/skip_list/skiplist.h index f60c7cc97c3..bbdde8f8aea 100644 --- a/library/cpp/threading/skip_list/skiplist.h +++ b/library/cpp/threading/skip_list/skiplist.h @@ -7,7 +7,8 @@ #include <util/generic/typetraits.h> #include <util/memory/pool.h> #include <util/random/random.h> -#include <library/cpp/deprecated/atomic/atomic.h> + +#include <atomic> namespace NThreading { //////////////////////////////////////////////////////////////////////////////// @@ -29,7 +30,6 @@ namespace NThreading { //////////////////////////////////////////////////////////////////////////////// class TSizeCounter { - private: size_t Size; public: @@ -73,9 +73,8 @@ namespace NThreading { int Branching = 4> class TSkipList: public TCounter, private TNonCopyable { class TNode { - private: T Value; // should be immutable after insert - TNode* Next[]; // variable-size array maximum of MaxHeight values + std::atomic<TNode*> Next[]; // variable-size array maximum of MaxHeight values public: TNode(T&& value) @@ -93,30 +92,24 @@ namespace NThreading { } TNode* GetNext(int height) const { - return AtomicGet(Next[height]); + return Next[height].load(); } - void Link(int height, TNode** prev) { + void Link(const int height, TNode** prev) { for (int i = 0; i < height; ++i) { - Next[i] = prev[i]->Next[i]; - AtomicSet(prev[i]->Next[i], this); + Next[i].store(prev[i]->Next[i]); + prev[i]->Next[i] = this; } } }; public: class TIterator { - private: - const TSkipList* List; - const TNode* Node; + const TSkipList* List = nullptr; + const TNode* Node = nullptr; public: - TIterator() - : List(nullptr) - , Node(nullptr) - { - } - + TIterator() noexcept = default; TIterator(const TSkipList* list, const TNode* node) : List(list) , Node(node) @@ -129,11 +122,7 @@ namespace NThreading { { } - TIterator& operator=(const TIterator& other) { - List = other.List; - Node = other.Node; - return *this; - } + TIterator& operator=(const TIterator& other) = default; void Next() { Node = Node ? Node->GetNext(0) : nullptr; @@ -166,7 +155,7 @@ namespace NThreading { TComparer Comparer; TNode* Head; - TAtomic Height; + std::atomic<int> Height; TCounter Counter; TNode* Prev[MaxHeight]; @@ -290,7 +279,7 @@ namespace NThreading { TNode* FindLast() const { TNode* node = Head; - int height = AtomicGet(Height) - 1; + int height = Height.load() - 1; while (true) { TNode* next = node->GetNext(height); @@ -315,7 +304,7 @@ namespace NThreading { template <typename TValue> TNode* FindLessThan(const TValue& value, TNode** links) const { TNode* node = Head; - int height = AtomicGet(Height) - 1; + int height = Height.load() - 1; TNode* prev = nullptr; while (true) { @@ -345,7 +334,7 @@ namespace NThreading { template <typename TValue> TNode* FindGreaterThanOrEqual(const TValue& value) const { TNode* node = Head; - int height = AtomicGet(Height) - 1; + int height = Height.load() - 1; TNode* prev = nullptr; while (true) { @@ -384,14 +373,14 @@ namespace NThreading { TNode* DoInsert(T&& value) { // choose level to place new node - int currentHeight = AtomicGet(Height); - int height = RandomHeight(); + const int currentHeight = Height.load(); + const int height = RandomHeight(); if (height > currentHeight) { for (int i = currentHeight; i < height; ++i) { // head should link to all levels Prev[i] = Head; } - AtomicSet(Height, height); + Height.store(height); } TNode* node = AllocateNode(std::move(value), height); diff --git a/library/cpp/threading/skip_list/ya.make b/library/cpp/threading/skip_list/ya.make index 0c3f91046ea..a63cb48eb8e 100644 --- a/library/cpp/threading/skip_list/ya.make +++ b/library/cpp/threading/skip_list/ya.make @@ -4,10 +4,6 @@ SRCS( skiplist.cpp ) -PEERDIR( - library/cpp/deprecated/atomic -) - END() RECURSE( diff --git a/library/cpp/tld/tlds-alpha-by-domain.txt b/library/cpp/tld/tlds-alpha-by-domain.txt index b3707ac93ce..b31b8a662e2 100644 --- a/library/cpp/tld/tlds-alpha-by-domain.txt +++ b/library/cpp/tld/tlds-alpha-by-domain.txt @@ -1,4 +1,4 @@ -# Version 2026011300, Last Updated Tue Jan 13 07:07:01 2026 UTC +# Version 2026011600, Last Updated Fri Jan 16 07:07:01 2026 UTC AAA AARP ABB |
