diff options
author | Ruslan Kovalev <ruslan.a.kovalev@gmail.com> | 2022-02-10 16:46:45 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:45 +0300 |
commit | 9123176b341b6f2658cff5132482b8237c1416c8 (patch) | |
tree | 49e222ea1c5804306084bb3ae065bb702625360f /library/cpp/containers | |
parent | 59e19371de37995fcb36beb16cd6ec030af960bc (diff) | |
download | ydb-9123176b341b6f2658cff5132482b8237c1416c8.tar.gz |
Restoring authorship annotation for Ruslan Kovalev <ruslan.a.kovalev@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/containers')
25 files changed, 380 insertions, 380 deletions
diff --git a/library/cpp/containers/atomizer/atomizer.h b/library/cpp/containers/atomizer/atomizer.h index f3dbbad788..5e40f47ab9 100644 --- a/library/cpp/containers/atomizer/atomizer.h +++ b/library/cpp/containers/atomizer/atomizer.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include <library/cpp/containers/str_map/str_map.h> diff --git a/library/cpp/containers/compact_vector/compact_vector.h b/library/cpp/containers/compact_vector/compact_vector.h index e7f4bfc54d..dbe7473f0c 100644 --- a/library/cpp/containers/compact_vector/compact_vector.h +++ b/library/cpp/containers/compact_vector/compact_vector.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include <util/generic/yexception.h> #include <util/generic/utility.h> diff --git a/library/cpp/containers/comptrie/array_with_size.h b/library/cpp/containers/comptrie/array_with_size.h index 267692b8bc..36e61c7410 100644 --- a/library/cpp/containers/comptrie/array_with_size.h +++ b/library/cpp/containers/comptrie/array_with_size.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include <util/generic/ptr.h> #include <util/generic/noncopyable.h> diff --git a/library/cpp/containers/comptrie/comptrie.h b/library/cpp/containers/comptrie/comptrie.h index b9a4c65280..f77024327e 100644 --- a/library/cpp/containers/comptrie/comptrie.h +++ b/library/cpp/containers/comptrie/comptrie.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once -#include "comptrie_trie.h" -#include "comptrie_builder.h" +#include "comptrie_trie.h" +#include "comptrie_builder.h" diff --git a/library/cpp/containers/comptrie/comptrie_builder.h b/library/cpp/containers/comptrie/comptrie_builder.h index 8254c4f592..cf7d2e39a3 100644 --- a/library/cpp/containers/comptrie/comptrie_builder.h +++ b/library/cpp/containers/comptrie/comptrie_builder.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "comptrie_packer.h" #include "minimize.h" @@ -17,7 +17,7 @@ // then all the keys that we add between these two also have the same prefix. // Actually in this mode the builder can accept even more freely ordered input, // but for input as above it is guaranteed to work. -enum ECompactTrieBuilderFlags { +enum ECompactTrieBuilderFlags { CTBF_NONE = 0, CTBF_PREFIX_GROUPED = 1 << 0, CTBF_VERBOSE = 1 << 1, @@ -25,7 +25,7 @@ enum ECompactTrieBuilderFlags { }; using TCompactTrieBuilderFlags = ECompactTrieBuilderFlags; - + inline TCompactTrieBuilderFlags operator|(TCompactTrieBuilderFlags first, TCompactTrieBuilderFlags second) { return static_cast<TCompactTrieBuilderFlags>(static_cast<int>(first) | second); } @@ -51,13 +51,13 @@ public: // All Add.. methods return true if it was a new key, false if the key already existed. bool Add(const TSymbol* key, size_t keylen, const TData& value); - bool Add(const TKeyBuf& key, const TData& value) { + bool Add(const TKeyBuf& key, const TData& value) { return Add(key.data(), key.size(), value); } // add already serialized data bool AddPtr(const TSymbol* key, size_t keylen, const char* data); - bool AddPtr(const TKeyBuf& key, const char* data) { + bool AddPtr(const TKeyBuf& key, const char* data) { return AddPtr(key.data(), key.size(), data); } @@ -88,8 +88,8 @@ public: return Save(out); } - void Clear(); // Returns all memory to the system and resets the builder state. - + void Clear(); // Returns all memory to the system and resets the builder state. + size_t GetEntryCount() const; size_t GetNodeCount() const; @@ -98,7 +98,7 @@ public: return Impl->MeasureByteSize(); } -protected: +protected: class TCompactTrieBuilderImpl; THolder<TCompactTrieBuilderImpl> Impl; }; @@ -133,12 +133,12 @@ size_t CompactTrieMinimize(IOutputStream& os, const TTrieBuilder& builder, bool // by Maxim Babenko and Ivan Puzyrevsky. The difference is that when we cut the tree into levels // two nodes connected by a forward link are put into the same level (because they usually lie near each other in the original tree). // The original paper (describing the layout in Section 2.1) is: -// Michael A. Bender, Erik D. Demaine, Martin Farach-Colton. Cache-Oblivious B-Trees -// SIAM Journal on Computing, volume 35, number 2, 2005, pages 341-358. +// Michael A. Bender, Erik D. Demaine, Martin Farach-Colton. Cache-Oblivious B-Trees +// SIAM Journal on Computing, volume 35, number 2, 2005, pages 341-358. // Available on the web: http://erikdemaine.org/papers/CacheObliviousBTrees_SICOMP/ -// Or: Michael A. Bender, Erik D. Demaine, and Martin Farach-Colton. Cache-Oblivious B-Trees -// Proceedings of the 41st Annual Symposium -// on Foundations of Computer Science (FOCS 2000), Redondo Beach, California, November 12-14, 2000, pages 399-409. +// Or: Michael A. Bender, Erik D. Demaine, and Martin Farach-Colton. Cache-Oblivious B-Trees +// Proceedings of the 41st Annual Symposium +// on Foundations of Computer Science (FOCS 2000), Redondo Beach, California, November 12-14, 2000, pages 399-409. // Available on the web: http://erikdemaine.org/papers/FOCS2000b/ // (there is not much difference between these papers, actually). // diff --git a/library/cpp/containers/comptrie/comptrie_builder.inl b/library/cpp/containers/comptrie/comptrie_builder.inl index ea151b946e..f273fa6571 100644 --- a/library/cpp/containers/comptrie/comptrie_builder.inl +++ b/library/cpp/containers/comptrie/comptrie_builder.inl @@ -1,6 +1,6 @@ -#pragma once +#pragma once -#include "comptrie_impl.h" +#include "comptrie_impl.h" #include "comptrie_trie.h" #include "make_fast_layout.h" #include "array_with_size.h" @@ -26,7 +26,7 @@ template <class T, class D, class S> class TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl { -protected: +protected: TMemoryPool Pool; size_t PayloadSize; THolder<TFixedSizeAllocator> NodeAllocator; @@ -45,7 +45,7 @@ protected: DATA_IN_MEMPOOL, }; -protected: +protected: void ConvertSymbolArrayToChar(const TSymbol* key, size_t keylen, TTempBuf& buf, size_t ckeylen) const; void NodeLinkTo(TNode* thiz, const TBlob& label, TNode* node); TNode* NodeForwardAdd(TNode* thiz, const char* label, size_t len, size_t& passed, size_t* nodeCount); @@ -335,10 +335,10 @@ public: union { char ArcsData[CONSTEXPR_MAX3(sizeof(TArcSet), sizeof(TBufferedSubtree), sizeof(TSubtreeInFile))]; - union { - void* Data1; - long long int Data2; - } Aligner; + union { + void* Data1; + long long int Data2; + } Aligner; }; inline ISubtree* Subtree() { @@ -451,7 +451,7 @@ bool TCompactTrieBuilder<T, D, S>::Find(const TSymbol* key, size_t keylen, TData } template <class T, class D, class S> -bool TCompactTrieBuilder<T, D, S>::FindLongestPrefix( +bool TCompactTrieBuilder<T, D, S>::FindLongestPrefix( const TSymbol* key, size_t keylen, size_t* prefixlen, TData* value) const { return Impl->FindLongestPrefix(key, keylen, prefixlen, value); } @@ -502,8 +502,8 @@ TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::~TCompactTrieBuilderImpl( } template <class T, class D, class S> -void TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::ConvertSymbolArrayToChar( - const TSymbol* key, size_t keylen, TTempBuf& buf, size_t buflen) const { +void TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::ConvertSymbolArrayToChar( + const TSymbol* key, size_t keylen, TTempBuf& buf, size_t buflen) const { char* ckeyptr = buf.Data(); for (size_t i = 0; i < keylen; ++i) { @@ -544,7 +544,7 @@ void TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::NodeReleasePayload(T template <class T, class D, class S> bool TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::AddEntry( - const TSymbol* key, size_t keylen, const TData& value) { + const TSymbol* key, size_t keylen, const TData& value) { size_t datalen = Packer.MeasureLeaf(value); bool isNewAddition = false; @@ -555,7 +555,7 @@ bool TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::AddEntry( template <class T, class D, class S> bool TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::AddEntryPtr( - const TSymbol* key, size_t keylen, const char* value) { + const TSymbol* key, size_t keylen, const char* value) { size_t datalen = Packer.SkipLeaf(value); bool isNewAddition = false; @@ -597,8 +597,8 @@ bool TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::AddSubtreeInBuffer( } template <class T, class D, class S> -typename TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::TNode* - TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::AddEntryForSomething( +typename TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::TNode* + TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::AddEntryForSomething( const TSymbol* key, size_t keylen, bool& isNewAddition) { using namespace NCompactTrie; @@ -684,7 +684,7 @@ bool TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::FindEntryImpl(const } template <class T, class D, class S> -bool TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::FindLongestPrefix( +bool TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::FindLongestPrefix( const TSymbol* key, size_t keylen, size_t* prefixlen, TData* value) const { using namespace NCompactTrie; @@ -778,8 +778,8 @@ size_t TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::GetNodeCount() con } template <class T, class D, class S> -typename TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::TNode* - TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::NodeForwardAdd( +typename TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::TNode* + TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::NodeForwardAdd( TNode* thiz, const char* label, size_t len, size_t& passed, size_t* nodeCount) { typename TNode::TArcSet* arcSet = dynamic_cast<typename TNode::TArcSet*>(thiz->Subtree()); if (!arcSet) @@ -892,8 +892,8 @@ TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::TArc::TArc(const TBlob& l {} template <class T, class D, class S> -ui64 TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::ArcMeasure( - const TArc* thiz, size_t leftsize, size_t rightsize) const { +ui64 TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::ArcMeasure( + const TArc* thiz, size_t leftsize, size_t rightsize) const { using namespace NCompactTrie; size_t coresize = 2 + NodeMeasureLeafValue(thiz->Node); // 2 == (char + flags) @@ -978,8 +978,8 @@ ui64 TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::ArcSaveAndDestroy(co // TCompactTrieBuilder::TCompactTrieBuilderImpl::TNode::TArcSet template <class T, class D, class S> -typename TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::TNode::TArcSet::iterator - TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::TNode::TArcSet::Find(char ch) { +typename TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::TNode::TArcSet::iterator + TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::TNode::TArcSet::Find(char ch) { using namespace NCompTriePrivate; iterator it = LowerBound(this->begin(), this->end(), ch, TCmp()); @@ -1083,12 +1083,12 @@ size_t CompactTrieMinimize(IOutputStream& os, const TTrieBuilder& builder, bool // by Maxim Babenko and Ivan Puzyrevsky. The difference is that when we cut the tree into levels // two nodes connected by a forward link are put into the same level (because they usually lie near each other in the original tree). // The original paper (describing the layout in Section 2.1) is: -// Michael A. Bender, Erik D. Demaine, Martin Farach-Colton. Cache-Oblivious B-Trees -// SIAM Journal on Computing, volume 35, number 2, 2005, pages 341-358. +// Michael A. Bender, Erik D. Demaine, Martin Farach-Colton. Cache-Oblivious B-Trees +// SIAM Journal on Computing, volume 35, number 2, 2005, pages 341-358. // Available on the web: http://erikdemaine.org/papers/CacheObliviousBTrees_SICOMP/ -// Or: Michael A. Bender, Erik D. Demaine, and Martin Farach-Colton. Cache-Oblivious B-Trees -// Proceedings of the 41st Annual Symposium -// on Foundations of Computer Science (FOCS 2000), Redondo Beach, California, November 12-14, 2000, pages 399-409. +// Or: Michael A. Bender, Erik D. Demaine, and Martin Farach-Colton. Cache-Oblivious B-Trees +// Proceedings of the 41st Annual Symposium +// on Foundations of Computer Science (FOCS 2000), Redondo Beach, California, November 12-14, 2000, pages 399-409. // Available on the web: http://erikdemaine.org/papers/FOCS2000b/ // (there is not much difference between these papers, actually). // diff --git a/library/cpp/containers/comptrie/comptrie_impl.h b/library/cpp/containers/comptrie/comptrie_impl.h index 37e5fa6221..f41c38311a 100644 --- a/library/cpp/containers/comptrie/comptrie_impl.h +++ b/library/cpp/containers/comptrie/comptrie_impl.h @@ -1,11 +1,11 @@ -#pragma once +#pragma once #include <util/stream/output.h> -#ifndef COMPTRIE_DATA_CHECK -#define COMPTRIE_DATA_CHECK 1 -#endif - +#ifndef COMPTRIE_DATA_CHECK +#define COMPTRIE_DATA_CHECK 1 +#endif + // NCompactTrie namespace NCompactTrie { diff --git a/library/cpp/containers/comptrie/comptrie_trie.h b/library/cpp/containers/comptrie/comptrie_trie.h index 5049be2831..40ec1e52b3 100644 --- a/library/cpp/containers/comptrie/comptrie_trie.h +++ b/library/cpp/containers/comptrie/comptrie_trie.h @@ -1,6 +1,6 @@ -#pragma once +#pragma once -#include "comptrie_impl.h" +#include "comptrie_impl.h" #include "comptrie_packer.h" #include "opaque_trie_iterator.h" #include "leaf_skipper.h" @@ -28,7 +28,7 @@ class TSearchIterator; template <class TTrie> class TPrefixIterator; -// in case of <char> specialization cannot distinguish between "" and "\0" keys +// in case of <char> specialization cannot distinguish between "" and "\0" keys template <class T = char, class D = ui64, class S = TCompactTriePacker<D>> class TCompactTrie { public: @@ -45,8 +45,8 @@ public: typedef TCompactTrieBuilder<T, D, S> TBuilder; -protected: - TBlob DataHolder; +protected: + TBlob DataHolder; const char* EmptyValue = nullptr; TPacker Packer; NCompactTrie::TPackerLeafSkipper<TPacker> Skipper = &Packer; // This should be true for every constructor. @@ -70,12 +70,12 @@ public: TCompactTrie& operator=(const TCompactTrie& other); TCompactTrie& operator=(TCompactTrie&& other) noexcept; - explicit operator bool() const { - return !IsEmpty(); - } - + explicit operator bool() const { + return !IsEmpty(); + } + void Init(const char* d, size_t len, TPacker packer = TPacker()); - void Init(const TBlob& data, TPacker packer = TPacker()); + void Init(const TBlob& data, TPacker packer = TPacker()); bool IsInitialized() const; bool IsEmpty() const; @@ -91,10 +91,10 @@ public: ythrow yexception() << "key " << TKey(key, keylen).Quote() << " not found in trie"; return value; } - TData Get(const TKeyBuf& key) const { + TData Get(const TKeyBuf& key) const { return Get(key.data(), key.size()); } - TData GetDefault(const TKeyBuf& key, const TData& def) const { + TData GetDefault(const TKeyBuf& key, const TData& def) const { TData value; if (!Find(key.data(), key.size(), &value)) return def; @@ -102,7 +102,7 @@ public: return value; } - const TBlob& Data() const { + const TBlob& Data() const { return DataHolder; }; @@ -119,7 +119,7 @@ public: } void FindPhrases(const TSymbol* key, size_t keylen, TPhraseMatchVector& matches, TSymbol separator = TSymbol(' ')) const; - void FindPhrases(const TKeyBuf& key, TPhraseMatchVector& matches, TSymbol separator = TSymbol(' ')) const { + void FindPhrases(const TKeyBuf& key, TPhraseMatchVector& matches, TSymbol separator = TSymbol(' ')) const { return FindPhrases(key.data(), key.size(), matches, separator); } bool FindLongestPrefix(const TSymbol* key, size_t keylen, size_t* prefixLen, TData* value = nullptr, bool* hasNext = nullptr) const; @@ -128,12 +128,12 @@ public: } // Return trie, containing all tails for the given key - inline TCompactTrie<T, D, S> FindTails(const TSymbol* key, size_t keylen) const; - TCompactTrie<T, D, S> FindTails(const TKeyBuf& key) const { + inline TCompactTrie<T, D, S> FindTails(const TSymbol* key, size_t keylen) const; + TCompactTrie<T, D, S> FindTails(const TKeyBuf& key) const { return FindTails(key.data(), key.size()); } - bool FindTails(const TSymbol* key, size_t keylen, TCompactTrie<T, D, S>& res) const; - bool FindTails(const TKeyBuf& key, TCompactTrie<T, D, S>& res) const { + bool FindTails(const TSymbol* key, size_t keylen, TCompactTrie<T, D, S>& res) const; + bool FindTails(const TKeyBuf& key, TCompactTrie<T, D, S>& res) const { return FindTails(key.data(), key.size(), res); } @@ -164,7 +164,7 @@ public: TValueType operator*(); TKey GetKey() const; - size_t GetKeySize() const; + size_t GetKeySize() const; TData GetValue() const; void GetValue(TData& data) const; const char* GetValuePtr() const; @@ -180,22 +180,22 @@ public: TConstIterator end() const; // Returns an iterator pointing to the smallest key in the trie >= the argument. - // TODO: misleading name. Should be called LowerBound for consistency with stl. + // TODO: misleading name. Should be called LowerBound for consistency with stl. // No. It is the STL that has a misleading name. // LowerBound of X cannot be greater than X. - TConstIterator UpperBound(const TKeyBuf& key) const; + TConstIterator UpperBound(const TKeyBuf& key) const; void Print(IOutputStream& os); - size_t Size() const; - + size_t Size() const; + friend class NCompactTrie::TFirstSymbolIterator<TCompactTrie>; friend class TSearchIterator<TCompactTrie>; friend class TPrefixIterator<TCompactTrie>; -protected: +protected: explicit TCompactTrie(const char* emptyValue); - TCompactTrie(const TBlob& data, const char* emptyValue, TPacker packer = TPacker()); + TCompactTrie(const TBlob& data, const char* emptyValue, TPacker packer = TPacker()); bool LookupLongestPrefix(const TSymbol* key, size_t keylen, size_t& prefixLen, const char*& valuepos, bool& hasNext) const; bool LookupLongestPrefix(const TSymbol* key, size_t keylen, size_t& prefixLen, const char*& valuepos) const { @@ -221,36 +221,36 @@ public: // TCompactTrie -template <class T, class D, class S> -TCompactTrie<T, D, S>::TCompactTrie(const TBlob& data, TPacker packer) +template <class T, class D, class S> +TCompactTrie<T, D, S>::TCompactTrie(const TBlob& data, TPacker packer) : DataHolder(data) , Packer(packer) { Init(data, packer); } -template <class T, class D, class S> -TCompactTrie<T, D, S>::TCompactTrie(const char* d, size_t len, TPacker packer) +template <class T, class D, class S> +TCompactTrie<T, D, S>::TCompactTrie(const char* d, size_t len, TPacker packer) : Packer(packer) { Init(d, len, packer); } -template <class T, class D, class S> -TCompactTrie<T, D, S>::TCompactTrie(const char* emptyValue) +template <class T, class D, class S> +TCompactTrie<T, D, S>::TCompactTrie(const char* emptyValue) : EmptyValue(emptyValue) { } -template <class T, class D, class S> -TCompactTrie<T, D, S>::TCompactTrie(const TBlob& data, const char* emptyValue, TPacker packer) +template <class T, class D, class S> +TCompactTrie<T, D, S>::TCompactTrie(const TBlob& data, const char* emptyValue, TPacker packer) : DataHolder(data) , EmptyValue(emptyValue) , Packer(packer) { } -template <class T, class D, class S> +template <class T, class D, class S> TCompactTrie<T, D, S>::TCompactTrie(const TCompactTrie& other) : DataHolder(other.DataHolder) , EmptyValue(other.EmptyValue) @@ -287,19 +287,19 @@ TCompactTrie<T, D, S>& TCompactTrie<T, D, S>::operator=(TCompactTrie&& other) no } template <class T, class D, class S> -void TCompactTrie<T, D, S>::Init(const char* d, size_t len, TPacker packer) { - Init(TBlob::NoCopy(d, len), packer); +void TCompactTrie<T, D, S>::Init(const char* d, size_t len, TPacker packer) { + Init(TBlob::NoCopy(d, len), packer); } -template <class T, class D, class S> -void TCompactTrie<T, D, S>::Init(const TBlob& data, TPacker packer) { +template <class T, class D, class S> +void TCompactTrie<T, D, S>::Init(const TBlob& data, TPacker packer) { using namespace NCompactTrie; DataHolder = data; Packer = packer; const char* datapos = DataHolder.AsCharPtr(); - size_t len = DataHolder.Length(); + size_t len = DataHolder.Length(); if (!len) return; @@ -313,17 +313,17 @@ void TCompactTrie<T, D, S>::Init(const TBlob& data, TPacker packer) { } } -template <class T, class D, class S> -bool TCompactTrie<T, D, S>::IsInitialized() const { +template <class T, class D, class S> +bool TCompactTrie<T, D, S>::IsInitialized() const { return DataHolder.Data() != nullptr; } -template <class T, class D, class S> -bool TCompactTrie<T, D, S>::IsEmpty() const { +template <class T, class D, class S> +bool TCompactTrie<T, D, S>::IsEmpty() const { return DataHolder.Size() == 0 && EmptyValue == nullptr; } -template <class T, class D, class S> +template <class T, class D, class S> bool TCompactTrie<T, D, S>::Find(const TSymbol* key, size_t keylen, TData* value) const { size_t prefixLen = 0; const char* valuepos = nullptr; @@ -335,20 +335,20 @@ bool TCompactTrie<T, D, S>::Find(const TSymbol* key, size_t keylen, TData* value return true; } -template <class T, class D, class S> -void TCompactTrie<T, D, S>::FindPhrases(const TSymbol* key, size_t keylen, TPhraseMatchVector& matches, TSymbol separator) const { +template <class T, class D, class S> +void TCompactTrie<T, D, S>::FindPhrases(const TSymbol* key, size_t keylen, TPhraseMatchVector& matches, TSymbol separator) const { LookupPhrases(DataHolder.AsCharPtr(), DataHolder.Length(), key, keylen, matches, separator); } -template <class T, class D, class S> -inline TCompactTrie<T, D, S> TCompactTrie<T, D, S>::FindTails(const TSymbol* key, size_t keylen) const { - TCompactTrie<T, D, S> ret; +template <class T, class D, class S> +inline TCompactTrie<T, D, S> TCompactTrie<T, D, S>::FindTails(const TSymbol* key, size_t keylen) const { + TCompactTrie<T, D, S> ret; FindTails(key, keylen, ret); return ret; } -template <class T, class D, class S> -bool TCompactTrie<T, D, S>::FindTails(const TSymbol* key, size_t keylen, TCompactTrie<T, D, S>& res) const { +template <class T, class D, class S> +bool TCompactTrie<T, D, S>::FindTails(const TSymbol* key, size_t keylen, TCompactTrie<T, D, S>& res) const { using namespace NCompactTrie; size_t len = DataHolder.Length(); @@ -376,7 +376,7 @@ bool TCompactTrie<T, D, S>::FindTails(const TSymbol* key, size_t keylen, TCompac if (key == keyend) { if (datapos) { Y_ASSERT(datapos >= datastart); - res = TCompactTrie<T, D, S>(TBlob::NoCopy(datapos, dataend - datapos), value); + res = TCompactTrie<T, D, S>(TBlob::NoCopy(datapos, dataend - datapos), value); } else { res = TCompactTrie<T, D, S>(value); } @@ -389,11 +389,11 @@ bool TCompactTrie<T, D, S>::FindTails(const TSymbol* key, size_t keylen, TCompac return false; } -template <class T, class D, class S> +template <class T, class D, class S> inline bool TCompactTrie<T, D, S>::FindTails(TSymbol label, TCompactTrie<T, D, S>& res) const { using namespace NCompactTrie; - const size_t len = DataHolder.Length(); + const size_t len = DataHolder.Length(); if (!len) return false; @@ -415,43 +415,43 @@ inline bool TCompactTrie<T, D, S>::FindTails(TSymbol label, TCompactTrie<T, D, S return true; } -template <class T, class D, class S> -typename TCompactTrie<T, D, S>::TConstIterator TCompactTrie<T, D, S>::Begin() const { +template <class T, class D, class S> +typename TCompactTrie<T, D, S>::TConstIterator TCompactTrie<T, D, S>::Begin() const { NCompactTrie::TOpaqueTrie self(DataHolder.AsCharPtr(), DataHolder.Length(), Skipper); return TConstIterator(self, EmptyValue, false, Packer); } -template <class T, class D, class S> +template <class T, class D, class S> typename TCompactTrie<T, D, S>::TConstIterator TCompactTrie<T, D, S>::begin() const { return Begin(); } template <class T, class D, class S> -typename TCompactTrie<T, D, S>::TConstIterator TCompactTrie<T, D, S>::End() const { +typename TCompactTrie<T, D, S>::TConstIterator TCompactTrie<T, D, S>::End() const { NCompactTrie::TOpaqueTrie self(DataHolder.AsCharPtr(), DataHolder.Length(), Skipper); return TConstIterator(self, EmptyValue, true, Packer); } -template <class T, class D, class S> +template <class T, class D, class S> typename TCompactTrie<T, D, S>::TConstIterator TCompactTrie<T, D, S>::end() const { return End(); } template <class T, class D, class S> -size_t TCompactTrie<T, D, S>::Size() const { - size_t res = 0; - for (TConstIterator it = Begin(); it != End(); ++it) - ++res; - return res; -} - -template <class T, class D, class S> -typename TCompactTrie<T, D, S>::TConstIterator TCompactTrie<T, D, S>::UpperBound(const TKeyBuf& key) const { +size_t TCompactTrie<T, D, S>::Size() const { + size_t res = 0; + for (TConstIterator it = Begin(); it != End(); ++it) + ++res; + return res; +} + +template <class T, class D, class S> +typename TCompactTrie<T, D, S>::TConstIterator TCompactTrie<T, D, S>::UpperBound(const TKeyBuf& key) const { NCompactTrie::TOpaqueTrie self(DataHolder.AsCharPtr(), DataHolder.Length(), Skipper); return TConstIterator(self, EmptyValue, key, Packer); } -template <class T, class D, class S> +template <class T, class D, class S> void TCompactTrie<T, D, S>::Print(IOutputStream& os) { typedef typename ::TCompactTrieKeySelector<T>::TKeyBuf TSBuffer; for (TConstIterator it = Begin(); it != End(); ++it) { @@ -459,7 +459,7 @@ void TCompactTrie<T, D, S>::Print(IOutputStream& os) { } } -template <class T, class D, class S> +template <class T, class D, class S> bool TCompactTrie<T, D, S>::FindLongestPrefix(const TSymbol* key, size_t keylen, size_t* prefixLen, TData* value, bool* hasNext) const { const char* valuepos = nullptr; size_t tempPrefixLen = 0; @@ -474,12 +474,12 @@ bool TCompactTrie<T, D, S>::FindLongestPrefix(const TSymbol* key, size_t keylen, return found; } -template <class T, class D, class S> +template <class T, class D, class S> bool TCompactTrie<T, D, S>::LookupLongestPrefix(const TSymbol* key, size_t keylen, size_t& prefixLen, const char*& valuepos, bool& hasNext) const { using namespace NCompactTrie; const char* datapos = DataHolder.AsCharPtr(); - size_t len = DataHolder.Length(); + size_t len = DataHolder.Length(); prefixLen = 0; hasNext = false; @@ -526,8 +526,8 @@ bool TCompactTrie<T, D, S>::LookupLongestPrefix(const TSymbol* key, size_t keyle return found; } -template <class T, class D, class S> -void TCompactTrie<T, D, S>::LookupPhrases( +template <class T, class D, class S> +void TCompactTrie<T, D, S>::LookupPhrases( const char* datapos, size_t len, const TSymbol* key, size_t keylen, TVector<TPhraseMatch>& matches, TSymbol separator) const { using namespace NCompactTrie; @@ -570,14 +570,14 @@ TCompactTrieHolder<T, D, S>::TCompactTrieHolder(IInputStream& is, size_t len) //---------------------------------------------------------------------------------------------------------------- // TCompactTrie::TConstIterator -template <class T, class D, class S> +template <class T, class D, class S> TCompactTrie<T, D, S>::TConstIterator::TConstIterator(const TOpaqueTrie& trie, const char* emptyValue, bool atend, TPacker packer) : Packer(packer) , Impl(new TOpaqueTrieIterator(trie, emptyValue, atend)) { } -template <class T, class D, class S> +template <class T, class D, class S> TCompactTrie<T, D, S>::TConstIterator::TConstIterator(const TOpaqueTrie& trie, const char* emptyValue, const TKeyBuf& key, TPacker packer) : Packer(packer) , Impl(new TOpaqueTrieIterator(trie, emptyValue, true)) @@ -585,7 +585,7 @@ TCompactTrie<T, D, S>::TConstIterator::TConstIterator(const TOpaqueTrie& trie, c Impl->UpperBound<TSymbol>(key); } -template <class T, class D, class S> +template <class T, class D, class S> bool TCompactTrie<T, D, S>::TConstIterator::operator==(const TConstIterator& other) const { if (!Impl) return !other.Impl; @@ -594,70 +594,70 @@ bool TCompactTrie<T, D, S>::TConstIterator::operator==(const TConstIterator& oth return *Impl == *other.Impl; } -template <class T, class D, class S> +template <class T, class D, class S> bool TCompactTrie<T, D, S>::TConstIterator::operator!=(const TConstIterator& other) const { return !operator==(other); } -template <class T, class D, class S> -typename TCompactTrie<T, D, S>::TConstIterator& TCompactTrie<T, D, S>::TConstIterator::operator++() { +template <class T, class D, class S> +typename TCompactTrie<T, D, S>::TConstIterator& TCompactTrie<T, D, S>::TConstIterator::operator++() { Impl->Forward(); return *this; } -template <class T, class D, class S> -typename TCompactTrie<T, D, S>::TConstIterator TCompactTrie<T, D, S>::TConstIterator::operator++(int /*unused*/) { +template <class T, class D, class S> +typename TCompactTrie<T, D, S>::TConstIterator TCompactTrie<T, D, S>::TConstIterator::operator++(int /*unused*/) { TConstIterator copy(*this); Impl->Forward(); return copy; } -template <class T, class D, class S> -typename TCompactTrie<T, D, S>::TConstIterator& TCompactTrie<T, D, S>::TConstIterator::operator--() { +template <class T, class D, class S> +typename TCompactTrie<T, D, S>::TConstIterator& TCompactTrie<T, D, S>::TConstIterator::operator--() { Impl->Backward(); return *this; } -template <class T, class D, class S> -typename TCompactTrie<T, D, S>::TConstIterator TCompactTrie<T, D, S>::TConstIterator::operator--(int /*unused*/) { +template <class T, class D, class S> +typename TCompactTrie<T, D, S>::TConstIterator TCompactTrie<T, D, S>::TConstIterator::operator--(int /*unused*/) { TConstIterator copy(*this); Impl->Backward(); return copy; } -template <class T, class D, class S> -typename TCompactTrie<T, D, S>::TValueType TCompactTrie<T, D, S>::TConstIterator::operator*() { +template <class T, class D, class S> +typename TCompactTrie<T, D, S>::TValueType TCompactTrie<T, D, S>::TConstIterator::operator*() { return TValueType(GetKey(), GetValue()); } -template <class T, class D, class S> +template <class T, class D, class S> typename TCompactTrie<T, D, S>::TKey TCompactTrie<T, D, S>::TConstIterator::GetKey() const { return Impl->GetKey<TSymbol>(); } -template <class T, class D, class S> +template <class T, class D, class S> size_t TCompactTrie<T, D, S>::TConstIterator::GetKeySize() const { return Impl->MeasureKey<TSymbol>(); -} - -template <class T, class D, class S> +} + +template <class T, class D, class S> const char* TCompactTrie<T, D, S>::TConstIterator::GetValuePtr() const { return Impl->GetValuePtr(); -} - -template <class T, class D, class S> +} + +template <class T, class D, class S> typename TCompactTrie<T, D, S>::TData TCompactTrie<T, D, S>::TConstIterator::GetValue() const { D data; GetValue(data); return data; } -template <class T, class D, class S> +template <class T, class D, class S> void TCompactTrie<T, D, S>::TConstIterator::GetValue(typename TCompactTrie<T, D, S>::TData& data) const { const char* ptr = GetValuePtr(); if (ptr) { Packer.UnpackLeaf(ptr, data); } else { - data = typename TCompactTrie<T, D, S>::TData(); + data = typename TCompactTrie<T, D, S>::TData(); } } diff --git a/library/cpp/containers/comptrie/comptrie_ut.cpp b/library/cpp/containers/comptrie/comptrie_ut.cpp index d73883afdc..74bee09b5d 100644 --- a/library/cpp/containers/comptrie/comptrie_ut.cpp +++ b/library/cpp/containers/comptrie/comptrie_ut.cpp @@ -36,7 +36,7 @@ private: UNIT_TEST(TestTrie8); UNIT_TEST(TestTrie16); UNIT_TEST(TestTrie32); - + UNIT_TEST(TestFastTrie8); UNIT_TEST(TestFastTrie16); UNIT_TEST(TestFastTrie32); @@ -44,7 +44,7 @@ private: UNIT_TEST(TestMinimizedTrie8); UNIT_TEST(TestMinimizedTrie16); UNIT_TEST(TestMinimizedTrie32); - + UNIT_TEST(TestFastMinimizedTrie8); UNIT_TEST(TestFastMinimizedTrie16); UNIT_TEST(TestFastMinimizedTrie32); @@ -52,11 +52,11 @@ private: UNIT_TEST(TestTrieIterator8); UNIT_TEST(TestTrieIterator16); UNIT_TEST(TestTrieIterator32); - + UNIT_TEST(TestMinimizedTrieIterator8); UNIT_TEST(TestMinimizedTrieIterator16); UNIT_TEST(TestMinimizedTrieIterator32); - + UNIT_TEST(TestPhraseSearch); UNIT_TEST(TestAddGet); UNIT_TEST(TestEmpty); @@ -169,11 +169,11 @@ private: public: void TestPackers(); - + void TestTrie8(); void TestTrie16(); void TestTrie32(); - + void TestFastTrie8(); void TestFastTrie16(); void TestFastTrie32(); @@ -181,7 +181,7 @@ public: void TestMinimizedTrie8(); void TestMinimizedTrie16(); void TestMinimizedTrie32(); - + void TestFastMinimizedTrie8(); void TestFastMinimizedTrie16(); void TestFastMinimizedTrie32(); @@ -189,11 +189,11 @@ public: void TestTrieIterator8(); void TestTrieIterator16(); void TestTrieIterator32(); - + void TestMinimizedTrieIterator8(); void TestMinimizedTrieIterator16(); void TestMinimizedTrieIterator32(); - + void TestPhraseSearch(); void TestAddGet(); void TestEmpty(); @@ -277,7 +277,7 @@ const char* TCompactTrieTest::SampleData[] = { }; template <class T> -typename TCompactTrie<T>::TKey MakeWideKey(const char* str, size_t len) { +typename TCompactTrie<T>::TKey MakeWideKey(const char* str, size_t len) { typename TCompactTrie<T>::TKey buffer; for (size_t i = 0; i < len; i++) { unsigned int ch = (str[i] & 0xFF); @@ -302,7 +302,7 @@ void TCompactTrieTest::CreateTrie(IOutputStream& out, bool minimize, bool useFas for (auto& i : SampleData) { size_t len = strlen(i); - + builder.Add(MakeWideKey<T>(i, len), len * 2); } @@ -362,7 +362,7 @@ void TCompactTrieTest::CheckData(const char* data, size_t datalen) { TCompactTrie<T> trie(data, datalen); UNIT_ASSERT_VALUES_EQUAL(Y_ARRAY_SIZE(SampleData), trie.Size()); - + for (auto& i : SampleData) { size_t len = strlen(i); ui64 value = 0; @@ -421,7 +421,7 @@ void TCompactTrieTest::CheckData(const char* data, size_t datalen) { template <class T> void TCompactTrieTest::CheckIterator(const char* data, size_t datalen) { - typedef typename TCompactTrie<T>::TKey TKey; + typedef typename TCompactTrie<T>::TKey TKey; typedef typename TCompactTrie<T>::TValueType TValue; TMap<TKey, ui64> stored; @@ -437,7 +437,7 @@ void TCompactTrieTest::CheckIterator(const char* data, size_t datalen) { size_t entry_count = 0; TMap<TKey, ui64> received; while (it != trie.End()) { - UNIT_ASSERT_VALUES_EQUAL(it.GetKeySize(), it.GetKey().size()); + UNIT_ASSERT_VALUES_EQUAL(it.GetKeySize(), it.GetKey().size()); received.insert(*it); items.push_back(*it); entry_count++; @@ -509,7 +509,7 @@ void TCompactTrieTest::TestTrie16() { void TCompactTrieTest::TestTrie32() { TestTrie<wchar32>(false, false); } - + void TCompactTrieTest::TestFastTrie8() { TestTrie<char>(false, true); } diff --git a/library/cpp/containers/comptrie/leaf_skipper.h b/library/cpp/containers/comptrie/leaf_skipper.h index e3aab8596f..3959258948 100644 --- a/library/cpp/containers/comptrie/leaf_skipper.h +++ b/library/cpp/containers/comptrie/leaf_skipper.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include <cstddef> diff --git a/library/cpp/containers/comptrie/make_fast_layout.cpp b/library/cpp/containers/comptrie/make_fast_layout.cpp index 779146df1f..ade78d7899 100644 --- a/library/cpp/containers/comptrie/make_fast_layout.cpp +++ b/library/cpp/containers/comptrie/make_fast_layout.cpp @@ -4,7 +4,7 @@ #include "write_trie_backwards.h" #include "comptrie_impl.h" -#include <util/generic/hash.h> +#include <util/generic/hash.h> #include <util/generic/utility.h> // Lay the trie in memory in such a way that there are less cache misses when jumping from root to leaf. diff --git a/library/cpp/containers/comptrie/make_fast_layout.h b/library/cpp/containers/comptrie/make_fast_layout.h index f176de6b73..b8fab5d65b 100644 --- a/library/cpp/containers/comptrie/make_fast_layout.h +++ b/library/cpp/containers/comptrie/make_fast_layout.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "leaf_skipper.h" #include <cstddef> diff --git a/library/cpp/containers/comptrie/minimize.cpp b/library/cpp/containers/comptrie/minimize.cpp index 7346668c57..80d0b25217 100644 --- a/library/cpp/containers/comptrie/minimize.cpp +++ b/library/cpp/containers/comptrie/minimize.cpp @@ -4,7 +4,7 @@ #include "write_trie_backwards.h" #include "comptrie_impl.h" -#include <util/generic/hash.h> +#include <util/generic/hash.h> #include <util/generic/algorithm.h> namespace NCompactTrie { @@ -42,7 +42,7 @@ namespace NCompactTrie { if (Data.size() <= hikey) Data.resize(hikey + 1); - + TSizePairVector& sublist = Data[hikey]; for (auto& it : sublist) { @@ -296,7 +296,7 @@ namespace NCompactTrie { if (iit == subtries.end()) continue; // fast forward to the next available length value - + TOffsetList& batch = iit->second; TPieceComparer comparer(trie.Data, curlen); Sort(batch.begin(), batch.end(), comparer); diff --git a/library/cpp/containers/comptrie/minimize.h b/library/cpp/containers/comptrie/minimize.h index 7b991584e9..baaa431d04 100644 --- a/library/cpp/containers/comptrie/minimize.h +++ b/library/cpp/containers/comptrie/minimize.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "leaf_skipper.h" #include <cstddef> diff --git a/library/cpp/containers/comptrie/node.cpp b/library/cpp/containers/comptrie/node.cpp index 99a56fe83a..5fd22f15ec 100644 --- a/library/cpp/containers/comptrie/node.cpp +++ b/library/cpp/containers/comptrie/node.cpp @@ -1,6 +1,6 @@ #include "node.h" #include "leaf_skipper.h" -#include "comptrie_impl.h" +#include "comptrie_impl.h" #include <util/system/yassert.h> #include <util/generic/yexception.h> @@ -56,7 +56,7 @@ namespace NCompactTrie { Offsets[D_FINAL] = datapos - data; LeafLength = skipFunction.SkipLeaf(datapos); } - + CoreLength = 2 + leftsize + rightsize + LeafLength; if (flags & MT_NEXT) { size_t& forwardOffset = Offsets[D_NEXT]; diff --git a/library/cpp/containers/comptrie/node.h b/library/cpp/containers/comptrie/node.h index d4d90201ef..d6f4317db0 100644 --- a/library/cpp/containers/comptrie/node.h +++ b/library/cpp/containers/comptrie/node.h @@ -32,7 +32,7 @@ namespace NCompactTrie { size_t GetOffset() const { return Offset; } - + size_t GetLeafOffset() const { return Offsets[D_FINAL]; } diff --git a/library/cpp/containers/comptrie/opaque_trie_iterator.cpp b/library/cpp/containers/comptrie/opaque_trie_iterator.cpp index 1c812d9521..5fd3914be6 100644 --- a/library/cpp/containers/comptrie/opaque_trie_iterator.cpp +++ b/library/cpp/containers/comptrie/opaque_trie_iterator.cpp @@ -1,5 +1,5 @@ #include "opaque_trie_iterator.h" -#include "comptrie_impl.h" +#include "comptrie_impl.h" #include "node.h" namespace NCompactTrie { @@ -157,8 +157,8 @@ namespace NCompactTrie { } else { return Key.size() == 1 && Key[0] == '\0'; } - } - + } + size_t TForkStack::MeasureKey() const { size_t result = Key.size() + (TopHasLabelInKey() ? 1 : 0); if (result == 1 && HasEmptyKey()) { diff --git a/library/cpp/containers/comptrie/opaque_trie_iterator.h b/library/cpp/containers/comptrie/opaque_trie_iterator.h index e136270163..195da3c191 100644 --- a/library/cpp/containers/comptrie/opaque_trie_iterator.h +++ b/library/cpp/containers/comptrie/opaque_trie_iterator.h @@ -1,6 +1,6 @@ -#pragma once +#pragma once -#include "comptrie_impl.h" +#include "comptrie_impl.h" #include "node.h" #include "key_selector.h" #include "leaf_skipper.h" diff --git a/library/cpp/containers/comptrie/ut/ya.make b/library/cpp/containers/comptrie/ut/ya.make index ed3048f0e3..c4f4666009 100644 --- a/library/cpp/containers/comptrie/ut/ya.make +++ b/library/cpp/containers/comptrie/ut/ya.make @@ -1,7 +1,7 @@ UNITTEST_FOR(library/cpp/containers/comptrie) OWNER(alzobnin) - + SRCS( comptrie_ut.cpp ) diff --git a/library/cpp/containers/comptrie/ya.make b/library/cpp/containers/comptrie/ya.make index 4480a4f01b..81352da4b2 100644 --- a/library/cpp/containers/comptrie/ya.make +++ b/library/cpp/containers/comptrie/ya.make @@ -1,7 +1,7 @@ LIBRARY() OWNER(velavokr) - + SRCS( array_with_size.h chunked_helpers_trie.h @@ -29,7 +29,7 @@ PEERDIR( library/cpp/packers library/cpp/containers/compact_vector library/cpp/on_disk/chunks - util/draft + util/draft ) END() diff --git a/library/cpp/containers/intrusive_avl_tree/avltree.h b/library/cpp/containers/intrusive_avl_tree/avltree.h index 39fe191a20..a58c63b07c 100644 --- a/library/cpp/containers/intrusive_avl_tree/avltree.h +++ b/library/cpp/containers/intrusive_avl_tree/avltree.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include <util/generic/noncopyable.h> diff --git a/library/cpp/containers/intrusive_rb_tree/rb_tree.h b/library/cpp/containers/intrusive_rb_tree/rb_tree.h index d595701bad..0259452a14 100644 --- a/library/cpp/containers/intrusive_rb_tree/rb_tree.h +++ b/library/cpp/containers/intrusive_rb_tree/rb_tree.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include <util/generic/utility.h> #include <util/generic/yexception.h> diff --git a/library/cpp/containers/paged_vector/paged_vector.h b/library/cpp/containers/paged_vector/paged_vector.h index 9730b00670..6a3657d3ea 100644 --- a/library/cpp/containers/paged_vector/paged_vector.h +++ b/library/cpp/containers/paged_vector/paged_vector.h @@ -1,15 +1,15 @@ -#pragma once - -#include <util/generic/ptr.h> -#include <util/generic/vector.h> -#include <util/generic/yexception.h> - +#pragma once + +#include <util/generic/ptr.h> +#include <util/generic/vector.h> +#include <util/generic/yexception.h> + #include <iterator> -namespace NPagedVector { +namespace NPagedVector { template <class T, ui32 PageSize = 1u << 20, class A = std::allocator<T>> class TPagedVector; - + namespace NPrivate { template <class T, class TT, ui32 PageSize, class A> struct TPagedVectorIterator { @@ -19,119 +19,119 @@ namespace NPagedVector { typedef TPagedVectorIterator<T, TT, PageSize, A> TSelf; size_t Offset; TVec* Vector; - + template <class T1, class TT1, ui32 PageSize1, class A1> friend struct TPagedVectorIterator; - + public: TPagedVectorIterator() : Offset() , Vector() { } - + TPagedVectorIterator(TVec* vector, size_t offset) : Offset(offset) , Vector(vector) { } - + template <class T1, class TT1, ui32 PageSize1, class A1> TPagedVectorIterator(const TPagedVectorIterator<T1, TT1, PageSize1, A1>& it) : Offset(it.Offset) , Vector(it.Vector) { } - + T& operator*() const { return (*Vector)[Offset]; } - + T* operator->() const { return &(**this); } - + template <class T1, class TT1, ui32 PageSize1, class A1> bool operator==(const TPagedVectorIterator<T1, TT1, PageSize1, A1>& it) const { return Offset == it.Offset; } - + template <class T1, class TT1, ui32 PageSize1, class A1> bool operator!=(const TPagedVectorIterator<T1, TT1, PageSize1, A1>& it) const { return !(*this == it); } - + template <class T1, class TT1, ui32 PageSize1, class A1> bool operator<(const TPagedVectorIterator<T1, TT1, PageSize1, A1>& it) const { return Offset < it.Offset; } - + template <class T1, class TT1, ui32 PageSize1, class A1> bool operator<=(const TPagedVectorIterator<T1, TT1, PageSize1, A1>& it) const { return Offset <= it.Offset; } - + template <class T1, class TT1, ui32 PageSize1, class A1> bool operator>(const TPagedVectorIterator<T1, TT1, PageSize1, A1>& it) const { return !(*this <= it); } - + template <class T1, class TT1, ui32 PageSize1, class A1> bool operator>=(const TPagedVectorIterator<T1, TT1, PageSize1, A1>& it) const { return !(*this < it); } - + template <class T1, class TT1, ui32 PageSize1, class A1> ptrdiff_t operator-(const TPagedVectorIterator<T1, TT1, PageSize1, A1>& it) const { return Offset - it.Offset; } - + TSelf& operator+=(ptrdiff_t off) { Offset += off; return *this; } - + TSelf& operator-=(ptrdiff_t off) { return this->operator+=(-off); } - + TSelf& operator++() { return this->operator+=(1); } - + TSelf& operator--() { return this->operator+=(-1); } - + TSelf operator++(int) { TSelf it = *this; this->operator+=(1); return it; } - + TSelf operator--(int) { TSelf it = *this; this->operator+=(-1); return it; } - + TSelf operator+(ptrdiff_t off) { TSelf res = *this; res += off; return res; } - + TSelf operator-(ptrdiff_t off) { return this->operator+(-off); } - + size_t GetOffset() { return Offset; } }; - } -} - + } +} + namespace std { template <class T, class TT, ui32 PageSize, class A> struct iterator_traits<NPagedVector::NPrivate::TPagedVectorIterator<T, TT, PageSize, A>> { @@ -141,19 +141,19 @@ namespace std { typedef T& reference; typedef random_access_iterator_tag iterator_category; }; - -} - -namespace NPagedVector { + +} + +namespace NPagedVector { //2-level radix tree template <class T, ui32 PageSize, class A> class TPagedVector: private TVector<TSimpleSharedPtr<TVector<T, A>>, A> { static_assert(PageSize, "expect PageSize"); - + typedef TVector<T, A> TPage; typedef TVector<TSimpleSharedPtr<TPage>, A> TPages; typedef TPagedVector<T, PageSize, A> TSelf; - + public: typedef NPrivate::TPagedVectorIterator<T, T, PageSize, A> iterator; typedef NPrivate::TPagedVectorIterator<const T, T, PageSize, A> const_iterator; @@ -162,99 +162,99 @@ namespace NPagedVector { typedef T value_type; typedef value_type& reference; typedef const value_type& const_reference; - + TPagedVector() = default; - + template <typename TIter> TPagedVector(TIter b, TIter e) { append(b, e); } - + iterator begin() { return iterator(this, 0); } - + const_iterator begin() const { return const_iterator((TSelf*)this, 0); } - + iterator end() { return iterator(this, size()); } - + const_iterator end() const { return const_iterator((TSelf*)this, size()); } - + reverse_iterator rbegin() { return reverse_iterator(end()); } - + const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } - + reverse_iterator rend() { return reverse_iterator(begin()); } - + const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } - + void swap(TSelf& v) { TPages::swap((TPages&)v); } - + private: static size_t PageNumber(size_t idx) { return idx / PageSize; } - + static size_t InPageIndex(size_t idx) { return idx % PageSize; } - + static size_t Index(size_t pnum, size_t poff) { return pnum * PageSize + poff; } - + TPage& PageAt(size_t pnum) const { return *TPages::at(pnum); } - + TPage& CurrentPage() const { return *TPages::back(); } - + size_t CurrentPageSize() const { return TPages::empty() ? 0 : CurrentPage().size(); } - + size_t NPages() const { return TPages::size(); } - + void AllocateNewPage() { TPages::push_back(new TPage()); CurrentPage().reserve(PageSize); } - + void MakeNewPage() { - AllocateNewPage(); + AllocateNewPage(); CurrentPage().resize(PageSize); } - + void PrepareAppend() { if (TPages::empty() || CurrentPage().size() + 1 > PageSize) AllocateNewPage(); } - + public: size_t size() const { return empty() ? 0 : (NPages() - 1) * PageSize + CurrentPage().size(); } - + bool empty() const { return TPages::empty() || 1 == NPages() && CurrentPage().empty(); } @@ -262,23 +262,23 @@ namespace NPagedVector { explicit operator bool() const noexcept { return !empty(); } - + void emplace_back() { PrepareAppend(); CurrentPage().emplace_back(); } - + void push_back(const_reference t) { - PrepareAppend(); + PrepareAppend(); CurrentPage().push_back(t); - } - + } + void pop_back() { if (CurrentPage().empty()) TPages::pop_back(); CurrentPage().pop_back(); - } - + } + template <typename TIter> void append(TIter b, TIter e) { size_t sz = e - b; @@ -303,15 +303,15 @@ namespace NPagedVector { TPage& p = CurrentPage(); p.insert(p.end(), b + sz1 + sz2 * PageSize, e); } - } - + } + iterator erase(iterator it) { size_t pnum = PageNumber(it.Offset); size_t pidx = InPageIndex(it.Offset); - + if (CurrentPage().empty()) TPages::pop_back(); - + for (size_t p = NPages() - 1; p > pnum; --p) { PageAt(p - 1).push_back(PageAt(p).front()); PageAt(p).erase(PageAt(p).begin()); @@ -319,114 +319,114 @@ namespace NPagedVector { PageAt(pnum).erase(PageAt(pnum).begin() + pidx); return it; - } - + } + iterator erase(iterator b, iterator e) { // todo : suboptimal! while (b != e) { b = erase(b); --e; } - + return b; - } - + } + iterator insert(iterator it, const value_type& v) { size_t pnum = PageNumber(it.Offset); size_t pidx = InPageIndex(it.Offset); - + PrepareAppend(); - + for (size_t p = NPages() - 1; p > pnum; --p) { PageAt(p).insert(PageAt(p).begin(), PageAt(p - 1).back()); PageAt(p - 1).pop_back(); } - + PageAt(pnum).insert(PageAt(pnum).begin() + pidx, v); return it; - } - + } + template <typename TIter> void insert(iterator it, TIter b, TIter e) { // todo : suboptimal! for (; b != e; ++b, ++it) it = insert(it, *b); } - + reference front() { return TPages::front()->front(); } - + const_reference front() const { return TPages::front()->front(); } - + reference back() { return CurrentPage().back(); } - + const_reference back() const { return CurrentPage().back(); } - + void clear() { TPages::clear(); } - + void resize(size_t sz) { if (sz == size()) return; - + const size_t npages = NPages(); const size_t newwholepages = sz / PageSize; const size_t pagepart = sz % PageSize; const size_t newpages = newwholepages + bool(pagepart); - + if (npages && newwholepages >= npages) CurrentPage().resize(PageSize); - + if (newpages < npages) TPages::resize(newpages); else for (size_t i = npages; i < newpages; ++i) MakeNewPage(); - + if (pagepart) CurrentPage().resize(pagepart); - + Y_VERIFY(sz == size(), "%" PRIu64 " %" PRIu64, (ui64)sz, (ui64)size()); } - + reference at(size_t idx) { return TPages::at(PageNumber(idx))->at(InPageIndex(idx)); } - + const_reference at(size_t idx) const { return TPages::at(PageNumber(idx))->at(InPageIndex(idx)); } - + reference operator[](size_t idx) { return TPages::operator[](PageNumber(idx))->operator[](InPageIndex(idx)); } - + const_reference operator[](size_t idx) const { return TPages::operator[](PageNumber(idx))->operator[](InPageIndex(idx)); } - + friend bool operator==(const TSelf& a, const TSelf& b) { return a.size() == b.size() && std::equal(a.begin(), a.end(), b.begin()); } - + friend bool operator<(const TSelf& a, const TSelf& b) { return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end()); } }; - + namespace NPrivate { typedef std::is_same<std::random_access_iterator_tag, std::iterator_traits< TPagedVector<ui32>::iterator>::iterator_category> TIteratorCheck; static_assert(TIteratorCheck::value, "expect TIteratorCheck::Result"); - } - -} + } + +} diff --git a/library/cpp/containers/paged_vector/ut/paged_vector_ut.cpp b/library/cpp/containers/paged_vector/ut/paged_vector_ut.cpp index ff6d86648c..e867808ee4 100644 --- a/library/cpp/containers/paged_vector/ut/paged_vector_ut.cpp +++ b/library/cpp/containers/paged_vector/ut/paged_vector_ut.cpp @@ -2,8 +2,8 @@ #include <library/cpp/testing/unittest/registar.h> #include <stdexcept> - -class TPagedVectorTest: public TTestBase { + +class TPagedVectorTest: public TTestBase { UNIT_TEST_SUITE(TPagedVectorTest); UNIT_TEST(Test0) UNIT_TEST(Test1) @@ -18,7 +18,7 @@ class TPagedVectorTest: public TTestBase { UNIT_TEST(TestIterators) //UNIT_TEST(TestEbo) UNIT_TEST_SUITE_END(); - + private: // Copy-paste of STLPort tests void Test0() { @@ -27,33 +27,33 @@ private: UNIT_ASSERT(v1.empty() == true); UNIT_ASSERT(v1.size() == 0); - + for (size_t i = 0; i < 256; ++i) { v1.resize(i + 1); UNIT_ASSERT_VALUES_EQUAL(v1.size(), i + 1); } - + for (size_t i = 256; i-- > 0;) { v1.resize(i); UNIT_ASSERT_VALUES_EQUAL(v1.size(), i); - } + } } - + void Test1() { using NPagedVector::TPagedVector; TPagedVector<int, 3> v1; // Empty vector of integers. - + UNIT_ASSERT(v1.empty() == true); UNIT_ASSERT(v1.size() == 0); - + // UNIT_ASSERT(v1.max_size() == INT_MAX / sizeof(int)); // cout << "max_size = " << v1.max_size() << endl; v1.push_back(42); // Add an integer to the vector. - + UNIT_ASSERT(v1.size() == 1); - + UNIT_ASSERT(v1[0] == 42); - + { TPagedVector<TPagedVector<int, 3>, 3> vect; vect.resize(10); @@ -63,10 +63,10 @@ private: UNIT_ASSERT((*it).empty()); UNIT_ASSERT((*it).size() == 0); UNIT_ASSERT((*it).begin() == (*it).end()); - } - } + } + } } - + void Test2() { using NPagedVector::TPagedVector; TPagedVector<double, 3> v1; // Empty vector of doubles. @@ -76,109 +76,109 @@ private: v1.push_back(33.4); TPagedVector<double, 3> v2; // Another empty vector of doubles. v2.push_back(3.56); - + UNIT_ASSERT(v1.size() == 4); UNIT_ASSERT(v1[0] == 32.1); UNIT_ASSERT(v1[1] == 40.5); UNIT_ASSERT(v1[2] == 45.5); UNIT_ASSERT(v1[3] == 33.4); - + UNIT_ASSERT(v2.size() == 1); UNIT_ASSERT(v2[0] == 3.56); v1.swap(v2); // Swap the vector's contents. - + UNIT_ASSERT(v1.size() == 1); UNIT_ASSERT(v1[0] == 3.56); - + UNIT_ASSERT(v2.size() == 4); UNIT_ASSERT(v2[0] == 32.1); UNIT_ASSERT(v2[1] == 40.5); UNIT_ASSERT(v2[2] == 45.5); UNIT_ASSERT(v2[3] == 33.4); - + v2 = v1; // Assign one vector to another. - + UNIT_ASSERT(v2.size() == 1); UNIT_ASSERT(v2[0] == 3.56); - + v2.pop_back(); UNIT_ASSERT(v2.size() == 0); UNIT_ASSERT(v2.empty()); } - + void Test3() { using NPagedVector::TPagedVector; TPagedVector<char, 1> v1; - + v1.push_back('h'); v1.push_back('i'); - + UNIT_ASSERT(v1.size() == 2); UNIT_ASSERT(v1[0] == 'h'); UNIT_ASSERT(v1[1] == 'i'); - + TPagedVector<char, 1> v2; v2.resize(v1.size()); - + for (size_t i = 0; i < v1.size(); ++i) v2[i] = v1[i]; - + v2[1] = 'o'; // Replace second character. - + UNIT_ASSERT(v2.size() == 2); UNIT_ASSERT(v2[0] == 'h'); UNIT_ASSERT(v2[1] == 'o'); - + UNIT_ASSERT((v1 == v2) == false); - + UNIT_ASSERT((v1 < v2) == true); } - + void Test4() { using NPagedVector::TPagedVector; TPagedVector<int, 3> v; v.resize(4); - + v[0] = 1; v[1] = 4; v[2] = 9; v[3] = 16; - + UNIT_ASSERT(v.front() == 1); UNIT_ASSERT(v.back() == 16); - + v.push_back(25); - + UNIT_ASSERT(v.back() == 25); UNIT_ASSERT(v.size() == 5); - + v.pop_back(); - + UNIT_ASSERT(v.back() == 16); UNIT_ASSERT(v.size() == 4); } - + void Test5() { int array[] = {1, 4, 9, 16}; - + typedef NPagedVector::TPagedVector<int, 3> TVectorType; TVectorType v(array, array + 4); - + UNIT_ASSERT(v.size() == 4); - + UNIT_ASSERT(v[0] == 1); UNIT_ASSERT(v[1] == 4); UNIT_ASSERT(v[2] == 9); UNIT_ASSERT(v[3] == 16); } - + void Test6() { int array[] = {1, 4, 9, 16, 25, 36}; - + typedef NPagedVector::TPagedVector<int, 3> TVectorType; TVectorType v(array, array + 6); TVectorType::iterator vit; - + UNIT_ASSERT_VALUES_EQUAL(v.size(), 6u); UNIT_ASSERT(v[0] == 1); UNIT_ASSERT(v[1] == 4); @@ -186,59 +186,59 @@ private: UNIT_ASSERT(v[3] == 16); UNIT_ASSERT(v[4] == 25); UNIT_ASSERT(v[5] == 36); - + vit = v.erase(v.begin()); // Erase first element. UNIT_ASSERT(*vit == 4); - + UNIT_ASSERT(v.size() == 5); UNIT_ASSERT(v[0] == 4); UNIT_ASSERT(v[1] == 9); UNIT_ASSERT(v[2] == 16); UNIT_ASSERT(v[3] == 25); UNIT_ASSERT(v[4] == 36); - + vit = v.erase(v.end() - 1); // Erase last element. UNIT_ASSERT(vit == v.end()); - + UNIT_ASSERT(v.size() == 4); UNIT_ASSERT(v[0] == 4); UNIT_ASSERT(v[1] == 9); UNIT_ASSERT(v[2] == 16); UNIT_ASSERT(v[3] == 25); - + v.erase(v.begin() + 1, v.end() - 1); // Erase all but first and last. - + UNIT_ASSERT(v.size() == 2); UNIT_ASSERT(v[0] == 4); UNIT_ASSERT(v[1] == 25); } - + void Test7() { int array1[] = {1, 4, 25}; int array2[] = {9, 16}; - + typedef NPagedVector::TPagedVector<int, 3> TVectorType; - + TVectorType v(array1, array1 + 3); TVectorType::iterator vit; vit = v.insert(v.begin(), 0); // Insert before first element. UNIT_ASSERT_VALUES_EQUAL(*vit, 0); - + vit = v.insert(v.end(), 36); // Insert after last element. UNIT_ASSERT(*vit == 36); - + UNIT_ASSERT(v.size() == 5); UNIT_ASSERT(v[0] == 0); UNIT_ASSERT(v[1] == 1); UNIT_ASSERT(v[2] == 4); UNIT_ASSERT(v[3] == 25); UNIT_ASSERT(v[4] == 36); - + // Insert contents of array2 before fourth element. v.insert(v.begin() + 3, array2, array2 + 2); - + UNIT_ASSERT(v.size() == 7); - + UNIT_ASSERT(v[0] == 0); UNIT_ASSERT(v[1] == 1); UNIT_ASSERT(v[2] == 4); @@ -246,21 +246,21 @@ private: UNIT_ASSERT(v[4] == 16); UNIT_ASSERT(v[5] == 25); UNIT_ASSERT(v[6] == 36); - + v.clear(); UNIT_ASSERT(v.empty()); } - + void TestAt() { using NPagedVector::TPagedVector; TPagedVector<int, 3> v; TPagedVector<int, 3> const& cv = v; - + v.push_back(10); UNIT_ASSERT(v.at(0) == 10); v.at(0) = 20; UNIT_ASSERT(cv.at(0) == 20); - + for (;;) { try { v.at(1) = 20; @@ -269,10 +269,10 @@ private: return; } catch (...) { UNIT_ASSERT(false); - } - } + } + } } - + void TestAutoRef() { using NPagedVector::TPagedVector; typedef TPagedVector<int, 3> TVec; @@ -280,7 +280,7 @@ private: for (int i = 0; i < 5; ++i) { ref.push_back(i); } - + TPagedVector<TVec, 3> v_v_int; v_v_int.push_back(ref); v_v_int.push_back(v_v_int[0]); @@ -288,17 +288,17 @@ private: v_v_int.push_back(v_v_int[0]); v_v_int.push_back(v_v_int[0]); v_v_int.push_back(ref); - + TPagedVector<TVec, 3>::iterator vvit(v_v_int.begin()), vvitEnd(v_v_int.end()); for (; vvit != vvitEnd; ++vvit) { UNIT_ASSERT(*vvit == ref); - } + } } - + struct Point { int x, y; }; - + struct PointEx: public Point { PointEx() : builtFromBase(false) @@ -308,42 +308,42 @@ private: : builtFromBase(true) { } - + bool builtFromBase; }; - + void TestIterators() { using NPagedVector::TPagedVector; TPagedVector<int, 3> vint; vint.resize(10); TPagedVector<int, 3> const& crvint = vint; - + UNIT_ASSERT(vint.begin() == vint.begin()); UNIT_ASSERT(crvint.begin() == vint.begin()); UNIT_ASSERT(vint.begin() == crvint.begin()); UNIT_ASSERT(crvint.begin() == crvint.begin()); - + UNIT_ASSERT(vint.begin() != vint.end()); UNIT_ASSERT(crvint.begin() != vint.end()); UNIT_ASSERT(vint.begin() != crvint.end()); UNIT_ASSERT(crvint.begin() != crvint.end()); - + UNIT_ASSERT(vint.rbegin() == vint.rbegin()); // Not Standard: //UNIT_ASSERT(vint.rbegin() == crvint.rbegin()); //UNIT_ASSERT(crvint.rbegin() == vint.rbegin()); UNIT_ASSERT(crvint.rbegin() == crvint.rbegin()); - + UNIT_ASSERT(vint.rbegin() != vint.rend()); // Not Standard: //UNIT_ASSERT(vint.rbegin() != crvint.rend()); //UNIT_ASSERT(crvint.rbegin() != vint.rend()); UNIT_ASSERT(crvint.rbegin() != crvint.rend()); } - + /* This test check a potential issue with empty base class - * optimization. Some compilers (VC6) do not implement it - * correctly resulting ina wrong behavior. */ + * optimization. Some compilers (VC6) do not implement it + * correctly resulting ina wrong behavior. */ void TestEbo() { using NPagedVector::TPagedVector; // We use heap memory as test failure can corrupt vector internal @@ -352,27 +352,27 @@ private: // by size or capacity checks. typedef TPagedVector<int, 3> V; V* pv1 = new V; - + pv1->resize(1); pv1->at(0) = 1; - + V* pv2 = new V; - + pv2->resize(10); for (int i = 0; i < 10; ++i) pv2->at(i) = 2; - + pv1->swap(*pv2); - + UNIT_ASSERT(pv1->size() == 10); UNIT_ASSERT((*pv1)[5] == 2); - + UNIT_ASSERT(pv2->size() == 1); UNIT_ASSERT((*pv2)[0] == 1); - + delete pv2; delete pv1; } -}; - -UNIT_TEST_SUITE_REGISTRATION(TPagedVectorTest); +}; + +UNIT_TEST_SUITE_REGISTRATION(TPagedVectorTest); diff --git a/library/cpp/containers/str_map/str_map.h b/library/cpp/containers/str_map/str_map.h index f734e74550..31b00d1b99 100644 --- a/library/cpp/containers/str_map/str_map.h +++ b/library/cpp/containers/str_map/str_map.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include <util/memory/segmented_string_pool.h> #include <util/generic/map.h> |