ddc05dcd7ce67ba39b3215ccce319984a39c20c7
1 /************************************************************************
2 ************************************************************************
4 Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale
5 ---------------------------------------------------------------------
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 ************************************************************************
20 ************************************************************************/
22 * @file occurrences.cpp
23 * Count the number of occurences of each subtree of a root tree.
29 // construction des representations graphiques
32 #include "occurrences.hh"
33 #include "compatibility.hh"
36 * Count the number of occurrences of each subtree of root
38 Occurrences::Occurrences(Tree root
)
40 fKey
= specificKey(root
);
41 countOccurrences(root
);
42 setCount(root
,0); // root as no occurences in itself
46 * Get the number of occurrences of t
48 int Occurrences::getCount(Tree t
)
51 return (getProperty(t
, fKey
, c
)) ? c
->node().getInt() : 0;
55 * Set the number of occurrences of t
57 void Occurrences::setCount(Tree t
, int c
)
59 setProperty(t
, fKey
, tree(c
));
65 * Creates a specific property key for occurrences count in root
67 Tree
Occurrences::specificKey(Tree root
)
70 snprintf(keyname
, 256, "OCCURRENCES COUNT IN %p : ", (CTree
*)root
);
72 return tree(unique(keyname
));
76 * Increment the occurrences count of t and its subtrees
78 void Occurrences::countOccurrences(Tree t
)
80 setCount(t
, getCount(t
)+1); // increment t occurrences count
81 for (int i
=0; i
<t
->arity(); i
++) {
82 countOccurrences(t
->branch(i
));