Count subtree occurences Count the number of occurences of each subtree of a root tree. More...
#include <occurrences.hh>
Public Member Functions | |
Occurrences (Tree root) | |
Count the number of occurrences of each subtree of root. | |
int | getCount (Tree t) |
Get the number of occurrences of t. | |
Private Member Functions | |
Tree | specificKey (Tree root) |
Creates a specific property key for occurrences count in root. | |
void | countOccurrences (Tree t) |
Increment the occurrences count of t and its subtrees. | |
void | setCount (Tree t, int c) |
Set the number of occurrences of t. | |
Private Attributes | |
Tree | fKey |
Count subtree occurences Count the number of occurences of each subtree of a root tree.
Definition at line 32 of file occurrences.hh.
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().
00039 { 00040 fKey = specificKey(root); 00041 countOccurrences(root); 00042 setCount(root,0); // root as no occurences in itself 00043 }
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().
00079 { 00080 setCount(t, getCount(t)+1); // increment t occurrences count 00081 for (int i=0; i<t->arity(); i++) { 00082 countOccurrences(t->branch(i)); 00083 } 00084 }
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().
00049 { 00050 Tree c; 00051 return (getProperty(t, fKey, c)) ? c->node().getInt() : 0; 00052 }
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().
00058 { 00059 setProperty(t, fKey, tree(c)); 00060 }
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().
00068 { 00069 char keyname[256]; 00070 snprintf(keyname, 256, "OCCURRENCES COUNT IN %p : ", (CTree*)root); 00071 00072 return tree(unique(keyname)); 00073 }
Tree Occurrences::fKey [private] |
Definition at line 34 of file occurrences.hh.
Referenced by getCount(), Occurrences(), and setCount().