From 37de222addabbef336dcaaea5f7c7645a629fc6d Mon Sep 17 00:00:00 2001 From: antonovvk Date: Thu, 10 Feb 2022 16:47:52 +0300 Subject: Restoring authorship annotation for . Commit 2 of 2. --- library/cpp/diff/diff.cpp | 104 +++++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 52 deletions(-) (limited to 'library/cpp/diff/diff.cpp') diff --git a/library/cpp/diff/diff.cpp b/library/cpp/diff/diff.cpp index 90c15bdb618..be57da7f396 100644 --- a/library/cpp/diff/diff.cpp +++ b/library/cpp/diff/diff.cpp @@ -1,27 +1,27 @@ -#include "diff.h" - -#include -#include - +#include "diff.h" + +#include +#include + #include -template -struct TCollectionImpl { +template +struct TCollectionImpl { TVector> Words; TVector Keys; - - inline bool Consume(const T* b, const T* e, const T*) { - if (b < e) { - Words.push_back(TConstArrayRef(b, e)); - Keys.push_back(FnvHash((const char*)b, (e - b) * sizeof(T))); - } - return true; - } - + + inline bool Consume(const T* b, const T* e, const T*) { + if (b < e) { + Words.push_back(TConstArrayRef(b, e)); + Keys.push_back(FnvHash((const char*)b, (e - b) * sizeof(T))); + } + return true; + } + TConstArrayRef Remap(const TConstArrayRef& keys) const { - if (keys.empty()) { - return TConstArrayRef(); - } + if (keys.empty()) { + return TConstArrayRef(); + } auto firstWordPos = std::distance(Keys.data(), keys.begin()); auto lastWordPos = std::distance(Keys.data(), keys.end()) - 1; Y_ASSERT(firstWordPos >= 0); @@ -29,59 +29,59 @@ struct TCollectionImpl { Y_ASSERT(static_cast(lastWordPos) < Words.size()); return TConstArrayRef(Words[firstWordPos].begin(), Words[lastWordPos].end()); - } - - TConstArrayRef GetKeys() const { + } + + TConstArrayRef GetKeys() const { return TConstArrayRef(Keys); - } -}; - -template -struct TCollection { -}; - -template <> -struct TCollection: public TCollectionImpl { + } +}; + +template +struct TCollection { +}; + +template <> +struct TCollection: public TCollectionImpl { TCollection(const TStringBuf& str, const TString& delims) { TSetDelimiter set(delims.data()); - TKeepDelimiters> c(this); - SplitString(str.begin(), str.end(), set, c); - } -}; - -template <> + TKeepDelimiters> c(this); + SplitString(str.begin(), str.end(), set, c); + } +}; + +template <> struct TCollection: public TCollectionImpl { TCollection(const TWtringBuf& str, const TUtf16String& delims) { TSetDelimiter set(delims.data()); TKeepDelimiters> c(this); - SplitString(str.begin(), str.end(), set, c); - } -}; - + SplitString(str.begin(), str.end(), set, c); + } +}; + size_t NDiff::InlineDiff(TVector>& chunks, const TStringBuf& left, const TStringBuf& right, const TString& delims) { - if (delims.empty()) { + if (delims.empty()) { return InlineDiff(chunks, TConstArrayRef(left.data(), left.size()), TConstArrayRef(right.data(), right.size())); - } - TCollection c1(left, delims); - TCollection c2(right, delims); + } + TCollection c1(left, delims); + TCollection c2(right, delims); TVector> diff; const size_t dist = InlineDiff(diff, c1.GetKeys(), c2.GetKeys()); for (const auto& it : diff) { chunks.push_back(TChunk(c1.Remap(it.Left), c2.Remap(it.Right), c1.Remap(it.Common))); - } + } return dist; -} - +} + size_t NDiff::InlineDiff(TVector>& chunks, const TWtringBuf& left, const TWtringBuf& right, const TUtf16String& delims) { - if (delims.empty()) { + if (delims.empty()) { return InlineDiff(chunks, TConstArrayRef(left.data(), left.size()), TConstArrayRef(right.data(), right.size())); - } + } TCollection c1(left, delims); TCollection c2(right, delims); TVector> diff; const size_t dist = InlineDiff(diff, c1.GetKeys(), c2.GetKeys()); for (const auto& it : diff) { chunks.push_back(TChunk(c1.Remap(it.Left), c2.Remap(it.Right), c1.Remap(it.Common))); - } + } return dist; -} +} -- cgit v1.3