From da38ae03edd9a031c82f7ab51c3dab43d49de598 Mon Sep 17 00:00:00 2001 From: Nathan Braswell Date: Fri, 29 Jan 2016 14:09:09 -0500 Subject: [PATCH] Profiled and added a map to GraphStructuredStack's getContainingFrontier to massivly improve the C++ Kraken compiler's compile time by improving parsing time (parsing time cut by significantly more than half) --- include/GraphStructuredStack.h | 1 + src/GraphStructuredStack.cpp | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/include/GraphStructuredStack.h b/include/GraphStructuredStack.h index 7d07443..65e6b12 100644 --- a/include/GraphStructuredStack.h +++ b/include/GraphStructuredStack.h @@ -32,6 +32,7 @@ class GraphStructuredStack { private: std::vector*>*> gss; std::map< std::pair< NodeTree*, NodeTree* >, NodeTree* > edges; + std::map< NodeTree*, int > containing_frontier_map; }; #endif diff --git a/src/GraphStructuredStack.cpp b/src/GraphStructuredStack.cpp index 1d117f3..9246b77 100644 --- a/src/GraphStructuredStack.cpp +++ b/src/GraphStructuredStack.cpp @@ -15,11 +15,10 @@ NodeTree* GraphStructuredStack::newNode(int stateNum) { void GraphStructuredStack::addToFrontier(int frontier, NodeTree* node) { //First, make sure our vector has this and lesser frontiers. If not, add it and up to it while (gss.size() <= frontier) { - //std::cout << "Adding a new frontier: " << gss.size() << std::endl; gss.push_back(new std::vector*>()); } - //std::cout << "Adding " << node << " (" << node->getData() << ") to frontier " << frontier << std::endl; gss[frontier]->push_back(node); + containing_frontier_map[node] = frontier; } NodeTree* GraphStructuredStack::inFrontier(int frontier, int state) { @@ -33,15 +32,19 @@ NodeTree* GraphStructuredStack::inFrontier(int frontier, int state) { } int GraphStructuredStack::getContainingFrontier(NodeTree* node) { - for (std::vector*>*>::size_type i = 0; i < gss.size(); i++) { - if (frontierIsEmpty(i)) - continue; - for (std::vector*>::size_type j = 0; j < gss[i]->size(); j++) { - if ((*(gss[i]))[j] == node) - return i; - } - } - return -1; + auto iter = containing_frontier_map.find(node); + if (iter != containing_frontier_map.end()) + return iter->second; + return -1; + //for (std::vector*>*>::size_type i = 0; i < gss.size(); i++) { + //if (frontierIsEmpty(i)) + //continue; + //for (std::vector*>::size_type j = 0; j < gss[i]->size(); j++) { + //if ((*(gss[i]))[j] == node) + //return i; + //} + //} + //return -1; } bool GraphStructuredStack::frontierIsEmpty(int frontier) {