153 ostream&
print (ostream& fout)
const;
192 inline Tree tree (
const Node& n,
const Tree& a,
const Tree& b,
const Tree& c,
const Tree& d,
const Tree& e) {
Tree br[]= {a,b,c,d,e};
return CTree::make(n, 5, br); }
A library to create and manipulate symbols with a unique name.
Class Node = (type x (int + double + Sym + void*))
double tree2float(Tree t)
if t has a node of type float, return it otherwise error
bool equiv(const Node &n, const tvec &br) const
used to check if an equivalent tree already exists
int fAperture
how "open" is a tree (synthezised field)
void updateAperture(Tree t)
void * tree2ptr(Tree t)
if t has a node of type ptr, return it otherwise error
A Node is a tagged unions of int, double, symbol and void* used in the implementation of CTrees...
bool isOpen(Tree t)
t contains free de Bruijn references
Tree deBruijn2Sym(Tree t)
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
unsigned int hashkey() const
return the hashkey of the tree
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"
void * getUserData(Tree t)
if t has a node of type symbol, return the associated user data
Tree rec(Tree body)
create a de Bruijn recursive tree
bool isClosed(Tree t)
t dont contain free de Bruijn ref
static void startNewVisit()
static const int kHashTableSize
unsigned int fVisitTime
keep track of visits
Tree ref(int level)
create a de Bruijn recursive reference
ostream & print(ostream &fout)
plist fProperties
the properties list attached to the tree
void setProperty(Tree key, Tree value)
bool isRec(Tree t, Tree &body)
is t a de Bruijn recursive tree
void * fType
the type of a tree
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
double tree2double(Tree t)
if t has a node of type float, return it otherwise error
int arity() const
return the number of branches (subtrees) of a tree
const tvec & branches() const
return all branches (subtrees) of a tree
bool isRef(Tree t, int &level)
is t a de Bruijn recursive reference
ostream & operator<<(ostream &s, const CTree &t)
static void control()
print the hash table content (for debug purpose)
static int calcTreeAperture(const Node &n, const tvec &br)
compute how open is a tree
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
int aperture() const
return how "open" is a tree in terms of free variables
static unsigned int gVisitTime
Should be incremented for each new visit to keep track of visited tree.
Tree getProperty(Tree key)
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
void clearProperty(Tree key)
void setAperture(int a)
modify the aperture of a tree
bool isTree(const Tree &t, const Node &n)