content: pyramid, build
This commit is contained in:
25
test.cpp
25
test.cpp
@@ -111,7 +111,9 @@ class AnswerCache
|
||||
{
|
||||
private:
|
||||
std::unordered_map<string, bool> mAllowedBottomcache;
|
||||
unsigned long long cacheHit, cacheWrite, cacheRead;
|
||||
|
||||
private:
|
||||
string wholeRowToString(unsigned rowIdx)
|
||||
{
|
||||
string s = "";
|
||||
@@ -134,13 +136,22 @@ public:
|
||||
// false: not in cache, true: hit
|
||||
int getCache(int rowIdx)
|
||||
{
|
||||
++cacheRead;
|
||||
string rowStr = wholeRowToString(rowIdx);
|
||||
return mAllowedBottomcache.contains(rowStr);
|
||||
}
|
||||
|
||||
void showCacheStatus()
|
||||
{
|
||||
cout << format("cache R/W: {}/{}, cache hit:{}\n", cacheRead, cacheWrite, cacheHit);
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
mAllowedBottomcache.clear();
|
||||
cacheHit = 0;
|
||||
cacheRead = 0;
|
||||
cacheWrite = 0;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -160,9 +171,9 @@ public:
|
||||
|
||||
// clear manager
|
||||
pMgr.clear();
|
||||
ansCache.clear();
|
||||
|
||||
// clear answer cache
|
||||
ansCache.clear();
|
||||
|
||||
// init pyramid
|
||||
for (int i = 0; i < 6; ++i)
|
||||
@@ -255,6 +266,8 @@ private:
|
||||
|
||||
void setToNextPossibleChar()
|
||||
{
|
||||
bool firstMove = (curChar() == '0');
|
||||
|
||||
// search end
|
||||
if (curChar() == '1')
|
||||
{
|
||||
@@ -286,10 +299,15 @@ private:
|
||||
|
||||
void _search()
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
cout << "enter _search()" << endl;
|
||||
}
|
||||
|
||||
// already found answer
|
||||
if (found || finished)
|
||||
{
|
||||
cout << "found or finished" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -347,6 +365,10 @@ public:
|
||||
while (!found && !finished)
|
||||
{
|
||||
_search();
|
||||
if (debug)
|
||||
{
|
||||
cout << format("found={}, finished={}\n", found, finished);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -366,6 +388,7 @@ public:
|
||||
// search the answer
|
||||
auto searcher = Searcher();
|
||||
searcher.search();
|
||||
ansCache.showCacheStatus();
|
||||
return found;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user