FAUST compiler  0.9.9.6b8
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Occurrences Class Reference

Count subtree occurences Count the number of occurences of each subtree of a root tree. More...

#include <occurrences.hh>

Collaboration diagram for Occurrences:
Collaboration graph
[legend]

Public Member Functions

 Occurrences (Tree root)
 Count the number of occurrences of each subtree of root. More...
 
int getCount (Tree t)
 Get the number of occurrences of t. More...
 

Private Member Functions

Tree specificKey (Tree root)
 Creates a specific property key for occurrences count in root. More...
 
void countOccurrences (Tree t)
 Increment the occurrences count of t and its subtrees. More...
 
void setCount (Tree t, int c)
 Set the number of occurrences of t. More...
 

Private Attributes

Tree fKey
 

Detailed Description

Count subtree occurences Count the number of occurences of each subtree of a root tree.

Definition at line 32 of file occurrences.hh.

Constructor & Destructor Documentation

Occurrences::Occurrences ( Tree  root)

Count the number of occurrences of each subtree of root.

Definition at line 38 of file occurrences.cpp.

References countOccurrences(), fKey, setCount(), and specificKey().

39 {
40  fKey = specificKey(root);
41  countOccurrences(root);
42  setCount(root,0); // root as no occurences in itself
43 }
void countOccurrences(Tree t)
Increment the occurrences count of t and its subtrees.
Definition: occurrences.cpp:78
void setCount(Tree t, int c)
Set the number of occurrences of t.
Definition: occurrences.cpp:57
Tree specificKey(Tree root)
Creates a specific property key for occurrences count in root.
Definition: occurrences.cpp:67

Here is the call graph for this function:

Member Function Documentation

void Occurrences::countOccurrences ( Tree  t)
private

Increment the occurrences count of t and its subtrees.

Definition at line 78 of file occurrences.cpp.

References CTree::arity(), CTree::branch(), getCount(), and setCount().

Referenced by Occurrences().

79 {
80  setCount(t, getCount(t)+1); // increment t occurrences count
81  for (int i=0; i<t->arity(); i++) {
82  countOccurrences(t->branch(i));
83  }
84 }
void countOccurrences(Tree t)
Increment the occurrences count of t and its subtrees.
Definition: occurrences.cpp:78
void setCount(Tree t, int c)
Set the number of occurrences of t.
Definition: occurrences.cpp:57
int arity() const
return the number of branches (subtrees) of a tree
Definition: tree.hh:144
int getCount(Tree t)
Get the number of occurrences of t.
Definition: occurrences.cpp:48
Tree branch(int i) const
return the ith branch (subtree) of a tree
Definition: tree.hh:145

Here is the call graph for this function:

Here is the caller graph for this function:

int Occurrences::getCount ( Tree  t)

Get the number of occurrences of t.

Definition at line 48 of file occurrences.cpp.

References fKey, Node::getInt(), getProperty(), and CTree::node().

Referenced by countOccurrences().

49 {
50  Tree c;
51  return (getProperty(t, fKey, c)) ? c->node().getInt() : 0;
52 }
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
const Node & node() const
return the content of the tree
Definition: tree.hh:143
int getInt() const
Definition: node.hh:104
bool getProperty(Tree t, Tree key, Tree &val)
Definition: list.cpp:423

Here is the call graph for this function:

Here is the caller graph for this function:

void Occurrences::setCount ( Tree  t,
int  c 
)
private

Set the number of occurrences of t.

Definition at line 57 of file occurrences.cpp.

References fKey, setProperty(), and tree().

Referenced by countOccurrences(), and Occurrences().

58 {
59  setProperty(t, fKey, tree(c));
60 }
Tree tree(const Node &n)
Definition: tree.hh:186
void setProperty(Tree t, Tree key, Tree val)
Definition: list.cpp:418

Here is the call graph for this function:

Here is the caller graph for this function:

Tree Occurrences::specificKey ( Tree  root)
private

Creates a specific property key for occurrences count in root.

Definition at line 67 of file occurrences.cpp.

References tree(), and unique().

Referenced by Occurrences().

68 {
69  char keyname[256];
70  snprintf(keyname, 256, "OCCURRENCES COUNT IN %p : ", (CTree*)root);
71 
72  return tree(unique(keyname));
73 }
Symbol * unique(const char *str)
Returns a new unique symbol of name strxxx.
Definition: symbol.hh:97
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree tree(const Node &n)
Definition: tree.hh:186

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

Tree Occurrences::fKey
private

Definition at line 34 of file occurrences.hh.

Referenced by getCount(), Occurrences(), and setCount().


The documentation for this class was generated from the following files: