diff options
author | grphil <grphil@yandex-team.ru> | 2022-02-10 16:48:06 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:06 +0300 |
commit | 66c9296f0f2f8a474c3b2f5880599f86e35ef592 (patch) | |
tree | 33e0abd07f443703d09fc80c857cb030858e2875 | |
parent | 3305cedaf9e392ab24e4b7dd6072976748ce60bf (diff) | |
download | ydb-66c9296f0f2f8a474c3b2f5880599f86e35ef592.tar.gz |
Restoring authorship annotation for <grphil@yandex-team.ru>. Commit 1 of 2.
-rw-r--r-- | contrib/libs/pire/pire/Makefile.am | 10 | ||||
-rw-r--r-- | contrib/libs/pire/pire/fsm.h | 4 | ||||
-rw-r--r-- | contrib/libs/pire/pire/half_final_fsm.cpp | 674 | ||||
-rw-r--r-- | contrib/libs/pire/pire/half_final_fsm.h | 96 | ||||
-rw-r--r-- | contrib/libs/pire/pire/pire.h | 2 | ||||
-rw-r--r-- | contrib/libs/pire/pire/scanner_io.cpp | 12 | ||||
-rw-r--r-- | contrib/libs/pire/pire/scanners/common.h | 18 | ||||
-rw-r--r-- | contrib/libs/pire/pire/scanners/half_final.h | 502 | ||||
-rw-r--r-- | contrib/libs/pire/pire/scanners/loaded.h | 2 | ||||
-rw-r--r-- | contrib/libs/pire/pire/scanners/multi.h | 24 | ||||
-rw-r--r-- | contrib/libs/pire/pire/scanners/null.cpp | 2 | ||||
-rw-r--r-- | contrib/libs/pire/pire/scanners/simple.h | 34 | ||||
-rw-r--r-- | contrib/libs/pire/pire/scanners/slow.h | 2 | ||||
-rw-r--r-- | library/cpp/regex/pire/ut/ya.make | 8 | ||||
-rw-r--r-- | library/cpp/regex/pire/ya.make | 2 |
15 files changed, 696 insertions, 696 deletions
diff --git a/contrib/libs/pire/pire/Makefile.am b/contrib/libs/pire/pire/Makefile.am index 09ef211704..6ae2f0bf9f 100644 --- a/contrib/libs/pire/pire/Makefile.am +++ b/contrib/libs/pire/pire/Makefile.am @@ -23,8 +23,8 @@ libpire_la_SOURCES = \ glue.cpp \ glue.h \ minimize.h \ - half_final_fsm.cpp \ - half_final_fsm.h \ + half_final_fsm.cpp \ + half_final_fsm.h \ partition.h \ pire.h \ re_lexer.cpp \ @@ -33,7 +33,7 @@ libpire_la_SOURCES = \ scanner_io.cpp \ vbitset.h \ re_parser.ypp \ - scanners/half_final.h \ + scanners/half_final.h \ scanners/loaded.h \ scanners/multi.h \ scanners/slow.h \ @@ -74,7 +74,7 @@ pire_hdr_HEADERS = \ fwd.h \ glue.h \ minimize.h \ - half_final_fsm.h \ + half_final_fsm.h \ partition.h \ pire.h \ re_lexer.h \ @@ -94,7 +94,7 @@ endif pire_scannersdir = $(includedir)/pire/scanners pire_scanners_HEADERS = \ scanners/common.h \ - scanners/half_final.h \ + scanners/half_final.h \ scanners/multi.h \ scanners/slow.h \ scanners/simple.h \ diff --git a/contrib/libs/pire/pire/fsm.h b/contrib/libs/pire/pire/fsm.h index 4dad06ca06..786d9da854 100644 --- a/contrib/libs/pire/pire/fsm.h +++ b/contrib/libs/pire/pire/fsm.h @@ -35,7 +35,7 @@ namespace Pire { namespace Impl { class FsmDetermineTask; class FsmMinimizeTask; - class HalfFinalDetermineTask; + class HalfFinalDetermineTask; } /// A Flying Spaghetti Monster... no, just a Finite State Machine. @@ -246,7 +246,7 @@ namespace Pire { friend class Impl::FsmDetermineTask; friend class Impl::FsmMinimizeTask; - friend class Impl::HalfFinalDetermineTask; + friend class Impl::HalfFinalDetermineTask; }; template<class Scanner> diff --git a/contrib/libs/pire/pire/half_final_fsm.cpp b/contrib/libs/pire/pire/half_final_fsm.cpp index e45d03b9e2..d5946d31d0 100644 --- a/contrib/libs/pire/pire/half_final_fsm.cpp +++ b/contrib/libs/pire/pire/half_final_fsm.cpp @@ -1,337 +1,337 @@ -#include "defs.h" -#include "determine.h" -#include "half_final_fsm.h" - -namespace Pire { - size_t HalfFinalFsm::MaxCountDepth = 10; - - void HalfFinalFsm::MakeScanner() { - fsm.Canonize(); - bool allowHalfFinals = AllowHalfFinals(); - if (!allowHalfFinals) { - MakeHalfFinal(); - return; - } - DisconnectFinals(true); - } - - bool HalfFinalFsm::AllowHalfFinals() { - fsm.Canonize(); - for (size_t state = 0; state < fsm.Size(); ++state) { - if (fsm.IsFinal(state)) { - for (const auto& let : fsm.Letters()) { - bool hasFinalTransition = fsm.Destinations(state, let.first).empty(); - for (const auto& to : fsm.Destinations(state, let.first)) { - if (fsm.IsFinal(to)) { - hasFinalTransition = true; - } - } - if (!hasFinalTransition) { - return false; - } - } - } - } - return true; - } - - void HalfFinalFsm::MakeHalfFinal() { - fsm.Unsparse(); - const auto newFinal = fsm.Size(); - fsm.Resize(newFinal + 1); - for (unsigned letter = 0; letter < MaxChar; ++letter) { - if (letter != Epsilon) { - fsm.Connect(newFinal, newFinal, letter); - } - } - for (size_t state = 0; state < fsm.Size(); ++state) { - bool hasFinalTransitions = false; - for (const auto& to : fsm.Destinations(state, EndMark)) { - if (fsm.IsFinal(to)) { - hasFinalTransitions = true; - break; - } - } - if (hasFinalTransitions) { - Fsm::StatesSet destinations = fsm.Destinations(state, EndMark); - for (const auto& to : destinations) { - fsm.Disconnect(state, to, EndMark); - } - fsm.Connect(state, newFinal, EndMark); - } - } - fsm.ClearFinal(); - fsm.SetFinal(newFinal, true); - fsm.Sparse(); - } - - void HalfFinalFsm::DisconnectFinals(bool allowIntersects) { - fsm.Unsparse(); - for (size_t state = 0; state != fsm.Size(); ++state) { - fsm.SetTag(state, 0); - if (fsm.IsFinal(state)) { - for (unsigned letter = 0; letter < MaxChar; ++letter) { - Fsm::StatesSet destinations = fsm.Destinations(state, letter); - for (const auto& to : destinations) { - fsm.Disconnect(state, to, letter); - } - } - if (!allowIntersects) { - fsm.Connect(state, fsm.Initial()); - } - } - } - if (allowIntersects) { - fsm.PrependAnything(); - } - fsm.Sparse(); - fsm.SetIsDetermined(false); - fsm.Canonize(); - } - - void HalfFinalFsm::MakeNonGreedyCounter(bool allowIntersects /* = true */, bool simplify /* = true */) { - fsm.Canonize(); - fsm.PrependAnything(); - fsm.RemoveDeadEnds(); - fsm.Canonize(); - if (!allowIntersects || simplify) { - DisconnectFinals(allowIntersects); - } - } - - void HalfFinalFsm::MakeGreedyCounter(bool simplify /* = true */) { - fsm.Canonize(); - fsm.RemoveDeadEnds(); - size_t determineFactor = MaxCountDepth; - if (simplify) { - determineFactor = 1; - } - Determine(determineFactor); - if (simplify) { - fsm.Minimize(); - } - fsm.RemoveDeadEnds(); - } - - namespace Impl { - - class HalfFinalDetermineState { - public: - HalfFinalDetermineState(const Fsm& fsm, bool initial = false, size_t lastFinalCount = 0) - : mFsm(fsm) - , ToAdd(0) - , LastFinalCount(lastFinalCount) - { - if (initial) { - FinishBuild(1); - } - } - - HalfFinalDetermineState Next(Char letter, size_t maxCount) const { - HalfFinalDetermineState next(mFsm, false, LastFinalCount); - for (const auto& state : States) { - for (const auto& nextState : mFsm.Destinations(state.State, letter)) { - next.AddState(nextState, state.Count, state.ReachedFinal); - } - } - next.FinishBuild(maxCount, States.back().Count); - if (letter == EndMark) { - next.ToAdd += next.LastFinalCount; - next.LastFinalCount = 0; - next.States.clear(); - next.AddState(mFsm.Initial(), 0, false, true); - return next; - } - return next; - } - - void CopyData(Fsm& newFsm, size_t index) const { - if (ToAdd) { - newFsm.SetFinal(index, true); - newFsm.SetTag(index, ToAdd); - } - } - - bool operator<(const HalfFinalDetermineState& otherState) const { - if (ToAdd != otherState.ToAdd) { - return ToAdd < otherState.ToAdd; - } - if (LastFinalCount != otherState.LastFinalCount) { - return LastFinalCount < otherState.LastFinalCount; - } - return States < otherState.States; - } - - struct StateHolder { - size_t State; - size_t Count; - bool ReachedFinal; - - bool operator<(const StateHolder& other) const { - if (State != other.State) { - return State < other.State; - } - if (Count != other.Count) { - return Count < other.Count; - } - return ReachedFinal < other.ReachedFinal; - } - }; - - private: - const Fsm& mFsm; - TVector<StateHolder> States; - size_t ToAdd; - size_t LastFinalCount; - - void AddState(size_t state, size_t count, bool reachedFinal, bool force = false) { - size_t newLastFinalCount = LastFinalCount; - if (mFsm.IsFinal(state) && !reachedFinal) { - ++count; - reachedFinal = true; - newLastFinalCount = count; - } - for (const auto& addedState : States) { - if (addedState.State == state) { - return; - } - } - if (States.empty() || !mFsm.IsFinal(States.back().State) || force) { - States.push_back({state, count, reachedFinal}); - LastFinalCount = newLastFinalCount; - } - } - - void FinishBuild(size_t maxCount, size_t lastCount = 0) { - if (!States.empty() && mFsm.IsFinal(States.back().State)) { - lastCount = States.back().Count; - } - AddState(mFsm.Initial(), lastCount, false, true); - LastFinalCount = std::min(LastFinalCount, maxCount); - size_t minCount = States[0].Count; - for (auto& state : States) { - if (state.Count > maxCount) { - state.Count = maxCount; - } - minCount = std::min(state.Count, minCount); - } - ToAdd = minCount; - for (auto& state : States) { - state.Count -= minCount; - } - LastFinalCount -= minCount; - } - }; - - class HalfFinalDetermineTask { - public: - typedef HalfFinalDetermineState State; - typedef Fsm::LettersTbl LettersTbl; - typedef TMap<State, size_t> InvStates; - - HalfFinalDetermineTask(const Fsm& fsm, size_t maxCount) - : mFsm(fsm) - , MaxCount(maxCount) - { - size_t oldSize = mFsm.Size(); - mFsm.Import(fsm); - mFsm.Unsparse(); - for (size_t state = 0; state < mFsm.Size(); ++state) { - for (Char letter = 0; letter < MaxChar; ++letter) { - Fsm::StatesSet destinations = mFsm.Destinations(state, letter); - for (const auto destination : destinations) { - size_t newDestination = destination % oldSize; - if (letter == EndMark) { - newDestination += oldSize; - } - if (destination != newDestination) { - mFsm.Disconnect(state, destination, letter); - mFsm.Connect(state, newDestination, letter); - } - } - } - if (mFsm.Destinations(state, EndMark).size() == 0) { - mFsm.Connect(state, oldSize + mFsm.Initial(), EndMark); - } - } - mFsm.Sparse(); - } - - const LettersTbl& Letters() const { return mFsm.Letters(); } - - State Initial() const { - return State(mFsm, true); - } - - State Next(const State& state, Char letter) const { - return state.Next(letter, MaxCount); - } - - bool IsRequired(const State& /*state*/) const { return true; } - - void AcceptStates(const TVector<State>& newStates) { - mNewFsm.Resize(newStates.size()); - mNewFsm.SetInitial(0); - mNewFsm.SetIsDetermined(true); - mNewFsm.letters = Letters(); - mNewFsm.ClearFinal(); - for (size_t i = 0; i < newStates.size(); i++) { - newStates[i].CopyData(mNewFsm, i); - } - } - - void Connect(size_t from, size_t to, Char letter) { - Y_ASSERT(mNewFsm.Destinations(from, letter).size() == 0); - mNewFsm.Connect(from, to, letter); - } - - typedef bool Result; - - Result Success() { return true; } - - Result Failure() { return false; } - - Fsm& Output() { return mNewFsm; } - - void SetMaxCount(size_t maxCount) { - MaxCount = maxCount; - } - - private: - Fsm mFsm; - size_t MaxCount; - Fsm mNewFsm; - }; - } - - void HalfFinalFsm::Determine(size_t depth) { - static const unsigned MaxSize = 200000; - - Impl::HalfFinalDetermineTask task(fsm, depth); - if (!Pire::Impl::Determine(task, MaxSize)) { - task.SetMaxCount(1); - Pire::Impl::Determine(task, MaxSize); - } - - task.Output().Swap(fsm); - } - - size_t HalfFinalFsm::GetCount(size_t state) const { - if (fsm.IsFinal(state)) { - if (fsm.Tag(state)) { - return fsm.Tag(state); - } else { - return 1; - } - } - return 0; - } - - size_t HalfFinalFsm::GetTotalCount() const { - size_t count = 0; - for (size_t state = 0; state < fsm.Size(); ++state) { - count += GetCount(state); - } - return count; - } -} +#include "defs.h" +#include "determine.h" +#include "half_final_fsm.h" + +namespace Pire { + size_t HalfFinalFsm::MaxCountDepth = 10; + + void HalfFinalFsm::MakeScanner() { + fsm.Canonize(); + bool allowHalfFinals = AllowHalfFinals(); + if (!allowHalfFinals) { + MakeHalfFinal(); + return; + } + DisconnectFinals(true); + } + + bool HalfFinalFsm::AllowHalfFinals() { + fsm.Canonize(); + for (size_t state = 0; state < fsm.Size(); ++state) { + if (fsm.IsFinal(state)) { + for (const auto& let : fsm.Letters()) { + bool hasFinalTransition = fsm.Destinations(state, let.first).empty(); + for (const auto& to : fsm.Destinations(state, let.first)) { + if (fsm.IsFinal(to)) { + hasFinalTransition = true; + } + } + if (!hasFinalTransition) { + return false; + } + } + } + } + return true; + } + + void HalfFinalFsm::MakeHalfFinal() { + fsm.Unsparse(); + const auto newFinal = fsm.Size(); + fsm.Resize(newFinal + 1); + for (unsigned letter = 0; letter < MaxChar; ++letter) { + if (letter != Epsilon) { + fsm.Connect(newFinal, newFinal, letter); + } + } + for (size_t state = 0; state < fsm.Size(); ++state) { + bool hasFinalTransitions = false; + for (const auto& to : fsm.Destinations(state, EndMark)) { + if (fsm.IsFinal(to)) { + hasFinalTransitions = true; + break; + } + } + if (hasFinalTransitions) { + Fsm::StatesSet destinations = fsm.Destinations(state, EndMark); + for (const auto& to : destinations) { + fsm.Disconnect(state, to, EndMark); + } + fsm.Connect(state, newFinal, EndMark); + } + } + fsm.ClearFinal(); + fsm.SetFinal(newFinal, true); + fsm.Sparse(); + } + + void HalfFinalFsm::DisconnectFinals(bool allowIntersects) { + fsm.Unsparse(); + for (size_t state = 0; state != fsm.Size(); ++state) { + fsm.SetTag(state, 0); + if (fsm.IsFinal(state)) { + for (unsigned letter = 0; letter < MaxChar; ++letter) { + Fsm::StatesSet destinations = fsm.Destinations(state, letter); + for (const auto& to : destinations) { + fsm.Disconnect(state, to, letter); + } + } + if (!allowIntersects) { + fsm.Connect(state, fsm.Initial()); + } + } + } + if (allowIntersects) { + fsm.PrependAnything(); + } + fsm.Sparse(); + fsm.SetIsDetermined(false); + fsm.Canonize(); + } + + void HalfFinalFsm::MakeNonGreedyCounter(bool allowIntersects /* = true */, bool simplify /* = true */) { + fsm.Canonize(); + fsm.PrependAnything(); + fsm.RemoveDeadEnds(); + fsm.Canonize(); + if (!allowIntersects || simplify) { + DisconnectFinals(allowIntersects); + } + } + + void HalfFinalFsm::MakeGreedyCounter(bool simplify /* = true */) { + fsm.Canonize(); + fsm.RemoveDeadEnds(); + size_t determineFactor = MaxCountDepth; + if (simplify) { + determineFactor = 1; + } + Determine(determineFactor); + if (simplify) { + fsm.Minimize(); + } + fsm.RemoveDeadEnds(); + } + + namespace Impl { + + class HalfFinalDetermineState { + public: + HalfFinalDetermineState(const Fsm& fsm, bool initial = false, size_t lastFinalCount = 0) + : mFsm(fsm) + , ToAdd(0) + , LastFinalCount(lastFinalCount) + { + if (initial) { + FinishBuild(1); + } + } + + HalfFinalDetermineState Next(Char letter, size_t maxCount) const { + HalfFinalDetermineState next(mFsm, false, LastFinalCount); + for (const auto& state : States) { + for (const auto& nextState : mFsm.Destinations(state.State, letter)) { + next.AddState(nextState, state.Count, state.ReachedFinal); + } + } + next.FinishBuild(maxCount, States.back().Count); + if (letter == EndMark) { + next.ToAdd += next.LastFinalCount; + next.LastFinalCount = 0; + next.States.clear(); + next.AddState(mFsm.Initial(), 0, false, true); + return next; + } + return next; + } + + void CopyData(Fsm& newFsm, size_t index) const { + if (ToAdd) { + newFsm.SetFinal(index, true); + newFsm.SetTag(index, ToAdd); + } + } + + bool operator<(const HalfFinalDetermineState& otherState) const { + if (ToAdd != otherState.ToAdd) { + return ToAdd < otherState.ToAdd; + } + if (LastFinalCount != otherState.LastFinalCount) { + return LastFinalCount < otherState.LastFinalCount; + } + return States < otherState.States; + } + + struct StateHolder { + size_t State; + size_t Count; + bool ReachedFinal; + + bool operator<(const StateHolder& other) const { + if (State != other.State) { + return State < other.State; + } + if (Count != other.Count) { + return Count < other.Count; + } + return ReachedFinal < other.ReachedFinal; + } + }; + + private: + const Fsm& mFsm; + TVector<StateHolder> States; + size_t ToAdd; + size_t LastFinalCount; + + void AddState(size_t state, size_t count, bool reachedFinal, bool force = false) { + size_t newLastFinalCount = LastFinalCount; + if (mFsm.IsFinal(state) && !reachedFinal) { + ++count; + reachedFinal = true; + newLastFinalCount = count; + } + for (const auto& addedState : States) { + if (addedState.State == state) { + return; + } + } + if (States.empty() || !mFsm.IsFinal(States.back().State) || force) { + States.push_back({state, count, reachedFinal}); + LastFinalCount = newLastFinalCount; + } + } + + void FinishBuild(size_t maxCount, size_t lastCount = 0) { + if (!States.empty() && mFsm.IsFinal(States.back().State)) { + lastCount = States.back().Count; + } + AddState(mFsm.Initial(), lastCount, false, true); + LastFinalCount = std::min(LastFinalCount, maxCount); + size_t minCount = States[0].Count; + for (auto& state : States) { + if (state.Count > maxCount) { + state.Count = maxCount; + } + minCount = std::min(state.Count, minCount); + } + ToAdd = minCount; + for (auto& state : States) { + state.Count -= minCount; + } + LastFinalCount -= minCount; + } + }; + + class HalfFinalDetermineTask { + public: + typedef HalfFinalDetermineState State; + typedef Fsm::LettersTbl LettersTbl; + typedef TMap<State, size_t> InvStates; + + HalfFinalDetermineTask(const Fsm& fsm, size_t maxCount) + : mFsm(fsm) + , MaxCount(maxCount) + { + size_t oldSize = mFsm.Size(); + mFsm.Import(fsm); + mFsm.Unsparse(); + for (size_t state = 0; state < mFsm.Size(); ++state) { + for (Char letter = 0; letter < MaxChar; ++letter) { + Fsm::StatesSet destinations = mFsm.Destinations(state, letter); + for (const auto destination : destinations) { + size_t newDestination = destination % oldSize; + if (letter == EndMark) { + newDestination += oldSize; + } + if (destination != newDestination) { + mFsm.Disconnect(state, destination, letter); + mFsm.Connect(state, newDestination, letter); + } + } + } + if (mFsm.Destinations(state, EndMark).size() == 0) { + mFsm.Connect(state, oldSize + mFsm.Initial(), EndMark); + } + } + mFsm.Sparse(); + } + + const LettersTbl& Letters() const { return mFsm.Letters(); } + + State Initial() const { + return State(mFsm, true); + } + + State Next(const State& state, Char letter) const { + return state.Next(letter, MaxCount); + } + + bool IsRequired(const State& /*state*/) const { return true; } + + void AcceptStates(const TVector<State>& newStates) { + mNewFsm.Resize(newStates.size()); + mNewFsm.SetInitial(0); + mNewFsm.SetIsDetermined(true); + mNewFsm.letters = Letters(); + mNewFsm.ClearFinal(); + for (size_t i = 0; i < newStates.size(); i++) { + newStates[i].CopyData(mNewFsm, i); + } + } + + void Connect(size_t from, size_t to, Char letter) { + Y_ASSERT(mNewFsm.Destinations(from, letter).size() == 0); + mNewFsm.Connect(from, to, letter); + } + + typedef bool Result; + + Result Success() { return true; } + + Result Failure() { return false; } + + Fsm& Output() { return mNewFsm; } + + void SetMaxCount(size_t maxCount) { + MaxCount = maxCount; + } + + private: + Fsm mFsm; + size_t MaxCount; + Fsm mNewFsm; + }; + } + + void HalfFinalFsm::Determine(size_t depth) { + static const unsigned MaxSize = 200000; + + Impl::HalfFinalDetermineTask task(fsm, depth); + if (!Pire::Impl::Determine(task, MaxSize)) { + task.SetMaxCount(1); + Pire::Impl::Determine(task, MaxSize); + } + + task.Output().Swap(fsm); + } + + size_t HalfFinalFsm::GetCount(size_t state) const { + if (fsm.IsFinal(state)) { + if (fsm.Tag(state)) { + return fsm.Tag(state); + } else { + return 1; + } + } + return 0; + } + + size_t HalfFinalFsm::GetTotalCount() const { + size_t count = 0; + for (size_t state = 0; state < fsm.Size(); ++state) { + count += GetCount(state); + } + return count; + } +} diff --git a/contrib/libs/pire/pire/half_final_fsm.h b/contrib/libs/pire/pire/half_final_fsm.h index 83828f8bb3..42e034f7db 100644 --- a/contrib/libs/pire/pire/half_final_fsm.h +++ b/contrib/libs/pire/pire/half_final_fsm.h @@ -1,48 +1,48 @@ -#include "fsm.h" -#include "defs.h" - -namespace Pire { - class HalfFinalFsm { - public: - HalfFinalFsm(const Fsm& sourceFsm) : fsm(sourceFsm) {} - - void MakeScanner(); - - /// Non greedy counter without allowed intersects works correctly on all regexps - /// Non simplified non greedy counter with allowed intersects counts number of positions in string, - /// on which ends at least one substring that matches regexp - /// Simplified non greedy counter with allowed intersects does not always work correctly, - /// but has fewer number of states and more regexps can be glued into single scanner - void MakeNonGreedyCounter(bool allowIntersects = true, bool simplify = true); - - // Simplified counter does not work correctly on all regexps, but has less number of states - // and allows to glue larger number of scanners into one within the same size limit - void MakeGreedyCounter(bool simplify = true); - - const Fsm& GetFsm() const { return fsm; } - - template<class Scanner> - Scanner Compile() const; - - size_t GetCount(size_t state) const; - - size_t GetTotalCount() const; - - static size_t MaxCountDepth; - private: - Fsm fsm; - - bool AllowHalfFinals(); - - void MakeHalfFinal(); - - void DisconnectFinals(bool allowIntersects); - - void Determine(size_t depth = MaxCountDepth); - }; - - template<class Scanner> - Scanner HalfFinalFsm::Compile() const { - auto scanner = Scanner(*this); - } -} +#include "fsm.h" +#include "defs.h" + +namespace Pire { + class HalfFinalFsm { + public: + HalfFinalFsm(const Fsm& sourceFsm) : fsm(sourceFsm) {} + + void MakeScanner(); + + /// Non greedy counter without allowed intersects works correctly on all regexps + /// Non simplified non greedy counter with allowed intersects counts number of positions in string, + /// on which ends at least one substring that matches regexp + /// Simplified non greedy counter with allowed intersects does not always work correctly, + /// but has fewer number of states and more regexps can be glued into single scanner + void MakeNonGreedyCounter(bool allowIntersects = true, bool simplify = true); + + // Simplified counter does not work correctly on all regexps, but has less number of states + // and allows to glue larger number of scanners into one within the same size limit + void MakeGreedyCounter(bool simplify = true); + + const Fsm& GetFsm() const { return fsm; } + + template<class Scanner> + Scanner Compile() const; + + size_t GetCount(size_t state) const; + + size_t GetTotalCount() const; + + static size_t MaxCountDepth; + private: + Fsm fsm; + + bool AllowHalfFinals(); + + void MakeHalfFinal(); + + void DisconnectFinals(bool allowIntersects); + + void Determine(size_t depth = MaxCountDepth); + }; + + template<class Scanner> + Scanner HalfFinalFsm::Compile() const { + auto scanner = Scanner(*this); + } +} diff --git a/contrib/libs/pire/pire/pire.h b/contrib/libs/pire/pire/pire.h index 12eb84ccb6..75c46aabba 100644 --- a/contrib/libs/pire/pire/pire.h +++ b/contrib/libs/pire/pire/pire.h @@ -25,7 +25,7 @@ #define PIRE_PIRE_H #include <contrib/libs/pire/pire/scanners/multi.h> -#include <contrib/libs/pire/pire/scanners/half_final.h> +#include <contrib/libs/pire/pire/scanners/half_final.h> #include <contrib/libs/pire/pire/scanners/simple.h> #include <contrib/libs/pire/pire/scanners/slow.h> #include <contrib/libs/pire/pire/scanners/pair.h> diff --git a/contrib/libs/pire/pire/scanner_io.cpp b/contrib/libs/pire/pire/scanner_io.cpp index 3956e3c6ed..97a88744c1 100644 --- a/contrib/libs/pire/pire/scanner_io.cpp +++ b/contrib/libs/pire/pire/scanner_io.cpp @@ -23,7 +23,7 @@ #include <contrib/libs/pire/pire/stub/stl.h> #include <contrib/libs/pire/pire/stub/saveload.h> -#include <contrib/libs/pire/pire/scanners/common.h> +#include <contrib/libs/pire/pire/scanners/common.h> #include <contrib/libs/pire/pire/scanners/slow.h> #include <contrib/libs/pire/pire/scanners/simple.h> #include <contrib/libs/pire/pire/scanners/loaded.h> @@ -34,7 +34,7 @@ namespace Pire { void SimpleScanner::Save(yostream* s) const { - SavePodType(s, Header(ScannerIOTypes::SimpleScanner, sizeof(m))); + SavePodType(s, Header(ScannerIOTypes::SimpleScanner, sizeof(m))); Impl::AlignSave(s, sizeof(Header)); Locals mc = m; mc.initial -= reinterpret_cast<size_t>(m_transitions); @@ -51,7 +51,7 @@ void SimpleScanner::Save(yostream* s) const void SimpleScanner::Load(yistream* s) { SimpleScanner sc; - Impl::ValidateHeader(s, ScannerIOTypes::SimpleScanner, sizeof(sc.m)); + Impl::ValidateHeader(s, ScannerIOTypes::SimpleScanner, sizeof(sc.m)); LoadPodType(s, sc.m); Impl::AlignLoad(s, sizeof(sc.m)); bool empty; @@ -70,7 +70,7 @@ void SimpleScanner::Load(yistream* s) void SlowScanner::Save(yostream* s) const { - SavePodType(s, Header(ScannerIOTypes::SlowScanner, sizeof(m))); + SavePodType(s, Header(ScannerIOTypes::SlowScanner, sizeof(m))); Impl::AlignSave(s, sizeof(Header)); SavePodType(s, m); Impl::AlignSave(s, sizeof(m)); @@ -112,7 +112,7 @@ void SlowScanner::Save(yostream* s) const void SlowScanner::Load(yistream* s) { SlowScanner sc; - Impl::ValidateHeader(s, ScannerIOTypes::SlowScanner, sizeof(sc.m)); + Impl::ValidateHeader(s, ScannerIOTypes::SlowScanner, sizeof(sc.m)); LoadPodType(s, sc.m); Impl::AlignLoad(s, sizeof(sc.m)); bool empty; @@ -195,7 +195,7 @@ void LoadedScanner::Load(yistream* s) { void LoadedScanner::Load(yistream* s, ui32* type) { LoadedScanner sc; - Header header = Impl::ValidateHeader(s, ScannerIOTypes::LoadedScanner, sizeof(sc.m)); + Header header = Impl::ValidateHeader(s, ScannerIOTypes::LoadedScanner, sizeof(sc.m)); if (type) { *type = header.Type; } diff --git a/contrib/libs/pire/pire/scanners/common.h b/contrib/libs/pire/pire/scanners/common.h index de5ea0af7b..8f6e05420c 100644 --- a/contrib/libs/pire/pire/scanners/common.h +++ b/contrib/libs/pire/pire/scanners/common.h @@ -30,16 +30,16 @@ #include <contrib/libs/pire/pire/platform.h> namespace Pire { - namespace ScannerIOTypes { - enum { - NoScanner = 0, - Scanner = 1, - SimpleScanner = 2, - SlowScanner = 3, + namespace ScannerIOTypes { + enum { + NoScanner = 0, + Scanner = 1, + SimpleScanner = 2, + SlowScanner = 3, LoadedScanner = 4, NoGlueLimitCountingScanner = 5, - }; - } + }; + } struct Header { ui32 Magic; @@ -111,7 +111,7 @@ namespace Pire { inline Header ValidateHeader(yistream* s, ui32 type, size_t hdrsize) { - Header hdr(ScannerIOTypes::NoScanner, 0); + Header hdr(ScannerIOTypes::NoScanner, 0); LoadPodType(s, hdr); AlignLoad(s, sizeof(hdr)); hdr.Validate(type, hdrsize); diff --git a/contrib/libs/pire/pire/scanners/half_final.h b/contrib/libs/pire/pire/scanners/half_final.h index 071c3414a2..31abc20907 100644 --- a/contrib/libs/pire/pire/scanners/half_final.h +++ b/contrib/libs/pire/pire/scanners/half_final.h @@ -1,255 +1,255 @@ -#ifndef PIRE_SCANNERS_HALF_FINAL_H -#define PIRE_SCANNERS_HALF_FINAL_H - -#include <string.h> -#include "common.h" -#include "multi.h" -#include <contrib/libs/pire/pire/fsm.h> -#include <contrib/libs/pire/pire//half_final_fsm.h> -#include <contrib/libs/pire/pire//stub/stl.h> - -namespace Pire { - -namespace Impl { - - -/* - * A half final scanner -- the deterministic scanner having half-terminal states, - * so it matches regexps in all terminal transitional states. - * - * The scanner can also count the number of substrings, that match each regexp. These substrings may intersect. - * - * Comparing it with scanner, it runs slower, but allows to glue significantly - * larger number of scanners into one within the same size limits. - * - * The class is subclass of Scanner, having the same methods, but different state type. - * - * There are no restrictions for regexps and fsm's, for which it is built, but it - * does not work properly if the matching text does not end with EndMark. - * - * For count to work correctly, the fsm should not be determined. - */ -template<typename Relocation, typename Shortcutting> -class HalfFinalScanner : public Scanner<Relocation, Shortcutting> { -public: - typedef typename Impl::Scanner<Relocation, Shortcutting> Scanner; - - HalfFinalScanner() : Scanner() {} - - explicit HalfFinalScanner(Fsm fsm_, size_t distance = 0) { - if (distance) { - fsm_ = CreateApproxFsm(fsm_, distance); - } - HalfFinalFsm fsm(fsm_); - fsm.MakeScanner(); - Scanner::Init(fsm.GetFsm().Size(), fsm.GetFsm().Letters(), fsm.GetFsm().Finals().size(), fsm.GetFsm().Initial(), 1); - BuildScanner(fsm.GetFsm(), *this); - } - - explicit HalfFinalScanner(const HalfFinalFsm& fsm) { - Scanner::Init(fsm.GetFsm().Size(), fsm.GetFsm().Letters(), fsm.GetTotalCount(), fsm.GetFsm().Initial(), 1); - BuildScanner(fsm.GetFsm(), *this); - BuildFinals(fsm); - } - - typedef typename Scanner::ScannerRowHeader ScannerRowHeader; - typedef typename Scanner::Action Action; - - class State { - public: - typedef TVector<size_t>::const_iterator IdsIterator; - - State() : ScannerState(0) {} - - State(const typename Scanner::State& otherState) : ScannerState(otherState) {} - - void GetMatchedRegexpsIds() { - MatchedRegexpsIds.clear(); - for (size_t i = 0; i < MatchedRegexps.size(); i++) { - if (MatchedRegexps[i]) { - MatchedRegexpsIds.push_back(i); - } - } - } - - IdsIterator IdsBegin() const { - return MatchedRegexpsIds.cbegin(); - } - - IdsIterator IdsEnd() const { - return MatchedRegexpsIds.cend(); - } - - bool operator==(const State& other) const { - return ScannerState == other.ScannerState && MatchedRegexps == other.MatchedRegexps; - } - - bool operator!=(const State& other) const { - return ScannerState != other.ScannerState || MatchedRegexps != other.MatchedRegexps; - } - - size_t Result(size_t regexp_id) const { - return MatchedRegexps[regexp_id]; - } - - void Save(yostream* s) const { - SavePodType(s, Pire::Header(5, sizeof(size_t))); - Impl::AlignSave(s, sizeof(Pire::Header)); - auto stateSizePair = ymake_pair(ScannerState, MatchedRegexps.size()); - SavePodType(s, stateSizePair); - Impl::AlignSave(s, sizeof(ypair<size_t, size_t>)); - Y_ASSERT(0); - } - - void Load(yistream* s) { - Impl::ValidateHeader(s, 5, sizeof(size_t)); - ypair<size_t, size_t> stateSizePair; - LoadPodType(s, stateSizePair); - Impl::AlignLoad(s, sizeof(ypair<size_t, size_t>)); - ScannerState = stateSizePair.first; - MatchedRegexps.clear(); - MatchedRegexps.resize(stateSizePair.second); - } - - private: - TVector<size_t> MatchedRegexpsIds; - typename Scanner::State ScannerState; - TVector<size_t> MatchedRegexps; - - friend class HalfFinalScanner<Relocation, Shortcutting>; - }; - - - /// Checks whether specified state is in any of the final sets - bool Final(const State& state) const { return Scanner::Final(state.ScannerState); } - - /// Checks whether specified state is 'dead' (i.e. scanner will never - /// reach any final state from current one) - bool Dead(const State& state) const { return Scanner::Dead(state.ScannerState); } - - typedef ypair<typename State::IdsIterator, typename State::IdsIterator> AcceptedRegexpsType; - - AcceptedRegexpsType AcceptedRegexps(State& state) const { - state.GetMatchedRegexpsIds(); - return ymake_pair(state.IdsBegin(), state.IdsEnd()); - } - - /// Returns an initial state for this scanner - void Initialize(State& state) const { - state.ScannerState = Scanner::m.initial; - state.MatchedRegexps.clear(); - state.MatchedRegexps.resize(Scanner::m.regexpsCount); - TakeAction(state, 0); - } - - Action NextTranslated(State& state, Char letter) const { - return Scanner::NextTranslated(state.ScannerState, letter); - } - - /// Handles one character - Action Next(State& state, Char c) const { - return Scanner::NextTranslated(state.ScannerState, Scanner::Translate(c)); - } - - void TakeAction(State& state, Action) const { - if (Final(state)) { - size_t idx = StateIndex(state); - const size_t *it = Scanner::m_final + Scanner::m_finalIndex[idx]; - while (*it != Scanner::End) { - state.MatchedRegexps[*it]++; - ++it; - } - } - } - - HalfFinalScanner(const HalfFinalScanner& s) : Scanner(s) {} - - HalfFinalScanner(const Scanner& s) : Scanner(s) {} - - HalfFinalScanner(HalfFinalScanner&& s) : Scanner(s) {} - - HalfFinalScanner(Scanner&& s) : Scanner(s) {} - - template<class AnotherRelocation> - HalfFinalScanner(const HalfFinalScanner<AnotherRelocation, Shortcutting>& s) - : Scanner(s) {} - - template<class AnotherRelocation> - HalfFinalScanner(const Impl::Scanner<AnotherRelocation, Shortcutting>& s) : Scanner(s) {} - - void Swap(HalfFinalScanner& s) { - Scanner::Swap(s); - } - - HalfFinalScanner& operator=(const HalfFinalScanner& s) { - HalfFinalScanner(s).Swap(*this); - return *this; - } - - size_t StateIndex(const State& s) const { - return Scanner::StateIndex(s.ScannerState); - } - - /** - * Agglutinates two scanners together, producing a larger scanner. - * Checking a string against that scanner effectively checks them against both agglutinated regexps - * (detailed information about matched regexps can be obtained with AcceptedRegexps()). - * - * Returns default-constructed scanner in case of failure - * (consult Scanner::Empty() to find out whether the operation was successful). - */ - static HalfFinalScanner Glue(const HalfFinalScanner& a, const HalfFinalScanner& b, size_t maxSize = 0) { - return Scanner::Glue(a, b, maxSize); - } - - ScannerRowHeader& Header(const State& s) { return Scanner::Header(s.ScannerState); } - - const ScannerRowHeader& Header(const State& s) const { return Scanner::Header(s.ScannerState); } - -private: - void BuildFinals(const HalfFinalFsm& fsm) { - Y_ASSERT(Scanner::m_buffer); - Y_ASSERT(fsm.GetFsm().Size() == Scanner::Size()); +#ifndef PIRE_SCANNERS_HALF_FINAL_H +#define PIRE_SCANNERS_HALF_FINAL_H + +#include <string.h> +#include "common.h" +#include "multi.h" +#include <contrib/libs/pire/pire/fsm.h> +#include <contrib/libs/pire/pire//half_final_fsm.h> +#include <contrib/libs/pire/pire//stub/stl.h> + +namespace Pire { + +namespace Impl { + + +/* + * A half final scanner -- the deterministic scanner having half-terminal states, + * so it matches regexps in all terminal transitional states. + * + * The scanner can also count the number of substrings, that match each regexp. These substrings may intersect. + * + * Comparing it with scanner, it runs slower, but allows to glue significantly + * larger number of scanners into one within the same size limits. + * + * The class is subclass of Scanner, having the same methods, but different state type. + * + * There are no restrictions for regexps and fsm's, for which it is built, but it + * does not work properly if the matching text does not end with EndMark. + * + * For count to work correctly, the fsm should not be determined. + */ +template<typename Relocation, typename Shortcutting> +class HalfFinalScanner : public Scanner<Relocation, Shortcutting> { +public: + typedef typename Impl::Scanner<Relocation, Shortcutting> Scanner; + + HalfFinalScanner() : Scanner() {} + + explicit HalfFinalScanner(Fsm fsm_, size_t distance = 0) { + if (distance) { + fsm_ = CreateApproxFsm(fsm_, distance); + } + HalfFinalFsm fsm(fsm_); + fsm.MakeScanner(); + Scanner::Init(fsm.GetFsm().Size(), fsm.GetFsm().Letters(), fsm.GetFsm().Finals().size(), fsm.GetFsm().Initial(), 1); + BuildScanner(fsm.GetFsm(), *this); + } + + explicit HalfFinalScanner(const HalfFinalFsm& fsm) { + Scanner::Init(fsm.GetFsm().Size(), fsm.GetFsm().Letters(), fsm.GetTotalCount(), fsm.GetFsm().Initial(), 1); + BuildScanner(fsm.GetFsm(), *this); + BuildFinals(fsm); + } + + typedef typename Scanner::ScannerRowHeader ScannerRowHeader; + typedef typename Scanner::Action Action; + + class State { + public: + typedef TVector<size_t>::const_iterator IdsIterator; + + State() : ScannerState(0) {} + + State(const typename Scanner::State& otherState) : ScannerState(otherState) {} + + void GetMatchedRegexpsIds() { + MatchedRegexpsIds.clear(); + for (size_t i = 0; i < MatchedRegexps.size(); i++) { + if (MatchedRegexps[i]) { + MatchedRegexpsIds.push_back(i); + } + } + } + + IdsIterator IdsBegin() const { + return MatchedRegexpsIds.cbegin(); + } + + IdsIterator IdsEnd() const { + return MatchedRegexpsIds.cend(); + } + + bool operator==(const State& other) const { + return ScannerState == other.ScannerState && MatchedRegexps == other.MatchedRegexps; + } + + bool operator!=(const State& other) const { + return ScannerState != other.ScannerState || MatchedRegexps != other.MatchedRegexps; + } + + size_t Result(size_t regexp_id) const { + return MatchedRegexps[regexp_id]; + } + + void Save(yostream* s) const { + SavePodType(s, Pire::Header(5, sizeof(size_t))); + Impl::AlignSave(s, sizeof(Pire::Header)); + auto stateSizePair = ymake_pair(ScannerState, MatchedRegexps.size()); + SavePodType(s, stateSizePair); + Impl::AlignSave(s, sizeof(ypair<size_t, size_t>)); + Y_ASSERT(0); + } + + void Load(yistream* s) { + Impl::ValidateHeader(s, 5, sizeof(size_t)); + ypair<size_t, size_t> stateSizePair; + LoadPodType(s, stateSizePair); + Impl::AlignLoad(s, sizeof(ypair<size_t, size_t>)); + ScannerState = stateSizePair.first; + MatchedRegexps.clear(); + MatchedRegexps.resize(stateSizePair.second); + } + + private: + TVector<size_t> MatchedRegexpsIds; + typename Scanner::State ScannerState; + TVector<size_t> MatchedRegexps; + + friend class HalfFinalScanner<Relocation, Shortcutting>; + }; + + + /// Checks whether specified state is in any of the final sets + bool Final(const State& state) const { return Scanner::Final(state.ScannerState); } + + /// Checks whether specified state is 'dead' (i.e. scanner will never + /// reach any final state from current one) + bool Dead(const State& state) const { return Scanner::Dead(state.ScannerState); } + + typedef ypair<typename State::IdsIterator, typename State::IdsIterator> AcceptedRegexpsType; + + AcceptedRegexpsType AcceptedRegexps(State& state) const { + state.GetMatchedRegexpsIds(); + return ymake_pair(state.IdsBegin(), state.IdsEnd()); + } + + /// Returns an initial state for this scanner + void Initialize(State& state) const { + state.ScannerState = Scanner::m.initial; + state.MatchedRegexps.clear(); + state.MatchedRegexps.resize(Scanner::m.regexpsCount); + TakeAction(state, 0); + } + + Action NextTranslated(State& state, Char letter) const { + return Scanner::NextTranslated(state.ScannerState, letter); + } + + /// Handles one character + Action Next(State& state, Char c) const { + return Scanner::NextTranslated(state.ScannerState, Scanner::Translate(c)); + } + + void TakeAction(State& state, Action) const { + if (Final(state)) { + size_t idx = StateIndex(state); + const size_t *it = Scanner::m_final + Scanner::m_finalIndex[idx]; + while (*it != Scanner::End) { + state.MatchedRegexps[*it]++; + ++it; + } + } + } + + HalfFinalScanner(const HalfFinalScanner& s) : Scanner(s) {} + + HalfFinalScanner(const Scanner& s) : Scanner(s) {} + + HalfFinalScanner(HalfFinalScanner&& s) : Scanner(s) {} + + HalfFinalScanner(Scanner&& s) : Scanner(s) {} + + template<class AnotherRelocation> + HalfFinalScanner(const HalfFinalScanner<AnotherRelocation, Shortcutting>& s) + : Scanner(s) {} + + template<class AnotherRelocation> + HalfFinalScanner(const Impl::Scanner<AnotherRelocation, Shortcutting>& s) : Scanner(s) {} + + void Swap(HalfFinalScanner& s) { + Scanner::Swap(s); + } + + HalfFinalScanner& operator=(const HalfFinalScanner& s) { + HalfFinalScanner(s).Swap(*this); + return *this; + } + + size_t StateIndex(const State& s) const { + return Scanner::StateIndex(s.ScannerState); + } + + /** + * Agglutinates two scanners together, producing a larger scanner. + * Checking a string against that scanner effectively checks them against both agglutinated regexps + * (detailed information about matched regexps can be obtained with AcceptedRegexps()). + * + * Returns default-constructed scanner in case of failure + * (consult Scanner::Empty() to find out whether the operation was successful). + */ + static HalfFinalScanner Glue(const HalfFinalScanner& a, const HalfFinalScanner& b, size_t maxSize = 0) { + return Scanner::Glue(a, b, maxSize); + } + + ScannerRowHeader& Header(const State& s) { return Scanner::Header(s.ScannerState); } + + const ScannerRowHeader& Header(const State& s) const { return Scanner::Header(s.ScannerState); } + +private: + void BuildFinals(const HalfFinalFsm& fsm) { + Y_ASSERT(Scanner::m_buffer); + Y_ASSERT(fsm.GetFsm().Size() == Scanner::Size()); auto finalWriter = Scanner::m_final; - for (size_t state = 0; state < Scanner::Size(); ++state) { + for (size_t state = 0; state < Scanner::Size(); ++state) { Scanner::m_finalIndex[state] = finalWriter - Scanner::m_final; - for (size_t i = 0; i < fsm.GetCount(state); i++) { + for (size_t i = 0; i < fsm.GetCount(state); i++) { *finalWriter++ = 0; - } + } *finalWriter++ = static_cast<size_t>(-1); - } - } - - template<class Scanner> - friend void Pire::BuildScanner(const Fsm&, Scanner&); - - typedef State InternalState; // Needed for agglutination -}; - -} - - -typedef Impl::HalfFinalScanner<Impl::Relocatable, Impl::ExitMasks<2> > HalfFinalScanner; -typedef Impl::HalfFinalScanner<Impl::Relocatable, Impl::NoShortcuts> HalfFinalScannerNoMask; - -/** - * Same as above, but does not allow relocation or mmap()-ing. - * On the other hand, runs faster than HalfFinal. - */ -typedef Impl::HalfFinalScanner<Impl::Nonrelocatable, Impl::ExitMasks<2> > NonrelocHalfFinalScanner; -typedef Impl::HalfFinalScanner<Impl::Nonrelocatable, Impl::NoShortcuts> NonrelocHalfFinalScannerNoMask; - -} - - -namespace std { - inline void swap(Pire::HalfFinalScanner& a, Pire::HalfFinalScanner& b) { - a.Swap(b); - } - - inline void swap(Pire::NonrelocHalfFinalScanner& a, Pire::NonrelocHalfFinalScanner& b) { - a.Swap(b); - } -} - -#endif + } + } + + template<class Scanner> + friend void Pire::BuildScanner(const Fsm&, Scanner&); + + typedef State InternalState; // Needed for agglutination +}; + +} + + +typedef Impl::HalfFinalScanner<Impl::Relocatable, Impl::ExitMasks<2> > HalfFinalScanner; +typedef Impl::HalfFinalScanner<Impl::Relocatable, Impl::NoShortcuts> HalfFinalScannerNoMask; + +/** + * Same as above, but does not allow relocation or mmap()-ing. + * On the other hand, runs faster than HalfFinal. + */ +typedef Impl::HalfFinalScanner<Impl::Nonrelocatable, Impl::ExitMasks<2> > NonrelocHalfFinalScanner; +typedef Impl::HalfFinalScanner<Impl::Nonrelocatable, Impl::NoShortcuts> NonrelocHalfFinalScannerNoMask; + +} + + +namespace std { + inline void swap(Pire::HalfFinalScanner& a, Pire::HalfFinalScanner& b) { + a.Swap(b); + } + + inline void swap(Pire::NonrelocHalfFinalScanner& a, Pire::NonrelocHalfFinalScanner& b) { + a.Swap(b); + } +} + +#endif diff --git a/contrib/libs/pire/pire/scanners/loaded.h b/contrib/libs/pire/pire/scanners/loaded.h index 120dc403b7..43729544f7 100644 --- a/contrib/libs/pire/pire/scanners/loaded.h +++ b/contrib/libs/pire/pire/scanners/loaded.h @@ -129,7 +129,7 @@ public: Impl::CheckAlign(ptr); LoadedScanner s; const size_t* p = reinterpret_cast<const size_t*>(ptr); - Header header = Impl::ValidateHeader(p, size, ScannerIOTypes::LoadedScanner, sizeof(s.m)); + Header header = Impl::ValidateHeader(p, size, ScannerIOTypes::LoadedScanner, sizeof(s.m)); if (type) { *type = header.Type; } diff --git a/contrib/libs/pire/pire/scanners/multi.h b/contrib/libs/pire/pire/scanners/multi.h index 29679e416e..1ec0edd2c3 100644 --- a/contrib/libs/pire/pire/scanners/multi.h +++ b/contrib/libs/pire/pire/scanners/multi.h @@ -205,12 +205,12 @@ public: } } - Scanner(Scanner&& s) - { - Alias(Null()); - Swap(s); - } - + Scanner(Scanner&& s) + { + Alias(Null()); + Swap(s); + } + template<class AnotherRelocation> Scanner(const Scanner<AnotherRelocation, Shortcutting>& s) { @@ -248,7 +248,7 @@ public: Scanner s; const size_t* p = reinterpret_cast<const size_t*>(ptr); - Impl::ValidateHeader(p, size, ScannerIOTypes::Scanner, sizeof(m)); + Impl::ValidateHeader(p, size, ScannerIOTypes::Scanner, sizeof(m)); if (size < sizeof(s.m)) throw Error("EOF reached while mapping Pire::Scanner"); @@ -311,7 +311,7 @@ public: ScannerRowHeader& Header(State s) { return *(ScannerRowHeader*) s; } const ScannerRowHeader& Header(State s) const { return *(const ScannerRowHeader*) s; } -protected: +protected: struct Locals { ui32 statesCount; @@ -558,7 +558,7 @@ struct ScannerSaver { typename ScannerType::Locals mc = scanner.m; mc.initial -= reinterpret_cast<size_t>(scanner.m_transitions); - SavePodType(s, Pire::Header(ScannerIOTypes::Scanner, sizeof(mc))); + SavePodType(s, Pire::Header(ScannerIOTypes::Scanner, sizeof(mc))); Impl::AlignSave(s, sizeof(Pire::Header)); SavePodType(s, mc); Impl::AlignSave(s, sizeof(mc)); @@ -574,7 +574,7 @@ struct ScannerSaver { typedef Scanner<Relocatable, Shortcutting> ScannerType; Scanner<Relocatable, Shortcutting> sc; - Impl::ValidateHeader(s, ScannerIOTypes::Scanner, sizeof(sc.m)); + Impl::ValidateHeader(s, ScannerIOTypes::Scanner, sizeof(sc.m)); LoadPodType(s, sc.m); Impl::AlignLoad(s, sizeof(sc.m)); if (Shortcutting::Signature != sc.m.shortcuttingSignature) @@ -1118,11 +1118,11 @@ typedef Impl::Scanner<Impl::Nonrelocatable, Impl::NoShortcuts> NonrelocScannerNo } namespace std { - inline void swap(Pire::Scanner& a, Pire::Scanner& b) { + inline void swap(Pire::Scanner& a, Pire::Scanner& b) { a.Swap(b); } - inline void swap(Pire::NonrelocScanner& a, Pire::NonrelocScanner& b) { + inline void swap(Pire::NonrelocScanner& a, Pire::NonrelocScanner& b) { a.Swap(b); } } diff --git a/contrib/libs/pire/pire/scanners/null.cpp b/contrib/libs/pire/pire/scanners/null.cpp index f0e21ce4d3..a4e3911e3d 100644 --- a/contrib/libs/pire/pire/scanners/null.cpp +++ b/contrib/libs/pire/pire/scanners/null.cpp @@ -1,6 +1,6 @@ #include <contrib/libs/pire/pire/fsm.h> #include "multi.h" -#include "half_final.h" +#include "half_final.h" #include "simple.h" #include "slow.h" #include "loaded.h" diff --git a/contrib/libs/pire/pire/scanners/simple.h b/contrib/libs/pire/pire/scanners/simple.h index ef959aeed1..e57f05bdfb 100644 --- a/contrib/libs/pire/pire/scanners/simple.h +++ b/contrib/libs/pire/pire/scanners/simple.h @@ -64,10 +64,10 @@ public: bool Dead(const State&) const { return false; } - ypair<const size_t*, const size_t*> AcceptedRegexps(const State& s) const { - return Final(s) ? Accept() : Deny(); - } - + ypair<const size_t*, const size_t*> AcceptedRegexps(const State& s) const { + return Final(s) ? Accept() : Deny(); + } + /// returns an initial state for this scanner void Initialize(State& state) const { state = m.initial; } @@ -128,7 +128,7 @@ public: SimpleScanner s; const size_t* p = reinterpret_cast<const size_t*>(ptr); - Impl::ValidateHeader(p, size, ScannerIOTypes::SimpleScanner, sizeof(m)); + Impl::ValidateHeader(p, size, ScannerIOTypes::SimpleScanner, sizeof(m)); if (size < sizeof(s.m)) throw Error("EOF reached while mapping NPire::Scanner"); @@ -185,18 +185,18 @@ protected: return n; } - static ypair<const size_t*, const size_t*> Accept() - { - static size_t v[1] = { 0 }; - return ymake_pair(v, v + 1); - } - - static ypair<const size_t*, const size_t*> Deny() - { - static size_t v[1] = { 0 }; - return ymake_pair(v, v); - } - + static ypair<const size_t*, const size_t*> Accept() + { + static size_t v[1] = { 0 }; + return ymake_pair(v, v + 1); + } + + static ypair<const size_t*, const size_t*> Deny() + { + static size_t v[1] = { 0 }; + return ymake_pair(v, v); + } + /* * Initializes pointers depending on buffer start, letters and states count */ diff --git a/contrib/libs/pire/pire/scanners/slow.h b/contrib/libs/pire/pire/scanners/slow.h index 6adfcb8c1d..3c8ce9759f 100644 --- a/contrib/libs/pire/pire/scanners/slow.h +++ b/contrib/libs/pire/pire/scanners/slow.h @@ -177,7 +177,7 @@ public: SlowScanner s; const size_t* p = reinterpret_cast<const size_t*>(ptr); - Impl::ValidateHeader(p, size, ScannerIOTypes::SlowScanner, sizeof(s.m)); + Impl::ValidateHeader(p, size, ScannerIOTypes::SlowScanner, sizeof(s.m)); Locals* locals; Impl::MapPtr(locals, 1, p, size); memcpy(&s.m, locals, sizeof(s.m)); diff --git a/library/cpp/regex/pire/ut/ya.make b/library/cpp/regex/pire/ut/ya.make index 8776695f40..780185b84f 100644 --- a/library/cpp/regex/pire/ut/ya.make +++ b/library/cpp/regex/pire/ut/ya.make @@ -35,10 +35,10 @@ SRCS( approx_matching_ut.cpp ) -SIZE(MEDIUM) - -TIMEOUT(600) - +SIZE(MEDIUM) + +TIMEOUT(600) + PIRE_INLINE(inline_ut.cpp) END() diff --git a/library/cpp/regex/pire/ya.make b/library/cpp/regex/pire/ya.make index c857e6d18b..6575cf9453 100644 --- a/library/cpp/regex/pire/ya.make +++ b/library/cpp/regex/pire/ya.make @@ -27,7 +27,7 @@ SRCS( read_unicode.cpp extraencodings.cpp approx_matching.cpp - half_final_fsm.cpp + half_final_fsm.cpp minimize.h ) |