forked from jasder/antlr
DFA states member is now a set (instead of a map).
This commit is contained in:
parent
e9d2a04be1
commit
c920d57331
|
@ -64,7 +64,7 @@ namespace atn {
|
|||
|
||||
virtual std::string toString();
|
||||
private:
|
||||
std::vector<Ref<PredictionContext>> makeRef(const std::vector<std::weak_ptr<PredictionContext> > &input);
|
||||
std::vector<Ref<PredictionContext>> makeRef(const std::vector<std::weak_ptr<PredictionContext>> &input);
|
||||
};
|
||||
|
||||
} // namespace atn
|
||||
|
|
|
@ -322,7 +322,7 @@ atn::ATNState *LexerATNSimulator::getReachableTarget(Transition *trans, ssize_t
|
|||
}
|
||||
|
||||
std::unique_ptr<ATNConfigSet> LexerATNSimulator::computeStartState(CharStream *input, ATNState *p) {
|
||||
Ref<PredictionContext> initialContext = PredictionContext::EMPTY; // ml: the purpose of this assignment is unclear
|
||||
Ref<PredictionContext> initialContext = PredictionContext::EMPTY; // ml: the purpose of this assignment is unclear
|
||||
std::unique_ptr<ATNConfigSet> configs(new OrderedATNConfigSet());
|
||||
for (size_t i = 0; i < p->getNumberOfTransitions(); i++) {
|
||||
ATNState *target = p->transition(i)->target;
|
||||
|
@ -582,13 +582,13 @@ dfa::DFAState *LexerATNSimulator::addDFAState(ATNConfigSet *configs) {
|
|||
auto iterator = dfa.states.find(proposed);
|
||||
if (iterator != dfa.states.end()) {
|
||||
delete proposed;
|
||||
return iterator->second;
|
||||
return *iterator;
|
||||
}
|
||||
}
|
||||
|
||||
proposed->stateNumber = (int)dfa.states.size();
|
||||
proposed->configs->setReadonly(true);
|
||||
dfa.states[proposed] = proposed;
|
||||
dfa.states.insert(proposed);
|
||||
return proposed;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1197,7 +1197,7 @@ dfa::DFAState *ParserATNSimulator::addDFAState(dfa::DFA &dfa, dfa::DFAState *D)
|
|||
|
||||
auto existing = dfa.states.find(D);
|
||||
if (existing != dfa.states.end()) {
|
||||
return existing->second;
|
||||
return *existing;
|
||||
}
|
||||
|
||||
D->stateNumber = (int)dfa.states.size();
|
||||
|
@ -1205,7 +1205,7 @@ dfa::DFAState *ParserATNSimulator::addDFAState(dfa::DFA &dfa, dfa::DFAState *D)
|
|||
D->configs->optimizeConfigs(this);
|
||||
D->configs->setReadonly(true);
|
||||
}
|
||||
dfa.states[D] = D;
|
||||
dfa.states.insert(D);
|
||||
if (debug) {
|
||||
std::cout << "adding new DFA state: " << D << std::endl;
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ DFA::DFA(const DFA &other) : atnStartState(other.atnStartState), decision(other.
|
|||
|
||||
DFA::~DFA() {
|
||||
for (auto state : states) {
|
||||
delete state.second;
|
||||
delete state;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ void DFA::setPrecedenceStartState(int precedence, DFAState *startState) {
|
|||
std::vector<DFAState *> DFA::getStates() const {
|
||||
std::vector<DFAState *> result;
|
||||
for (auto state : states)
|
||||
result.push_back(state.first);
|
||||
result.push_back(state);
|
||||
|
||||
std::sort(result.begin(), result.end(), [](DFAState *o1, DFAState *o2) -> bool {
|
||||
return o1->stateNumber < o2->stateNumber;
|
||||
|
|
|
@ -43,7 +43,7 @@ namespace dfa {
|
|||
|
||||
/// From which ATN state did we create this DFA?
|
||||
atn::DecisionState *const atnStartState;
|
||||
std::unordered_map<DFAState *, DFAState *, DFAState::Hasher, DFAState::Comparer> states; // States are owned by this class.
|
||||
std::unordered_set<DFAState *, DFAState::Hasher, DFAState::Comparer> states; // States are owned by this class.
|
||||
DFAState *s0;
|
||||
const int decision;
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ std::set<int> DFAState::getAltSet() {
|
|||
}
|
||||
return alts;
|
||||
}
|
||||
|
||||
|
||||
size_t DFAState::hashCode() const {
|
||||
size_t hash = misc::MurmurHash::initialize(7);
|
||||
hash = misc::MurmurHash::update(hash, configs->hashCode());
|
||||
|
@ -93,7 +93,7 @@ bool DFAState::operator == (const DFAState &o) const {
|
|||
return true;
|
||||
}
|
||||
|
||||
return configs == o.configs;
|
||||
return *configs == *o.configs;
|
||||
}
|
||||
|
||||
std::string DFAState::toString() {
|
||||
|
|
|
@ -67,6 +67,11 @@ namespace misc {
|
|||
return update(hash, value != nullptr ? value->hashCode() : 0);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static size_t update(size_t hash, T *value) {
|
||||
return update(hash, value != nullptr ? value->hashCode() : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply the final computation steps to the intermediate value {@code hash}
|
||||
/// to form the final result of the MurmurHash 3 hash function.
|
||||
|
|
Loading…
Reference in New Issue