diff options
author | munjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-25 06:03:03 +0000 |
---|---|---|
committer | munjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-25 06:03:03 +0000 |
commit | 9ff22ee49210c04a4f06f6da034360948dab409a (patch) | |
tree | 9606a41467af85d99396cf75d3922d697dd84a29 /app | |
parent | efe9922157e9824cce7afe5671c2c68ab38b3091 (diff) | |
download | chromium_src-9ff22ee49210c04a4f06f6da034360948dab409a.zip chromium_src-9ff22ee49210c04a4f06f6da034360948dab409a.tar.gz chromium_src-9ff22ee49210c04a4f06f6da034360948dab409a.tar.bz2 |
Add a method to TreeNode to return total number of nodes in a subtree.
BUG=25542
TEST=none
Review URL: http://codereview.chromium.org/332016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30027 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/tree_node_model.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/app/tree_node_model.h b/app/tree_node_model.h index 7d96438..8d8b713 100644 --- a/app/tree_node_model.h +++ b/app/tree_node_model.h @@ -104,6 +104,17 @@ class TreeNode : public TreeModelNode { return static_cast<int>(children_->size()); } + // Returns the number of all nodes in teh subtree rooted at this node, + // including this node. + int GetTotalNodeCount() const { + int count = 1; // Start with one to include the node itself. + for (size_t i = 0; i < children_->size(); ++i) { + TreeNode<NodeType>* child = children_[i]; + count += child->GetTotalNodeCount(); + } + return count; + } + // Returns a child by index. NodeType* GetChild(int index) { DCHECK(index >= 0 && index < GetChildCount()); |