93 cerr <<
"ERROR : " << s <<
" : " << *t << endl;
96 #define ERROR(s,t) { error(s,t); exit(1); }
108 fAperture(calcTreeAperture(n,br)),
152 tvec::const_iterator b = br.begin();
153 tvec::const_iterator z = br.end();
156 hk = (hk << 1) ^ (hk >> 20) ^ ((*b)->fHashKey);
167 for (
int i=0; i<ar; i++) br[i] = tbl[i];
172 while (t && !t->
equiv(n, br)) {
175 return (t) ? t :
new CTree(hk, n, br);
184 while (t && !t->
equiv(n, br)) {
187 return (t) ? t :
new CTree(hk, n, br);
194 fout <<
"<" <<
this <<
">@";
200 for (sep =
'[', i = 0; i < a; sep =
',', i++) {
212 printf(
"\ngHashTable Content :\n\n");
216 printf (
"%4d = ", i);
225 printf(
"\nEnd gHashTable\n");
240 ERROR(
"the node of the tree is not an int nor a float", t);
256 ERROR(
"the node of the tree is not a float nor an int", t);
272 ERROR(
"the node of the tree is not a float nor an int", t);
282 ERROR(
"the node of the tree is not a symbol", t);
292 ERROR(
"the node of the tree is not a pointer", t);
307 return (t->
node() == n);
312 if ((t->
node() == n) && (t->
arity() == 1)) {
322 if ((t->
node() == n) && (t->
arity() == 2)) {
333 if ((t->
node() == n) && (t->
arity() == 3)) {
345 if ((t->
node() == n) && (t->
arity() == 4)) {
358 if ((t->
node() == n) && (t->
arity() == 5)) {
391 keys.push_back(p->first);
392 values.push_back(p->second);
A tree library with hashconsing and maximal sharing capabilities.
Class Node = (type x (int + double + Sym + void*))
bool equiv(const Node &n, const tvec &br) const
used to check if an equivalent tree already exists
int tree2int(Tree t)
if t has a node of type int, return it otherwise error
static unsigned int calcTreeHash(const Node &n, const tvec &br)
compute the hash key of a tree according to its node and branches
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
const Node & node() const
return the content of the tree
static Tree make(const Node &n, int ar, Tree br[])
return a new tree or an existing equivalent one
static Tree gHashTable[kHashTableSize]
hash table used for "hash consing"
static const int kHashTableSize
static void error(const char *s, Tree t)
void * getUserData(Tree t)
if t has a node of type symbol, return the associated user data
plist fProperties
the properties list attached to the tree
bool isDouble(const Node &n)
bool isSym(const Node &n)
ostream & print(ostream &fout) const
print recursively the content of a tree on a stream
unsigned int fHashKey
the hashtable key
static bool gDetails
Ctree::print() print with more details when true.
Tree fNext
next tree in the same hashtable entry
int arity() const
return the number of branches (subtrees) of a tree
const char * name(Symbol *sym)
Returns the name of a symbol.
void * tree2ptr(Tree t)
if t has a node of type ptr, return it otherwise error
static void control()
print the hash table content (for debug purpose)
Symbols are unique objects with a name stored in a hash table.
bool isTree(const Tree &t, const Node &n)
CTree(unsigned int hk, const Node &n, const tvec &br)
construction is private, uses tree::make instead
Node fNode
the node content of the tree
Symbol * symbol(const char *str)
Returns (and creates if new) the symbol of name str.
bool isPointer(const Node &n)
double tree2double(Tree t)
if t has a node of type float, return it otherwise error
static unsigned int gVisitTime
Should be incremented for each new visit to keep track of visited tree.
bool isInt(const Node &n)
double tree2float(Tree t)
if t has a node of type float, return it otherwise error
void exportProperties(vector< Tree > &keys, vector< Tree > &values)
export the properties of a CTree as two vectors, one for the keys and one for the associated values ...
const char * tree2str(Tree t)
if t has a node of type symbol, return its name otherwise error
Tree branch(int i) const
return the ith branch (subtree) of a tree