diff options
author | tldr <tldr@yandex-team.ru> | 2022-02-10 16:50:18 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:18 +0300 |
commit | 42d219fbd63ee173b0cb7db1b26a3ec615f0bb71 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 | |
parent | fb217752f4b5a81abe9df05e38c5a71d080fc2a8 (diff) | |
download | ydb-42d219fbd63ee173b0cb7db1b26a3ec615f0bb71.tar.gz |
Restoring authorship annotation for <tldr@yandex-team.ru>. Commit 2 of 2.
-rw-r--r-- | build/sysincl/darwin.yml | 2 | ||||
-rw-r--r-- | build/ya.conf.json | 2 | ||||
-rw-r--r-- | library/cpp/cache/cache.h | 182 | ||||
-rw-r--r-- | library/cpp/cache/ut/cache_ut.cpp | 134 | ||||
-rw-r--r-- | library/cpp/getopt/small/completion_generator.cpp | 4 | ||||
-rw-r--r-- | library/cpp/getopt/small/modchooser.cpp | 32 | ||||
-rw-r--r-- | library/cpp/getopt/small/modchooser.h | 12 | ||||
-rw-r--r-- | util/folder/path.cpp | 38 | ||||
-rw-r--r-- | util/folder/path.h | 40 | ||||
-rw-r--r-- | util/folder/path_ut.cpp | 82 |
10 files changed, 264 insertions, 264 deletions
diff --git a/build/sysincl/darwin.yml b/build/sysincl/darwin.yml index 2a7aa975e7..582c7e1202 100644 --- a/build/sysincl/darwin.yml +++ b/build/sysincl/darwin.yml @@ -30,7 +30,7 @@ - CommonCrypto/CommonHMAC.h - CommonCrypto/CommonKeyDerivation.h - ConditionalMacros.h - - DiskArbitration/DiskArbitration.h + - DiskArbitration/DiskArbitration.h - Endian.h - MacTypes.h - TargetConditionals.h diff --git a/build/ya.conf.json b/build/ya.conf.json index 5fb238590d..5f7cc875d6 100644 --- a/build/ya.conf.json +++ b/build/ya.conf.json @@ -5798,7 +5798,7 @@ "arc": { "formula": { "sandbox_id": [ - 1205199935 + 1205199935 ], "match": "arc" }, diff --git a/library/cpp/cache/cache.h b/library/cpp/cache/cache.h index 2314b588ea..6dc997076d 100644 --- a/library/cpp/cache/cache.h +++ b/library/cpp/cache/cache.h @@ -8,26 +8,26 @@ #include <util/generic/yexception.h> #include <utility> -template <class TValue> -struct TUniformSizeProvider { - size_t operator()(const TValue&) { - return 1; - } -}; - -template <typename TKey, typename TValue, class TSizeProvider = TUniformSizeProvider<TValue>> +template <class TValue> +struct TUniformSizeProvider { + size_t operator()(const TValue&) { + return 1; + } +}; + +template <typename TKey, typename TValue, class TSizeProvider = TUniformSizeProvider<TValue>> class TLRUList { public: - TLRUList(size_t maxSize, const TSizeProvider& sizeProvider = TSizeProvider()) + TLRUList(size_t maxSize, const TSizeProvider& sizeProvider = TSizeProvider()) : List() - , SizeProvider(sizeProvider) - , ItemsAmount(0) - , TotalSize(0) + , SizeProvider(sizeProvider) + , ItemsAmount(0) + , TotalSize(0) , MaxSize(maxSize) { } -public: +public: struct TItem: public TIntrusiveListItem<TItem> { typedef TIntrusiveListItem<TItem> TBase; TItem(const TKey& key, const TValue& value = TValue()) @@ -65,15 +65,15 @@ public: public: TItem* Insert(TItem* item) { List.PushBack(item); - ++ItemsAmount; - TotalSize += SizeProvider(item->Value); - - return RemoveIfOverflown(); - } - - TItem* RemoveIfOverflown() { + ++ItemsAmount; + TotalSize += SizeProvider(item->Value); + + return RemoveIfOverflown(); + } + + TItem* RemoveIfOverflown() { TItem* deleted = nullptr; - if (TotalSize > MaxSize && ItemsAmount > 1) { + if (TotalSize > MaxSize && ItemsAmount > 1) { deleted = GetOldest(); Erase(deleted); } @@ -88,8 +88,8 @@ public: void Erase(TItem* item) { item->Unlink(); - --ItemsAmount; - TotalSize -= SizeProvider(item->Value); + --ItemsAmount; + TotalSize -= SizeProvider(item->Value); } void Promote(TItem* item) { @@ -98,7 +98,7 @@ public: } size_t GetSize() const { - return ItemsAmount; + return ItemsAmount; } size_t GetTotalSize() const { @@ -118,9 +118,9 @@ public: private: typedef TIntrusiveList<TItem> TListType; TListType List; - TSizeProvider SizeProvider; - size_t ItemsAmount; - size_t TotalSize; + TSizeProvider SizeProvider; + size_t ItemsAmount; + size_t TotalSize; size_t MaxSize; }; @@ -175,11 +175,11 @@ public: TItem* Insert(TItem* item) { List.PushBack(item); // give a chance for promotion ++ListSize; - - return RemoveIfOverflown(); - } - - TItem* RemoveIfOverflown() { + + return RemoveIfOverflown(); + } + + TItem* RemoveIfOverflown() { TItem* deleted = nullptr; if (ListSize > MaxSize) { deleted = GetLeastFrequentlyUsed(); @@ -283,35 +283,35 @@ public: public: TItem* Insert(TItem* item) { - FixHeap(); - - if (Size >= MaxSize && item->Weight < GetLightest()->Weight) { - return item; - } - - Heap.push_back(item); - PushHeap(Heap.begin(), Heap.end(), THeapComparator()); - ++Size; - - return RemoveIfOverflown(); - } - - TItem* RemoveIfOverflown() { - if (Size <= MaxSize) { + FixHeap(); + + if (Size >= MaxSize && item->Weight < GetLightest()->Weight) { + return item; + } + + Heap.push_back(item); + PushHeap(Heap.begin(), Heap.end(), THeapComparator()); + ++Size; + + return RemoveIfOverflown(); + } + + TItem* RemoveIfOverflown() { + if (Size <= MaxSize) { return nullptr; } - - auto lightest = GetLightest(); - Erase(lightest); - PopHeap(Heap.begin(), Heap.end(), THeapComparator()); - return lightest; + + auto lightest = GetLightest(); + Erase(lightest); + PopHeap(Heap.begin(), Heap.end(), THeapComparator()); + return lightest; } TItem* GetLightest() { - FixHeap(); - + FixHeap(); + Y_ASSERT(!Heap.empty()); - + return Heap.front(); } @@ -320,16 +320,16 @@ public: // and will be deleted on-access (using FixHeap method) void Erase(TItem* item) { Y_ASSERT(Size > 0); - + --Size; - Removed.insert(item); + Removed.insert(item); } void Promote(TItem*) { // do nothing } - [[nodiscard]] size_t GetSize() const { + [[nodiscard]] size_t GetSize() const { return Size; } @@ -349,20 +349,20 @@ public: Size = 0; } -private: +private: // Physically remove erased elements from the heap void FixHeap() { - if (Removed.empty()) { - return; + if (Removed.empty()) { + return; } - - Heap.erase(std::remove_if(Heap.begin(), Heap.end(), [this](TItem* item) { - return this->Removed.contains(item); - }), - Heap.end()); - MakeHeap(Heap.begin(), Heap.end(), THeapComparator()); - Removed.clear(); - Size = Heap.size(); + + Heap.erase(std::remove_if(Heap.begin(), Heap.end(), [this](TItem* item) { + return this->Removed.contains(item); + }), + Heap.end()); + MakeHeap(Heap.begin(), Heap.end(), THeapComparator()); + Removed.clear(); + Size = Heap.size(); } private: @@ -424,9 +424,9 @@ public: TIndexConstIterator Iter; }; - TCache(TListType&& list, bool multiValue = false) + TCache(TListType&& list, bool multiValue = false) : Index() - , List(std::move(list)) + , List(std::move(list)) , MultiValue(multiValue) { } @@ -482,18 +482,18 @@ public: TIndexIterator it = Index.insert(tmpItem); TItem* insertedItem = const_cast<TItem*>(&*it); - auto removedItem = List.Insert(insertedItem); - auto insertedWasRemoved = removedItem == insertedItem; + auto removedItem = List.Insert(insertedItem); + auto insertedWasRemoved = removedItem == insertedItem; if (removedItem) { EraseFromIndex(removedItem); - while ((removedItem = List.RemoveIfOverflown())) { - insertedWasRemoved = insertedWasRemoved || insertedItem == removedItem; - EraseFromIndex(removedItem); - } + while ((removedItem = List.RemoveIfOverflown())) { + insertedWasRemoved = insertedWasRemoved || insertedItem == removedItem; + EraseFromIndex(removedItem); + } } Y_ASSERT(Index.size() == List.GetSize()); - return !insertedWasRemoved; + return !insertedWasRemoved; } void Update(const TKey& key, const TValue& value) { @@ -574,20 +574,20 @@ struct TNoopDelete { } }; -template <typename TKey, typename TValue, typename TDeleter = TNoopDelete, class TSizeProvider = TUniformSizeProvider<TValue>> -class TLRUCache: public TCache<TKey, TValue, TLRUList<TKey, TValue, TSizeProvider>, TDeleter> { - using TListType = TLRUList<TKey, TValue, TSizeProvider>; - typedef TCache<TKey, TValue, TListType, TDeleter> TBase; +template <typename TKey, typename TValue, typename TDeleter = TNoopDelete, class TSizeProvider = TUniformSizeProvider<TValue>> +class TLRUCache: public TCache<TKey, TValue, TLRUList<TKey, TValue, TSizeProvider>, TDeleter> { + using TListType = TLRUList<TKey, TValue, TSizeProvider>; + typedef TCache<TKey, TValue, TListType, TDeleter> TBase; public: - TLRUCache(size_t maxSize, bool multiValue = false, const TSizeProvider& sizeProvider = TSizeProvider()) - : TBase(TListType(maxSize, sizeProvider), multiValue) + TLRUCache(size_t maxSize, bool multiValue = false, const TSizeProvider& sizeProvider = TSizeProvider()) + : TBase(TListType(maxSize, sizeProvider), multiValue) { } -public: - typedef typename TBase::TIterator TIterator; - +public: + typedef typename TBase::TIterator TIterator; + TValue& GetOldest() { return TBase::List.GetOldest()->Value; } @@ -604,13 +604,13 @@ public: template <typename TKey, typename TValue, typename TDeleter = TNoopDelete> class TLFUCache: public TCache<TKey, TValue, TLFUList<TKey, TValue>, TDeleter> { typedef TCache<TKey, TValue, TLFUList<TKey, TValue>, TDeleter> TBase; - using TListType = TLFUList<TKey, TValue>; + using TListType = TLFUList<TKey, TValue>; public: typedef typename TBase::TIterator TIterator; TLFUCache(size_t maxSize, bool multiValue = false) - : TBase(TListType(maxSize), multiValue) + : TBase(TListType(maxSize), multiValue) { } @@ -629,13 +629,13 @@ public: template <typename TKey, typename TValue, typename TWeight, typename TWeighter, typename TDeleter = TNoopDelete> class TLWCache: public TCache<TKey, TValue, TLWList<TKey, TValue, TWeight, TWeighter>, TDeleter> { typedef TCache<TKey, TValue, TLWList<TKey, TValue, TWeight, TWeighter>, TDeleter> TBase; - using TListType = TLWList<TKey, TValue, TWeight, TWeighter>; + using TListType = TLWList<TKey, TValue, TWeight, TWeighter>; public: typedef typename TBase::TIterator TIterator; TLWCache(size_t maxSize, bool multiValue = false) - : TBase(TListType(maxSize), multiValue) + : TBase(TListType(maxSize), multiValue) { } diff --git a/library/cpp/cache/ut/cache_ut.cpp b/library/cpp/cache/ut/cache_ut.cpp index 886afecb88..329872cfde 100644 --- a/library/cpp/cache/ut/cache_ut.cpp +++ b/library/cpp/cache/ut/cache_ut.cpp @@ -29,42 +29,42 @@ Y_UNIT_TEST_SUITE(TCacheTest) { UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 1); } - Y_UNIT_TEST(LRUListWeightedTest) { - typedef TLRUList<int, TString, size_t (*)(const TString&)> TListType; - TListType list(7, [](auto& string) { - return string.size(); - }); - - TListType::TItem x1(1, "ttt"); - list.Insert(&x1); - while (list.RemoveIfOverflown()) { - } - UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 1); - - TListType::TItem x2(2, "yyy"); - list.Insert(&x2); - while (list.RemoveIfOverflown()) { - } - UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 1); - - list.Promote(list.GetOldest()); - while (list.RemoveIfOverflown()) { - } - UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 2); - - TListType::TItem x3(3, "zzz"); - list.Insert(&x3); - while (list.RemoveIfOverflown()) { - } - UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 1); - - TListType::TItem x4(4, "longlong"); - list.Insert(&x4); - while (list.RemoveIfOverflown()) { - } - UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 4); - } - + Y_UNIT_TEST(LRUListWeightedTest) { + typedef TLRUList<int, TString, size_t (*)(const TString&)> TListType; + TListType list(7, [](auto& string) { + return string.size(); + }); + + TListType::TItem x1(1, "ttt"); + list.Insert(&x1); + while (list.RemoveIfOverflown()) { + } + UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 1); + + TListType::TItem x2(2, "yyy"); + list.Insert(&x2); + while (list.RemoveIfOverflown()) { + } + UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 1); + + list.Promote(list.GetOldest()); + while (list.RemoveIfOverflown()) { + } + UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 2); + + TListType::TItem x3(3, "zzz"); + list.Insert(&x3); + while (list.RemoveIfOverflown()) { + } + UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 1); + + TListType::TItem x4(4, "longlong"); + list.Insert(&x4); + while (list.RemoveIfOverflown()) { + } + UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 4); + } + Y_UNIT_TEST(LFUListTest) { typedef TLFUList<int, TString> TListType; TListType list(2); @@ -141,37 +141,37 @@ Y_UNIT_TEST_SUITE(TCacheTest) { UNIT_ASSERT(s.Find(3) == s.End()); } - Y_UNIT_TEST(LRUWithCustomSizeProviderTest) { - typedef TLRUCache<int, TString, TNoopDelete, size_t(*)(const TString&)> TCache; - TCache s(10, false, [](auto& string) { return string.size(); }); // size 10 - s.Insert(1, "abcd"); - UNIT_ASSERT(s.Find(1) != s.End()); - UNIT_ASSERT_EQUAL(*s.Find(1), "abcd"); - s.Insert(2, "defg"); - UNIT_ASSERT(s.GetOldest() == "abcd"); - s.Insert(3, "2c"); - UNIT_ASSERT(s.GetOldest() == "abcd"); - s.Insert(4, "hjkl"); - UNIT_ASSERT(s.GetOldest() == "defg"); - // key 1 will be deleted - UNIT_ASSERT(s.Find(1) == s.End()); - UNIT_ASSERT(s.Find(2) != s.End()); - UNIT_ASSERT(*s.Find(2) == "defg"); - UNIT_ASSERT(s.Find(3) != s.End()); - UNIT_ASSERT(*s.Find(3) == "2c"); - UNIT_ASSERT(s.Find(4) != s.End()); - UNIT_ASSERT(*s.Find(4) == "hjkl"); - - UNIT_ASSERT(!s.Insert(3, "abcd")); - UNIT_ASSERT(*s.Find(3) == "2c"); - s.Update(3, "abcd"); - UNIT_ASSERT(*s.Find(3) == "abcd"); - - TCache::TIterator it = s.Find(3); - s.Erase(it); - UNIT_ASSERT(s.Find(3) == s.End()); - } - + Y_UNIT_TEST(LRUWithCustomSizeProviderTest) { + typedef TLRUCache<int, TString, TNoopDelete, size_t(*)(const TString&)> TCache; + TCache s(10, false, [](auto& string) { return string.size(); }); // size 10 + s.Insert(1, "abcd"); + UNIT_ASSERT(s.Find(1) != s.End()); + UNIT_ASSERT_EQUAL(*s.Find(1), "abcd"); + s.Insert(2, "defg"); + UNIT_ASSERT(s.GetOldest() == "abcd"); + s.Insert(3, "2c"); + UNIT_ASSERT(s.GetOldest() == "abcd"); + s.Insert(4, "hjkl"); + UNIT_ASSERT(s.GetOldest() == "defg"); + // key 1 will be deleted + UNIT_ASSERT(s.Find(1) == s.End()); + UNIT_ASSERT(s.Find(2) != s.End()); + UNIT_ASSERT(*s.Find(2) == "defg"); + UNIT_ASSERT(s.Find(3) != s.End()); + UNIT_ASSERT(*s.Find(3) == "2c"); + UNIT_ASSERT(s.Find(4) != s.End()); + UNIT_ASSERT(*s.Find(4) == "hjkl"); + + UNIT_ASSERT(!s.Insert(3, "abcd")); + UNIT_ASSERT(*s.Find(3) == "2c"); + s.Update(3, "abcd"); + UNIT_ASSERT(*s.Find(3) == "abcd"); + + TCache::TIterator it = s.Find(3); + s.Erase(it); + UNIT_ASSERT(s.Find(3) == s.End()); + } + Y_UNIT_TEST(LRUSetMaxSizeTest) { typedef TLRUCache<int, TString> TCache; TCache s(2); // size 2 diff --git a/library/cpp/getopt/small/completion_generator.cpp b/library/cpp/getopt/small/completion_generator.cpp index 3e8a5302b4..ac41988217 100644 --- a/library/cpp/getopt/small/completion_generator.cpp +++ b/library/cpp/getopt/small/completion_generator.cpp @@ -453,7 +453,7 @@ namespace NLastGetopt { auto& line = L << "COMPREPLY+=( $(compgen -W '"; TStringBuf sep = ""; for (auto& mode : modes) { - if (!mode->Hidden && !mode->NoCompletion) { + if (!mode->Hidden && !mode->NoCompletion) { line << sep << B(mode->Name); sep = " "; } @@ -470,7 +470,7 @@ namespace NLastGetopt { I; for (auto& mode : modes) { - if (mode->Name.empty() || mode->Hidden || mode->NoCompletion) { + if (mode->Name.empty() || mode->Hidden || mode->NoCompletion) { continue; } diff --git a/library/cpp/getopt/small/modchooser.cpp b/library/cpp/getopt/small/modchooser.cpp index 3e37a768e1..2fa5cfd070 100644 --- a/library/cpp/getopt/small/modchooser.cpp +++ b/library/cpp/getopt/small/modchooser.cpp @@ -60,12 +60,12 @@ private: TMainClassV* Main; }; -TModChooser::TMode::TMode(const TString& name, TMainClass* main, const TString& descr, bool hidden, bool noCompletion) +TModChooser::TMode::TMode(const TString& name, TMainClass* main, const TString& descr, bool hidden, bool noCompletion) : Name(name) , Main(main) , Description(descr) , Hidden(hidden) - , NoCompletion(noCompletion) + , NoCompletion(noCompletion) { } @@ -80,25 +80,25 @@ TModChooser::TModChooser() TModChooser::~TModChooser() = default; -void TModChooser::AddMode(const TString& mode, const TMainFunctionRawPtr func, const TString& description, bool hidden, bool noCompletion) { - AddMode(mode, TMainFunctionPtr(func), description, hidden, noCompletion); +void TModChooser::AddMode(const TString& mode, const TMainFunctionRawPtr func, const TString& description, bool hidden, bool noCompletion) { + AddMode(mode, TMainFunctionPtr(func), description, hidden, noCompletion); } -void TModChooser::AddMode(const TString& mode, const TMainFunctionRawPtrV func, const TString& description, bool hidden, bool noCompletion) { - AddMode(mode, TMainFunctionPtrV(func), description, hidden, noCompletion); +void TModChooser::AddMode(const TString& mode, const TMainFunctionRawPtrV func, const TString& description, bool hidden, bool noCompletion) { + AddMode(mode, TMainFunctionPtrV(func), description, hidden, noCompletion); } -void TModChooser::AddMode(const TString& mode, const TMainFunctionPtr func, const TString& description, bool hidden, bool noCompletion) { +void TModChooser::AddMode(const TString& mode, const TMainFunctionPtr func, const TString& description, bool hidden, bool noCompletion) { Wrappers.push_back(MakeHolder<PtrWrapper>(func)); - AddMode(mode, Wrappers.back().Get(), description, hidden, noCompletion); + AddMode(mode, Wrappers.back().Get(), description, hidden, noCompletion); } -void TModChooser::AddMode(const TString& mode, const TMainFunctionPtrV func, const TString& description, bool hidden, bool noCompletion) { +void TModChooser::AddMode(const TString& mode, const TMainFunctionPtrV func, const TString& description, bool hidden, bool noCompletion) { Wrappers.push_back(MakeHolder<PtrvWrapper>(func)); - AddMode(mode, Wrappers.back().Get(), description, hidden, noCompletion); + AddMode(mode, Wrappers.back().Get(), description, hidden, noCompletion); } -void TModChooser::AddMode(const TString& mode, TMainClass* func, const TString& description, bool hidden, bool noCompletion) { +void TModChooser::AddMode(const TString& mode, TMainClass* func, const TString& description, bool hidden, bool noCompletion) { if (Modes.FindPtr(mode)) { ythrow yexception() << "TMode '" << mode << "' already exists in TModChooser."; } @@ -106,12 +106,12 @@ void TModChooser::AddMode(const TString& mode, TMainClass* func, const TString& Modes[mode] = UnsortedModes.emplace_back(MakeHolder<TMode>(mode, func, description, hidden, noCompletion)).Get(); } -void TModChooser::AddMode(const TString& mode, TMainClassV* func, const TString& description, bool hidden, bool noCompletion) { +void TModChooser::AddMode(const TString& mode, TMainClassV* func, const TString& description, bool hidden, bool noCompletion) { Wrappers.push_back(MakeHolder<ClassWrapper>(func)); - AddMode(mode, Wrappers.back().Get(), description, hidden, noCompletion); + AddMode(mode, Wrappers.back().Get(), description, hidden, noCompletion); } -void TModChooser::AddGroupModeDescription(const TString& description, bool hidden, bool noCompletion) { +void TModChooser::AddGroupModeDescription(const TString& description, bool hidden, bool noCompletion) { UnsortedModes.push_back(MakeHolder<TMode>(TString(), nullptr, description.data(), hidden, noCompletion)); } @@ -156,10 +156,10 @@ void TModChooser::DisableSvnRevisionOption() { SvnRevisionOptionDisabled = true; } -void TModChooser::AddCompletions(TString progName, const TString& name, bool hidden, bool noCompletion) { +void TModChooser::AddCompletions(TString progName, const TString& name, bool hidden, bool noCompletion) { if (CompletionsGenerator == nullptr) { CompletionsGenerator = NLastGetopt::MakeCompletionMod(this, std::move(progName), name); - AddMode(name, CompletionsGenerator.Get(), "generate autocompletion files", hidden, noCompletion); + AddMode(name, CompletionsGenerator.Get(), "generate autocompletion files", hidden, noCompletion); } } diff --git a/library/cpp/getopt/small/modchooser.h b/library/cpp/getopt/small/modchooser.h index 2b9cf2246b..0a8de6d50b 100644 --- a/library/cpp/getopt/small/modchooser.h +++ b/library/cpp/getopt/small/modchooser.h @@ -51,11 +51,11 @@ public: void AddMode(const TString& mode, TMainFunctionRawPtrV func, const TString& description, bool hidden = false, bool noCompletion = false); void AddMode(const TString& mode, TMainFunctionPtr func, const TString& description, bool hidden = false, bool noCompletion = false); void AddMode(const TString& mode, TMainFunctionPtrV func, const TString& description, bool hidden = false, bool noCompletion = false); - void AddMode(const TString& mode, TMainClass* func, const TString& description, bool hidden = false, bool noCompletion = false); - void AddMode(const TString& mode, TMainClassV* func, const TString& description, bool hidden = false, bool noCompletion = false); + void AddMode(const TString& mode, TMainClass* func, const TString& description, bool hidden = false, bool noCompletion = false); + void AddMode(const TString& mode, TMainClassV* func, const TString& description, bool hidden = false, bool noCompletion = false); //! Hidden groups won't be displayed in 'help' block - void AddGroupModeDescription(const TString& description, bool hidden = false, bool noCompletion = false); + void AddGroupModeDescription(const TString& description, bool hidden = false, bool noCompletion = false); //! Set default mode (if not specified explicitly) void SetDefaultMode(const TString& mode); @@ -82,7 +82,7 @@ public: void DisableSvnRevisionOption(); - void AddCompletions(TString progName, const TString& name = "completion", bool hidden = false, bool noCompletion = false); + void AddCompletions(TString progName, const TString& name = "completion", bool hidden = false, bool noCompletion = false); /*! Run appropriate mode. * @@ -107,7 +107,7 @@ public: TMainClass* Main; TString Description; bool Hidden; - bool NoCompletion; + bool NoCompletion; TVector<TString> Aliases; TMode() @@ -115,7 +115,7 @@ public: { } - TMode(const TString& name, TMainClass* main, const TString& descr, bool hidden, bool noCompletion); + TMode(const TString& name, TMainClass* main, const TString& descr, bool hidden, bool noCompletion); // Full name includes primary name and aliases. Also, will add ANSI colors. size_t CalculateFullNameLen() const; diff --git a/util/folder/path.cpp b/util/folder/path.cpp index 400fa90741..bfe0c67d68 100644 --- a/util/folder/path.cpp +++ b/util/folder/path.cpp @@ -40,25 +40,25 @@ bool TFsPath::IsSubpathOf(const TFsPath& that) const { return std::equal(rsplit.begin(), rsplit.end(), split.begin()); } -bool TFsPath::IsNonStrictSubpathOf(const TFsPath& that) const { - const TSplit& split = GetSplit(); - const TSplit& rsplit = that.GetSplit(); - - if (rsplit.IsAbsolute != split.IsAbsolute) { - return false; - } - - if (rsplit.Drive != split.Drive) { - return false; - } - - if (rsplit.size() > split.size()) { - return false; - } - - return std::equal(rsplit.begin(), rsplit.end(), split.begin()); -} - +bool TFsPath::IsNonStrictSubpathOf(const TFsPath& that) const { + const TSplit& split = GetSplit(); + const TSplit& rsplit = that.GetSplit(); + + if (rsplit.IsAbsolute != split.IsAbsolute) { + return false; + } + + if (rsplit.Drive != split.Drive) { + return false; + } + + if (rsplit.size() > split.size()) { + return false; + } + + return std::equal(rsplit.begin(), rsplit.end(), split.begin()); +} + TFsPath TFsPath::RelativeTo(const TFsPath& root) const { TSplit split = GetSplit(); const TSplit& rsplit = root.GetSplit(); diff --git a/util/folder/path.h b/util/folder/path.h index 4582b3fe7b..2fb4d6b4ef 100644 --- a/util/folder/path.h +++ b/util/folder/path.h @@ -88,27 +88,27 @@ public: bool IsAbsolute() const; bool IsRelative() const; - /** - * TFsPath("/a/b").IsSubpathOf("/a") -> true - * - * TFsPath("/a").IsSubpathOf("/a") -> false - * - * TFsPath("/a").IsSubpathOf("/other/path") -> false - * @param that - presumable parent path of this - * @return True if this is a subpath of that and false otherwise. - */ + /** + * TFsPath("/a/b").IsSubpathOf("/a") -> true + * + * TFsPath("/a").IsSubpathOf("/a") -> false + * + * TFsPath("/a").IsSubpathOf("/other/path") -> false + * @param that - presumable parent path of this + * @return True if this is a subpath of that and false otherwise. + */ bool IsSubpathOf(const TFsPath& that) const; - - /** - * TFsPath("/a/b").IsNonStrictSubpathOf("/a") -> true - * - * TFsPath("/a").IsNonStrictSubpathOf("/a") -> true - * - * TFsPath("/a").IsNonStrictSubpathOf("/other/path") -> false - * @param that - presumable parent path of this - * @return True if this is a subpath of that or they are equivalent and false otherwise. - */ - bool IsNonStrictSubpathOf(const TFsPath& that) const; + + /** + * TFsPath("/a/b").IsNonStrictSubpathOf("/a") -> true + * + * TFsPath("/a").IsNonStrictSubpathOf("/a") -> true + * + * TFsPath("/a").IsNonStrictSubpathOf("/other/path") -> false + * @param that - presumable parent path of this + * @return True if this is a subpath of that or they are equivalent and false otherwise. + */ + bool IsNonStrictSubpathOf(const TFsPath& that) const; bool IsContainerOf(const TFsPath& that) const { return that.IsSubpathOf(*this); diff --git a/util/folder/path_ut.cpp b/util/folder/path_ut.cpp index d8cc8ac133..e6a3451016 100644 --- a/util/folder/path_ut.cpp +++ b/util/folder/path_ut.cpp @@ -293,47 +293,47 @@ Y_UNIT_TEST_SUITE(TFsPathTests) { #endif } - Y_UNIT_TEST(TestNonStrictSubpathOf) { - UNIT_ASSERT(TFsPath("/a/b/c/d").IsNonStrictSubpathOf("/a/b")); - - UNIT_ASSERT(TFsPath("/a").IsNonStrictSubpathOf("/")); - UNIT_ASSERT(!TFsPath("/").IsNonStrictSubpathOf("/a")); - - UNIT_ASSERT(TFsPath("/a/b").IsNonStrictSubpathOf("/a")); - UNIT_ASSERT(TFsPath("a/b").IsNonStrictSubpathOf("a")); - UNIT_ASSERT(!TFsPath("/a/b").IsNonStrictSubpathOf("/b")); - UNIT_ASSERT(!TFsPath("a/b").IsNonStrictSubpathOf("b")); - - // mixing absolute/relative - UNIT_ASSERT(!TFsPath("a").IsNonStrictSubpathOf("/")); - UNIT_ASSERT(!TFsPath("a").IsNonStrictSubpathOf("/a")); - UNIT_ASSERT(!TFsPath("/a").IsNonStrictSubpathOf("a")); - UNIT_ASSERT(!TFsPath("a/b").IsNonStrictSubpathOf("/a")); - UNIT_ASSERT(!TFsPath("/a/b").IsNonStrictSubpathOf("a")); - - // equal paths - UNIT_ASSERT(TFsPath("").IsNonStrictSubpathOf("")); - UNIT_ASSERT(TFsPath("/").IsNonStrictSubpathOf("/")); - UNIT_ASSERT(TFsPath("a").IsNonStrictSubpathOf("a")); - UNIT_ASSERT(TFsPath("/a").IsNonStrictSubpathOf("/a")); - UNIT_ASSERT(TFsPath("/a").IsNonStrictSubpathOf("/a/")); - UNIT_ASSERT(TFsPath("/a/").IsNonStrictSubpathOf("/a")); - UNIT_ASSERT(TFsPath("/a/").IsNonStrictSubpathOf("/a/")); - -#ifdef _win_ - UNIT_ASSERT(TFsPath("x:/a/b").IsNonStrictSubpathOf("x:/a")); - - UNIT_ASSERT(TFsPath("x:/a").IsNonStrictSubpathOf("x:/a")); - UNIT_ASSERT(TFsPath("x:/a/").IsNonStrictSubpathOf("x:/a")); - UNIT_ASSERT(TFsPath("x:/a").IsNonStrictSubpathOf("x:/a/")); - UNIT_ASSERT(TFsPath("x:/a/").IsNonStrictSubpathOf("x:/a/")); - - UNIT_ASSERT(!TFsPath("x:/").IsNonStrictSubpathOf("y:/")); - UNIT_ASSERT(!TFsPath("x:/a/b").IsNonStrictSubpathOf("y:/a")); - UNIT_ASSERT(!TFsPath("x:/a/b").IsNonStrictSubpathOf("a")); -#endif - } - + Y_UNIT_TEST(TestNonStrictSubpathOf) { + UNIT_ASSERT(TFsPath("/a/b/c/d").IsNonStrictSubpathOf("/a/b")); + + UNIT_ASSERT(TFsPath("/a").IsNonStrictSubpathOf("/")); + UNIT_ASSERT(!TFsPath("/").IsNonStrictSubpathOf("/a")); + + UNIT_ASSERT(TFsPath("/a/b").IsNonStrictSubpathOf("/a")); + UNIT_ASSERT(TFsPath("a/b").IsNonStrictSubpathOf("a")); + UNIT_ASSERT(!TFsPath("/a/b").IsNonStrictSubpathOf("/b")); + UNIT_ASSERT(!TFsPath("a/b").IsNonStrictSubpathOf("b")); + + // mixing absolute/relative + UNIT_ASSERT(!TFsPath("a").IsNonStrictSubpathOf("/")); + UNIT_ASSERT(!TFsPath("a").IsNonStrictSubpathOf("/a")); + UNIT_ASSERT(!TFsPath("/a").IsNonStrictSubpathOf("a")); + UNIT_ASSERT(!TFsPath("a/b").IsNonStrictSubpathOf("/a")); + UNIT_ASSERT(!TFsPath("/a/b").IsNonStrictSubpathOf("a")); + + // equal paths + UNIT_ASSERT(TFsPath("").IsNonStrictSubpathOf("")); + UNIT_ASSERT(TFsPath("/").IsNonStrictSubpathOf("/")); + UNIT_ASSERT(TFsPath("a").IsNonStrictSubpathOf("a")); + UNIT_ASSERT(TFsPath("/a").IsNonStrictSubpathOf("/a")); + UNIT_ASSERT(TFsPath("/a").IsNonStrictSubpathOf("/a/")); + UNIT_ASSERT(TFsPath("/a/").IsNonStrictSubpathOf("/a")); + UNIT_ASSERT(TFsPath("/a/").IsNonStrictSubpathOf("/a/")); + +#ifdef _win_ + UNIT_ASSERT(TFsPath("x:/a/b").IsNonStrictSubpathOf("x:/a")); + + UNIT_ASSERT(TFsPath("x:/a").IsNonStrictSubpathOf("x:/a")); + UNIT_ASSERT(TFsPath("x:/a/").IsNonStrictSubpathOf("x:/a")); + UNIT_ASSERT(TFsPath("x:/a").IsNonStrictSubpathOf("x:/a/")); + UNIT_ASSERT(TFsPath("x:/a/").IsNonStrictSubpathOf("x:/a/")); + + UNIT_ASSERT(!TFsPath("x:/").IsNonStrictSubpathOf("y:/")); + UNIT_ASSERT(!TFsPath("x:/a/b").IsNonStrictSubpathOf("y:/a")); + UNIT_ASSERT(!TFsPath("x:/a/b").IsNonStrictSubpathOf("a")); +#endif + } + Y_UNIT_TEST(TestRelativePath) { UNIT_ASSERT_VALUES_EQUAL(TFsPath("/a/b/c/d").RelativePath(TFsPath("/a/b")), TFsPath("c/d")); UNIT_ASSERT_VALUES_EQUAL(TFsPath("/a/b/c/d").RelativePath(TFsPath("/a/b/e/f")), TFsPath("../../c/d")); |