aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/containers/comptrie
diff options
context:
space:
mode:
authorudovichenko-r <udovichenko-r@yandex-team.ru>2022-02-10 16:49:22 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:22 +0300
commita6f6b22bda21d53d07bd2e0ff63a2b2abf69ede9 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/containers/comptrie
parentd7e4eaec9d325e188dabb3eb1949a32a5229e9ce (diff)
downloadydb-a6f6b22bda21d53d07bd2e0ff63a2b2abf69ede9.tar.gz
Restoring authorship annotation for <udovichenko-r@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/containers/comptrie')
-rw-r--r--library/cpp/containers/comptrie/comptrie_impl.h60
-rw-r--r--library/cpp/containers/comptrie/comptrie_trie.h46
-rw-r--r--library/cpp/containers/comptrie/comptrie_ut.cpp116
-rw-r--r--library/cpp/containers/comptrie/protopacker.h2
4 files changed, 112 insertions, 112 deletions
diff --git a/library/cpp/containers/comptrie/comptrie_impl.h b/library/cpp/containers/comptrie/comptrie_impl.h
index 068bed2e6c..f41c38311a 100644
--- a/library/cpp/containers/comptrie/comptrie_impl.h
+++ b/library/cpp/containers/comptrie/comptrie_impl.h
@@ -182,40 +182,40 @@ namespace NCompactTrie {
// If there is a value associated with the symbol, makes the value pointer point to it,
// otherwise sets it to nullptr.
// Returns true if the symbol was succesfully found in the trie, false otherwise.
- template <typename TSymbol, class TPacker>
+ template <typename TSymbol, class TPacker>
Y_FORCE_INLINE bool Advance(const char*& datapos, const char* const dataend, const char*& value,
TSymbol label, TPacker packer) {
Y_ASSERT(datapos < dataend);
- char flags = MT_NEXT;
- for (int i = (int)ExtraBits<TSymbol>(); i >= 0; i -= 8) {
- flags = LeapByte(datapos, dataend, (char)(label >> i));
- if (!datapos) {
- return false; // no such arc
- }
-
+ char flags = MT_NEXT;
+ for (int i = (int)ExtraBits<TSymbol>(); i >= 0; i -= 8) {
+ flags = LeapByte(datapos, dataend, (char)(label >> i));
+ if (!datapos) {
+ return false; // no such arc
+ }
+
value = nullptr;
-
+
Y_ASSERT(datapos <= dataend);
- if ((flags & MT_FINAL)) {
- value = datapos;
- datapos += packer.SkipLeaf(datapos);
- }
-
- if (!(flags & MT_NEXT)) {
- if (i == 0) {
+ if ((flags & MT_FINAL)) {
+ value = datapos;
+ datapos += packer.SkipLeaf(datapos);
+ }
+
+ if (!(flags & MT_NEXT)) {
+ if (i == 0) {
datapos = nullptr;
- return true;
- }
- return false; // no further way
- }
-
- TraverseEpsilon(datapos);
- if (i == 0) { // last byte, and got a match
- return true;
- }
- }
-
- return false;
- }
-
+ return true;
+ }
+ return false; // no further way
+ }
+
+ TraverseEpsilon(datapos);
+ if (i == 0) { // last byte, and got a match
+ return true;
+ }
+ }
+
+ return false;
+ }
+
}
diff --git a/library/cpp/containers/comptrie/comptrie_trie.h b/library/cpp/containers/comptrie/comptrie_trie.h
index ffba10ae40..40ec1e52b3 100644
--- a/library/cpp/containers/comptrie/comptrie_trie.h
+++ b/library/cpp/containers/comptrie/comptrie_trie.h
@@ -139,7 +139,7 @@ public:
// same as FindTails(&key, 1), a bit faster
// return false, if no arc with @label exists
- inline bool FindTails(TSymbol label, TCompactTrie<T, D, S>& res) const;
+ inline bool FindTails(TSymbol label, TCompactTrie<T, D, S>& res) const;
class TConstIterator {
private:
@@ -361,28 +361,28 @@ bool TCompactTrie<T, D, S>::FindTails(const TSymbol* key, size_t keylen, TCompac
return true;
}
- const char* datastart = DataHolder.AsCharPtr();
- const char* datapos = datastart;
- const char* const dataend = datapos + len;
-
+ const char* datastart = DataHolder.AsCharPtr();
+ const char* datapos = datastart;
+ const char* const dataend = datapos + len;
+
const TSymbol* keyend = key + keylen;
const char* value = nullptr;
-
+
while (key != keyend) {
T label = *(key++);
- if (!NCompactTrie::Advance(datapos, dataend, value, label, Packer))
- return false;
+ if (!NCompactTrie::Advance(datapos, dataend, value, label, Packer))
+ return false;
- if (key == keyend) {
- if (datapos) {
+ if (key == keyend) {
+ if (datapos) {
Y_ASSERT(datapos >= datastart);
res = TCompactTrie<T, D, S>(TBlob::NoCopy(datapos, dataend - datapos), value);
- } else {
- res = TCompactTrie<T, D, S>(value);
+ } else {
+ res = TCompactTrie<T, D, S>(value);
}
- return true;
- } else if (!datapos) {
- return false; // No further way
+ return true;
+ } else if (!datapos) {
+ return false; // No further way
}
}
@@ -390,7 +390,7 @@ bool TCompactTrie<T, D, S>::FindTails(const TSymbol* key, size_t keylen, TCompac
}
template <class T, class D, class S>
-inline bool TCompactTrie<T, D, S>::FindTails(TSymbol label, TCompactTrie<T, D, S>& res) const {
+inline bool TCompactTrie<T, D, S>::FindTails(TSymbol label, TCompactTrie<T, D, S>& res) const {
using namespace NCompactTrie;
const size_t len = DataHolder.Length();
@@ -402,17 +402,17 @@ inline bool TCompactTrie<T, D, S>::FindTails(TSymbol label, TCompactTrie<T, D, S
const char* datapos = datastart;
const char* value = nullptr;
- if (!NCompactTrie::Advance(datapos, dataend, value, label, Packer))
- return false;
+ if (!NCompactTrie::Advance(datapos, dataend, value, label, Packer))
+ return false;
- if (datapos) {
+ if (datapos) {
Y_ASSERT(datapos >= datastart);
- res = TCompactTrie<T, D, S>(TBlob::NoCopy(datapos, dataend - datapos), value);
- } else {
- res = TCompactTrie<T, D, S>(value);
+ res = TCompactTrie<T, D, S>(TBlob::NoCopy(datapos, dataend - datapos), value);
+ } else {
+ res = TCompactTrie<T, D, S>(value);
}
- return true;
+ return true;
}
template <class T, class D, class S>
diff --git a/library/cpp/containers/comptrie/comptrie_ut.cpp b/library/cpp/containers/comptrie/comptrie_ut.cpp
index ea7df5c59d..74bee09b5d 100644
--- a/library/cpp/containers/comptrie/comptrie_ut.cpp
+++ b/library/cpp/containers/comptrie/comptrie_ut.cpp
@@ -96,7 +96,7 @@ private:
UNIT_TEST(TestSearchIterChar);
UNIT_TEST(TestSearchIterWchar);
UNIT_TEST(TestSearchIterWchar32)
-
+
UNIT_TEST(TestCopyAndAssignment);
UNIT_TEST(TestFirstSymbolIterator8);
@@ -152,9 +152,9 @@ private:
template <class TContainer>
void TestTrieWithContainers(const TVector<TUtf16String>& keys, const TVector<TContainer>& sampleData, TString methodName);
- template <typename TChar>
- void TestSearchIterImpl();
-
+ template <typename TChar>
+ void TestSearchIterImpl();
+
template <class TTrie>
void TestFirstSymbolIteratorForTrie(const TTrie& trie, const TStringBuf& narrowAnswers);
@@ -230,8 +230,8 @@ public:
void TestEmptyValueOutOfOrder();
void TestFindLongestPrefixWithEmptyValue();
- void TestSearchIterChar();
- void TestSearchIterWchar();
+ void TestSearchIterChar();
+ void TestSearchIterWchar();
void TestSearchIterWchar32();
void TestCopyAndAssignment();
@@ -1292,21 +1292,21 @@ void TCompactTrieTest::TestFindLongestPrefixWithEmptyValue() {
UNIT_ASSERT(value == 31415);
}
}
-
-template <typename TChar>
-struct TConvertKey {
+
+template <typename TChar>
+struct TConvertKey {
static inline TString Convert(const TStringBuf& key) {
return ToString(key);
- }
-};
-
-template <>
-struct TConvertKey<wchar16> {
+ }
+};
+
+template <>
+struct TConvertKey<wchar16> {
static inline TUtf16String Convert(const TStringBuf& key) {
- return UTF8ToWide(key);
- }
-};
-
+ return UTF8ToWide(key);
+ }
+};
+
template <>
struct TConvertKey<wchar32> {
static inline TUtf32String Convert(const TStringBuf& key) {
@@ -1314,62 +1314,62 @@ struct TConvertKey<wchar32> {
}
};
-template <class TSearchIter, class TKeyBuf>
-static void MoveIter(TSearchIter& iter, const TKeyBuf& key) {
- for (size_t i = 0; i < key.length(); ++i) {
- UNIT_ASSERT(iter.Advance(key[i]));
- }
-}
-
-template <typename TChar>
-void TCompactTrieTest::TestSearchIterImpl() {
- TBufferOutput buffer;
- {
- TCompactTrieBuilder<TChar, ui32> builder;
- TStringBuf data[] = {
+template <class TSearchIter, class TKeyBuf>
+static void MoveIter(TSearchIter& iter, const TKeyBuf& key) {
+ for (size_t i = 0; i < key.length(); ++i) {
+ UNIT_ASSERT(iter.Advance(key[i]));
+ }
+}
+
+template <typename TChar>
+void TCompactTrieTest::TestSearchIterImpl() {
+ TBufferOutput buffer;
+ {
+ TCompactTrieBuilder<TChar, ui32> builder;
+ TStringBuf data[] = {
TStringBuf("abaab"),
TStringBuf("abcdef"),
TStringBuf("abbbc"),
TStringBuf("bdfaa"),
- };
+ };
for (size_t i = 0; i < Y_ARRAY_SIZE(data); ++i) {
- builder.Add(TConvertKey<TChar>::Convert(data[i]), i + 1);
- }
- builder.Save(buffer);
- }
-
- TCompactTrie<TChar, ui32> trie(buffer.Buffer().Data(), buffer.Buffer().Size());
- ui32 value = 0;
+ builder.Add(TConvertKey<TChar>::Convert(data[i]), i + 1);
+ }
+ builder.Save(buffer);
+ }
+
+ TCompactTrie<TChar, ui32> trie(buffer.Buffer().Data(), buffer.Buffer().Size());
+ ui32 value = 0;
auto iter(MakeSearchIterator(trie));
MoveIter(iter, TConvertKey<TChar>::Convert(TStringBuf("abc")));
- UNIT_ASSERT(!iter.GetValue(&value));
-
+ UNIT_ASSERT(!iter.GetValue(&value));
+
iter = MakeSearchIterator(trie);
MoveIter(iter, TConvertKey<TChar>::Convert(TStringBuf("abbbc")));
- UNIT_ASSERT(iter.GetValue(&value));
- UNIT_ASSERT_EQUAL(value, 3);
-
+ UNIT_ASSERT(iter.GetValue(&value));
+ UNIT_ASSERT_EQUAL(value, 3);
+
iter = MakeSearchIterator(trie);
UNIT_ASSERT(iter.Advance(TConvertKey<TChar>::Convert(TStringBuf("bdfa"))));
- UNIT_ASSERT(!iter.GetValue(&value));
-
+ UNIT_ASSERT(!iter.GetValue(&value));
+
iter = MakeSearchIterator(trie);
UNIT_ASSERT(iter.Advance(TConvertKey<TChar>::Convert(TStringBuf("bdfaa"))));
- UNIT_ASSERT(iter.GetValue(&value));
- UNIT_ASSERT_EQUAL(value, 4);
-
+ UNIT_ASSERT(iter.GetValue(&value));
+ UNIT_ASSERT_EQUAL(value, 4);
+
UNIT_ASSERT(!MakeSearchIterator(trie).Advance(TChar('z')));
UNIT_ASSERT(!MakeSearchIterator(trie).Advance(TConvertKey<TChar>::Convert(TStringBuf("cdf"))));
UNIT_ASSERT(!MakeSearchIterator(trie).Advance(TConvertKey<TChar>::Convert(TStringBuf("abca"))));
-}
-
-void TCompactTrieTest::TestSearchIterChar() {
- TestSearchIterImpl<char>();
-}
-
-void TCompactTrieTest::TestSearchIterWchar() {
- TestSearchIterImpl<wchar16>();
-}
+}
+
+void TCompactTrieTest::TestSearchIterChar() {
+ TestSearchIterImpl<char>();
+}
+
+void TCompactTrieTest::TestSearchIterWchar() {
+ TestSearchIterImpl<wchar16>();
+}
void TCompactTrieTest::TestSearchIterWchar32() {
TestSearchIterImpl<wchar32>();
diff --git a/library/cpp/containers/comptrie/protopacker.h b/library/cpp/containers/comptrie/protopacker.h
index 1e3785d5b7..3e15866dc5 100644
--- a/library/cpp/containers/comptrie/protopacker.h
+++ b/library/cpp/containers/comptrie/protopacker.h
@@ -1,6 +1,6 @@
#pragma once
-#include <util/stream/mem.h>
+#include <util/stream/mem.h>
#include <util/ysaveload.h>
template <class Proto>