[mlpack-git] master: Simplify some loops. (0496768)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 21:58:09 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40

>---------------------------------------------------------------

commit 0496768367809c12d13ea9fcb689c7b61bd3850a
Author: Ryan Curtin <ryan at ratml.org>
Date:   Sun Aug 17 05:00:05 2014 +0000

    Simplify some loops.


>---------------------------------------------------------------

0496768367809c12d13ea9fcb689c7b61bd3850a
 .../core/tree/rectangle_tree/r_tree_split_impl.hpp | 24 ++++++----------------
 1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp
index 1469fbe..7a73eff 100644
--- a/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp
@@ -60,15 +60,9 @@ void RTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
 
   // Remove this node and insert treeOne and treeTwo.
   TreeType* par = tree->Parent();
-  int index = 0;
-  for (int i = 0; i < par->NumChildren(); i++)
-  {
-    if (par->Children()[i] == tree)
-    {
-      index = i;
-      break;
-    }
-  }
+  size_t index = 0;
+  while (par->Children()[index] != tree) { ++index; }
+
   par->Children()[index] = treeOne;
   par->Children()[par->NumChildren()++] = treeTwo;
 
@@ -130,15 +124,9 @@ bool RTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
 
   // Remove this node and insert treeOne and treeTwo.
   TreeType* par = tree->Parent();
-  int index = -1;
-  for (int i = 0; i < par->NumChildren(); i++)
-  {
-    if (par->Children()[i] == tree)
-    {
-      index = i;
-      break;
-    }
-  }
+  size_t index = 0;
+  while (par->Children()[index] != tree) { ++index; }
+
   assert(index != -1);
   par->Children()[index] = treeOne;
   par->Children()[par->NumChildren()++] = treeTwo;



More information about the mlpack-git mailing list