summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cacount.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/cacount.cpp b/cacount.cpp
index 210d9b8..bd8f1a6 100644
--- a/cacount.cpp
+++ b/cacount.cpp
@@ -9,6 +9,8 @@
#include <map>
#include <set>
+#include <sys/mman.h>
+
using namespace std;
typedef uint32_t State;
@@ -48,19 +50,17 @@ void init(Trans &t) {
t[s] = update(s); });
}
-Trans* findCycle(Trans &t) {
+void findCycle(Trans &t, Trans &c) {
// forward to t=maxState; now every state is in a cycle
iterTrans(logState, [&](int s) {
t[s] = t[t[s]]; }, true);
// compute loop id (lowest occuring state no): go through the loop again and
// record the lowest occuring state number
- Trans &c(*new Trans());
iterState([&](int s) {
c[s] = t[s]; });
iterTrans(logState, [&](int s) {
c[s] = min(c[s], c[t[s]]);
t[s] = t[t[s]]; }, true);
- return &c;
}
void cycleStat(Trans &c) {
@@ -120,6 +120,16 @@ void printTraj(State s, int count) {
}
}
+template<typename T>
+T* mmalloc() {
+ void *p = MAP_FAILED;
+ for (auto flag : {MAP_POPULATE | MAP_HUGETLB, MAP_POPULATE, 0})
+ if (p == MAP_FAILED)
+ p = mmap(NULL, sizeof(Trans), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | flag, -1, 0);
+ assert(p != MAP_FAILED);
+ return (T*) p;
+}
+
int main(int argc, char **argv) {
assert(argc >= 2);
rule = atoi(argv[1]);
@@ -128,10 +138,11 @@ int main(int argc, char **argv) {
printTraj(atoi(argv[3]), atoi(argv[4]));
}
if (!strcmp(argv[2], "cycle")) {
- Trans &t = *(new Trans);
- init(t);
- Trans &c(*findCycle(t));
- cycleStat(c);
+ Trans *t = mmalloc<Trans>(),
+ *c = mmalloc<Trans>();
+ init(*t);
+ findCycle(*t, *c);
+ cycleStat(*c);
}
return 0;
}
contact: Jan Huwald // Impressum