-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDyckWord.cpp
41 lines (32 loc) · 976 Bytes
/
DyckWord.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "DyckWord.h"
int DyckWord::numBrackets(const std::map<Vertex, int>& brackets, Vertex v) {
auto res = brackets.find(v);
if(res == brackets.end()) {
return 0;
}
return res->second;
}
DyckWord::DyckWord(const Graph& g, const std::map<Vertex, int>& lbrackets, const std::map<Vertex, int>& rbrackets, const std::vector<Vertex>& fac)
{
for (const auto& v : fac)
{
std::generate_n(std::back_inserter(dyck_word), numBrackets(lbrackets, v), [] { return Token::createLBracket(); });
dyck_word.push_back(Token::createNode(v)); // vertex
std::generate_n(std::back_inserter(dyck_word), numBrackets(rbrackets, v), [] { return Token::createRBracket(); });
}
}
int DyckWord::size() const
{
return dyck_word.size();
}
Token DyckWord::getToken(int i) const
{
return dyck_word[i];
}
const std::string DyckWord::toString(const Graph& g) const
{
std::string ret;
for (const Token& t : dyck_word)
ret += t.toString(g);
return ret;
}