Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R+ and R++ trees implementation #699

Merged
merged 12 commits into from Jul 7, 2016
7 changes: 6 additions & 1 deletion src/mlpack/core/tree/hrectbound.hpp
Expand Up @@ -190,7 +190,12 @@ class HRectBound
/**
* Returns the intersection of this bound and another.
*/
HRectBound Intersect(const HRectBound& bound) const;
HRectBound operator&(const HRectBound& bound) const;

/**
* Intersects this bound with another.
*/
HRectBound& operator&=(const HRectBound& bound);

/**
* Returns the volume of overlap of this bound and another.
Expand Down
26 changes: 25 additions & 1 deletion src/mlpack/core/tree/hrectbound_impl.hpp
Expand Up @@ -435,6 +435,9 @@ inline bool HRectBound<MetricType, ElemType>::Contains(const VecType& point) con
return true;
}

/**
* Determines if this bound partially contains a bound.
*/
template<typename MetricType, typename ElemType>
inline bool HRectBound<MetricType, ElemType>::Contains(
const HRectBound& bound) const
Expand All @@ -451,9 +454,12 @@ inline bool HRectBound<MetricType, ElemType>::Contains(
return true;
}

/**
* Returns the intersection of this bound and another.
*/
template<typename MetricType, typename ElemType>
inline HRectBound<MetricType, ElemType> HRectBound<MetricType, ElemType>::
Intersect(const HRectBound& bound) const
operator&(const HRectBound& bound) const
{
HRectBound<MetricType, ElemType> result(dim);

Expand All @@ -465,6 +471,24 @@ Intersect(const HRectBound& bound) const
return result;
}

/**
* Intersects this bound with another.
*/
template<typename MetricType, typename ElemType>
inline HRectBound<MetricType, ElemType>& HRectBound<MetricType, ElemType>::
operator&=(const HRectBound& bound)
{
for (size_t k = 0; k < dim; k++)
{
bounds[k].Lo() = std::max(bounds[k].Lo(), bound.bounds[k].Lo());
bounds[k].Hi() = std::min(bounds[k].Hi(), bound.bounds[k].Hi());
}
return *this;
}

/**
* Returns the volume of overlap of this bound and another.
*/
template<typename MetricType, typename ElemType>
inline ElemType HRectBound<MetricType, ElemType>::Overlap(
const HRectBound& bound) const
Expand Down