Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Side by Side Diff: app/tree_node_model.h

Issue 332016: Add a method to TreeNode to return total number of nodes in a subtree. Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef APP_TREE_NODE_MODEL_H_ 5 #ifndef APP_TREE_NODE_MODEL_H_
6 #define APP_TREE_NODE_MODEL_H_ 6 #define APP_TREE_NODE_MODEL_H_
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 for (size_t i = 0; i < children_->size(); ++i) 97 for (size_t i = 0; i < children_->size(); ++i)
98 children_[i]->parent_ = NULL; 98 children_[i]->parent_ = NULL;
99 children_->clear(); 99 children_->clear();
100 } 100 }
101 101
102 // Returns the number of children. 102 // Returns the number of children.
103 int GetChildCount() const { 103 int GetChildCount() const {
104 return static_cast<int>(children_->size()); 104 return static_cast<int>(children_->size());
105 } 105 }
106 106
107 // Returns the number of all nodes in teh subtree rooted at this node,
108 // including this node.
109 int GetTotalNodeCount() const {
110 int count = 1; // Start with one to include the node itself.
111 for (size_t i = 0; i < children_->size()(); ++i) {
sky 2009/10/23 21:50:21 ()()->()
112 TreeNode<NodeType> *child = children_[i];
113 count += child->GetTotalNodeCount();
114 }
115 return count;
116 }
117
107 // Returns a child by index. 118 // Returns a child by index.
108 NodeType* GetChild(int index) { 119 NodeType* GetChild(int index) {
109 DCHECK(index >= 0 && index < GetChildCount()); 120 DCHECK(index >= 0 && index < GetChildCount());
110 return children_[index]; 121 return children_[index];
111 } 122 }
112 const NodeType* GetChild(int index) const { 123 const NodeType* GetChild(int index) const {
113 DCHECK(index >= 0 && index < GetChildCount()); 124 DCHECK(index >= 0 && index < GetChildCount());
114 return children_[index]; 125 return children_[index];
115 } 126 }
116 127
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 // The root. 288 // The root.
278 scoped_ptr<NodeType> root_; 289 scoped_ptr<NodeType> root_;
279 290
280 // The observer. 291 // The observer.
281 TreeModelObserver* observer_; 292 TreeModelObserver* observer_;
282 293
283 DISALLOW_COPY_AND_ASSIGN(TreeNodeModel); 294 DISALLOW_COPY_AND_ASSIGN(TreeNodeModel);
284 }; 295 };
285 296
286 #endif // APP_TREE_NODE_MODEL_H_ 297 #endif // APP_TREE_NODE_MODEL_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698