}
TreeNode::~TreeNode() {
- std::map<tree_t, class TreeNode *>::iterator it;
+ std::map<int, class TreeNode *>::iterator it;
for (it = children.begin(); it != children.end(); it++)
delete it->second;
}
-TreeNode * TreeNode::exploreChild(tree_t id)
+TreeNode * TreeNode::exploreChild(thread_id_t id)
{
TreeNode *n;
- std::set<tree_t >::iterator it;
+ std::set<int>::iterator it;
+ int i = id_to_int(id);
if (!hasBeenExplored(id)) {
n = new TreeNode(this);
- children[id] = n;
+ children[i] = n;
} else {
- n = children[id];
+ n = children[i];
}
- if ((it = backtrack.find(id)) != backtrack.end())
+ if ((it = backtrack.find(i)) != backtrack.end())
backtrack.erase(it);
return n;
}
-int TreeNode::setBacktrack(tree_t id)
+int TreeNode::setBacktrack(thread_id_t id)
{
- if (backtrack.find(id) != backtrack.end())
+ int i = id_to_int(id);
+ if (backtrack.find(i) != backtrack.end())
return 1;
- backtrack.insert(id);
+ backtrack.insert(i);
return 0;
}
-tree_t TreeNode::getNextBacktrack()
+thread_id_t TreeNode::getNextBacktrack()
{
if (backtrack.empty())
- return TREE_T_NONE;
- return *backtrack.begin();
+ return THREAD_ID_T_NONE;
+ return int_to_id(*backtrack.begin());
}
TreeNode * TreeNode::getRoot()
#include <map>
#include "threads.h"
-typedef thread_id_t tree_t;
-#define TREE_T_NONE THREAD_ID_T_NONE
-
/*
* An n-ary tree
*
public:
TreeNode(TreeNode *par);
~TreeNode();
- bool hasBeenExplored(tree_t id) { return children.find(id) != children.end(); }
- TreeNode * exploreChild(tree_t id);
- tree_t getNextBacktrack();
+ bool hasBeenExplored(thread_id_t id) { return children.find(id_to_int(id)) != children.end(); }
+ TreeNode * exploreChild(thread_id_t id);
+ thread_id_t getNextBacktrack();
/* Return 1 if already in backtrack, 0 otherwise */
- int setBacktrack(tree_t id);
+ int setBacktrack(thread_id_t id);
TreeNode * getRoot();
static int getTotalNodes() { return TreeNode::totalNodes; }
private:
TreeNode *parent;
- std::map<tree_t, class TreeNode *> children;
- std::set<tree_t> backtrack;
+ std::map<int, class TreeNode *> children;
+ std::set<int> backtrack;
static int totalNodes;
};