Mantid
Loading...
Searching...
No Matches
FindSubtreeRoots.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
9#include <algorithm>
10
12
13auto FindSubtreeRoots::operator()(std::vector<RowLocation> region) -> boost::optional<std::vector<RowLocation>> {
14 std::sort(region.begin(), region.end());
15 if (!region.empty()) {
16 auto subtreeRootDepth = region[0].depth();
17 if (allSubtreeRootsShareAParentAndAllSubtreeNodesAreConnected(subtreeRootDepth, region.cbegin(), region.cend())) {
18 removeIfDepthNotEqualTo(region, subtreeRootDepth);
19 return region;
20 } else {
21 return boost::none;
22 }
23 } else {
24 return std::vector<RowLocation>();
25 }
26}
27
28void FindSubtreeRoots::removeIfDepthNotEqualTo(std::vector<RowLocation> &region, int expectedDepth) const {
29 region.erase(std::remove_if(
30 region.begin(), region.end(),
31 [expectedDepth](RowLocation const &location) -> bool { return location.depth() != expectedDepth; }),
32 region.end());
33}
34
35} // namespace MantidQt::MantidWidgets::Batch
void removeIfDepthNotEqualTo(std::vector< RowLocation > &region, int expectedDepth) const
boost::optional< std::vector< RowLocation > > operator()(std::vector< RowLocation > region)
bool allSubtreeRootsShareAParentAndAllSubtreeNodesAreConnected(int subtreeRootDepth, RowLocationConstIterator sortedRegionBegin, RowLocationConstIterator sortedRegionEnd)
Definition: Subtree.h:58