[mlpack-svn] r12554 - mlpack/trunk/src/mlpack/core/tree

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Apr 27 16:02:09 EDT 2012


Author: rcurtin
Date: 2012-04-27 16:02:09 -0400 (Fri, 27 Apr 2012)
New Revision: 12554

Modified:
   mlpack/trunk/src/mlpack/core/tree/binary_space_tree.hpp
   mlpack/trunk/src/mlpack/core/tree/binary_space_tree_impl.hpp
Log:
Add NumChildren() and Child() to BinarySpaceTree for compatibility.


Modified: mlpack/trunk/src/mlpack/core/tree/binary_space_tree.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/binary_space_tree.hpp	2012-04-27 19:52:32 UTC (rev 12553)
+++ mlpack/trunk/src/mlpack/core/tree/binary_space_tree.hpp	2012-04-27 20:02:09 UTC (rev 12554)
@@ -235,15 +235,21 @@
   //! Fills the tree to the specified level.
   size_t ExtendTree(const size_t level);
 
-  /**
-   * Gets the left child of this node.
-   */
+  //! Gets the left child of this node.
   BinarySpaceTree* Left() const;
 
+  //! Gets the right child of this node.
+  BinarySpaceTree* Right() const;
+
+  //! Return the number of children in this node.
+  size_t NumChildren() const;
+
   /**
-   * Gets the right child of this node.
+   * Return the specified child (0 will be left, 1 will be right).
+   *
+   * @param child Index of child to return.
    */
-  BinarySpaceTree* Right() const;
+  BinarySpaceTree* Child(const size_t child) const;
 
   /**
   * Returns the dimension this parent's children are split on.

Modified: mlpack/trunk/src/mlpack/core/tree/binary_space_tree_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/binary_space_tree_impl.hpp	2012-04-27 19:52:32 UTC (rev 12553)
+++ mlpack/trunk/src/mlpack/core/tree/binary_space_tree_impl.hpp	2012-04-27 20:02:09 UTC (rev 12554)
@@ -385,6 +385,37 @@
 }
 
 /**
+ * Returns the number of children in this node.
+ */
+template<typename BoundType, typename StatisticType, typename MatType>
+inline size_t
+    BinarySpaceTree<BoundType, StatisticType, MatType>::NumChildren() const
+{
+  if (left && right)
+    return 2;
+  if (left)
+    return 1;
+
+  return 0;
+}
+
+/**
+ * Return the specified child.
+ */
+template<typename BoundType, typename StatisticType, typename MatType>
+inline BinarySpaceTree<BoundType, StatisticType, MatType>*
+    BinarySpaceTree<BoundType, StatisticType, MatType>::Child(
+    const size_t child) const
+{
+  if (child == 0)
+    return left;
+  else if (child == 1)
+    return right;
+  else
+    return NULL;
+}
+
+/**
  * Gets the index of the begin point of this subset.
  */
 template<typename BoundType, typename StatisticType, typename MatType>




More information about the mlpack-svn mailing list