Skip to content

Commit

Permalink
Meto aun mas movimientos, bajo la cantidad de allocs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan-R0 committed Nov 14, 2020
1 parent a4a78a7 commit ded2539
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
40 changes: 20 additions & 20 deletions graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
#include <map>
#include <string>

bool Graph::hasBeenFound(int node, std::list<int>& found) {
return (find(found.begin(), found.end(), node) != found.end());
}

void Graph::addVertex(int node) { nodes[node] = {}; }

void Graph::addEdge(int from, int to) {
Expand All @@ -33,6 +29,26 @@ void Graph::addIfItsNotIn(int node) {
}
}

void Graph::clear() { nodes.clear(); }

void Graph::connectLast(int to) { this->addEdge(nodes.size() - 1, to); }

void Graph::disconnectNext(int nodo) {
std::list<int> searching = std::move(nodes[nodo]);
for (int& it : searching) {
if (nodo + 1 == it) {
nodes[nodo].remove(it);
break;
}
}
}

void Graph::connect(int from, int to) { nodes[from].push_front(to); }

bool Graph::hasBeenFound(int node, std::list<int>& found) {
return (find(found.begin(), found.end(), node) != found.end());
}

bool Graph::_isCyclic(int start, std::list<int>& found) {
if (hasBeenFound(start, found)) return true;
found.push_front(start);
Expand All @@ -43,8 +59,6 @@ bool Graph::_isCyclic(int start, std::list<int>& found) {
return false;
}

void Graph::clear() { nodes.clear(); }

bool Graph::isCyclic() {
std::list<int> found;
for (auto& it : nodes) {
Expand All @@ -56,8 +70,6 @@ bool Graph::isCyclic() {
return false;
}

void Graph::connectLast(int to) { this->addEdge(nodes.size() - 1, to); }

void Graph::dfs(int start, std::list<int>& found) {
if (hasBeenFound(start, found)) return;
found.push_front(start);
Expand All @@ -76,15 +88,3 @@ bool Graph::hasUnusedInstructions() {
found.clear();
return (amountFound != nodes.size());
}

void Graph::disconnectNext(int nodo) {
std::list<int> searching = std::move(nodes[nodo]);
for (int& it : searching) {
if (nodo + 1 == it) {
nodes[nodo].remove(it);
break;
}
}
}

void Graph::connect(int from, int to) { nodes[from].push_front(to); }
2 changes: 2 additions & 0 deletions graphFiller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ Graphfiller::Graphfiller() {

void Graphfiller::addInstructionToGraph(std::string line, int lineNumber) {
if (line.size() == 0) return;

Asmline instruction;
parser.parseInstruction(std::move(line), instruction);
opGraph.addVertex(lineNumber);
if (lineNumber != 1) opGraph.connectLast(lineNumber);

std::list<std::string> labelsToJump = instruction.getLabelsToJumpTo();
if (instruction.esCortante()) aristaACortar.push_front(lineNumber);
if (instruction.getLabel().size() != 0)
Expand Down
18 changes: 9 additions & 9 deletions parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
#include <string>

#define SUCCESS 0
#define FAILURE (SUCCESS - 1)

Parser::Parser() { delims = {':', ',', ' ', '\n', '\t', '\0'}; }
Parser::Parser() : delims({':', ',', ' ', '\n', '\t', '\0'}) {}

bool Parser::isDelim(char c) {
for (auto i : delims) {
Expand Down Expand Up @@ -50,7 +51,7 @@ static int parseData(Parser* p, std::string asmLine, bool& hasLabel,
}
}
if (!p->isDelim(lastChar)) parts.push_back(placeHolder);
if (parts.size() == 0) return 1; // Empty line.
if (parts.size() == 0) return FAILURE; // Empty line.
parseLabel(instruction, hasLabel, parts);
return SUCCESS;
}
Expand All @@ -61,11 +62,10 @@ void Parser::parseInstruction(std::string asmLine, Asmline& instruction) {

parseSpaces(&asmLine);

if (parseData(this, std::move(asmLine), hasLabel, parts, instruction) !=
SUCCESS)
return;

instruction.setOpCode(std::move(parts.front()));
parts.pop_front();
instruction.setLabelsToJump(std::move(parts));
if (parseData(this, std::move(asmLine), hasLabel, parts, instruction) ==
SUCCESS) {
instruction.setOpCode(std::move(parts.front()));
parts.pop_front();
instruction.setLabelsToJump(std::move(parts));
}
}
6 changes: 3 additions & 3 deletions results.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ void Results::addResult(std::string file, bool hasCycleB, bool hasUnusedOpB) {
std::unique_lock<std::mutex> lock(m);
allops.push_back(file);
if (hasCycleB) {
hasCycle.push_back(file);
hasCycle.push_back(std::move(file));
} else if (hasUnusedOpB) {
hasUnusedInstructions.push_back(file);
hasUnusedInstructions.push_back(std::move(file));
} else {
good.push_back(file);
good.push_back(std::move(file));
}
}

Expand Down

0 comments on commit ded2539

Please sign in to comment.