LR0: Converted ::getExpected from std::vector to std::set

This commit is contained in:
Paul Beckingham 2016-01-02 14:33:05 -05:00
parent 1305c0cb55
commit 31b53e8c23
2 changed files with 6 additions and 6 deletions

View file

@ -116,13 +116,12 @@ LR0::Closure LR0::getClosure (const Closure& items)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Collect a unique set of expected symbols from the closure. // Collect a unique set of expected symbols from the closure.
std::vector <std::string> LR0::getExpected (const Closure& closure) std::set <std::string> LR0::getExpected (const Closure& closure)
{ {
std::vector <std::string> expected; std::set <std::string> expected;
for (auto& item : closure) for (auto& item : closure)
if (! item.done () && if (! item.done ())
std::find (expected.begin (), expected.end (), item.next ()) == expected.end ()) expected.insert (item.next ());
expected.push_back (item.next ());
return expected; return expected;
} }

View file

@ -28,6 +28,7 @@
#define INCLUDED_LR0 #define INCLUDED_LR0
#include <Grammar.h> #include <Grammar.h>
#include <set>
#include <map> #include <map>
#include <string> #include <string>
@ -68,7 +69,7 @@ public:
private: private:
Closure getClosure (const Closure&); Closure getClosure (const Closure&);
std::vector <std::string> getExpected (const Closure&); std::set <std::string> getExpected (const Closure&);
private: private:
// Copy of the augmented grammar. // Copy of the augmented grammar.