Mantid
Loading...
Searching...
No Matches
Subtree.h
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 +
11#pragma once
13
14#include <algorithm>
15
16namespace MantidQt {
17namespace MantidWidgets {
18namespace Batch {
19
20using Subtree = std::vector<Row>;
21
22template <typename RowLocationConstIterator>
23bool hasSubtreeRootShallowerThanFirstRoot(RowLocationConstIterator sortedRegionBegin,
24 RowLocationConstIterator sortedRegionEnd) {
25 auto firstLocationAtMinimumDepth =
26 std::min_element(sortedRegionBegin, sortedRegionEnd, [](RowLocation const &lhs, RowLocation const &rhs) -> bool {
27 return lhs.depth() < rhs.depth();
28 });
29 return firstLocationAtMinimumDepth != sortedRegionBegin;
30}
31
32template <typename RowLocationConstIterator>
33bool allNodesDescendedFromParentOfFirstRoot(RowLocationConstIterator sortedRegionBegin,
34 RowLocationConstIterator sortedRegionEnd) {
35 auto firstRootParent = (*sortedRegionBegin).parent();
36 return std::all_of(sortedRegionBegin + 1, sortedRegionEnd, [&firstRootParent](RowLocation const &location) -> bool {
37 return location.isDescendantOf(firstRootParent);
38 });
39}
40
41template <typename RowLocationConstIterator>
42bool maximumIncreaseInDepthIsOne(RowLocationConstIterator sortedRegionBegin, RowLocationConstIterator sortedRegionEnd) {
43 return std::adjacent_find(sortedRegionBegin, sortedRegionEnd,
44 [](RowLocation const &previous, RowLocation const &current) -> bool {
45 return (previous.depth() - current.depth()) < -1;
46 }) == sortedRegionEnd;
47}
48
49template <typename RowLocationConstIterator>
50bool hasSubtreeRootDeeperThanFirstRoot(int firstSubtreeRootDepth, RowLocationConstIterator sortedRegionBegin,
51 RowLocationConstIterator sortedRegionEnd) {
52 return std::adjacent_find(sortedRegionBegin, sortedRegionEnd,
53 [firstSubtreeRootDepth](RowLocation const &previous, RowLocation const &current) -> bool {
54 return current.depth() > firstSubtreeRootDepth &&
55 !pathsSameUntilDepth(firstSubtreeRootDepth, current, previous);
56 }) != sortedRegionEnd;
57}
58
59template <typename RowLocationConstIterator>
61 RowLocationConstIterator sortedRegionBegin,
62 RowLocationConstIterator sortedRegionEnd) {
63 return allNodesDescendedFromParentOfFirstRoot(sortedRegionBegin, sortedRegionEnd) &&
64 maximumIncreaseInDepthIsOne(sortedRegionBegin, sortedRegionEnd) &&
65 !hasSubtreeRootDeeperThanFirstRoot(subtreeRootDepth, sortedRegionBegin, sortedRegionEnd);
66}
67} // namespace Batch
68} // namespace MantidWidgets
69} // namespace MantidQt
const std::vector< double > & rhs
bool isDescendantOf(RowLocation const &other) const
bool allNodesDescendedFromParentOfFirstRoot(RowLocationConstIterator sortedRegionBegin, RowLocationConstIterator sortedRegionEnd)
Definition Subtree.h:33
bool allSubtreeRootsShareAParentAndAllSubtreeNodesAreConnected(int subtreeRootDepth, RowLocationConstIterator sortedRegionBegin, RowLocationConstIterator sortedRegionEnd)
Definition Subtree.h:60
bool hasSubtreeRootShallowerThanFirstRoot(RowLocationConstIterator sortedRegionBegin, RowLocationConstIterator sortedRegionEnd)
Definition Subtree.h:23
std::vector< Row > Subtree
Definition Subtree.h:20
EXPORT_OPT_MANTIDQT_COMMON bool pathsSameUntilDepth(int depth, RowLocation const &locationA, RowLocation const &locationB)
bool hasSubtreeRootDeeperThanFirstRoot(int firstSubtreeRootDepth, RowLocationConstIterator sortedRegionBegin, RowLocationConstIterator sortedRegionEnd)
Definition Subtree.h:50
bool maximumIncreaseInDepthIsOne(RowLocationConstIterator sortedRegionBegin, RowLocationConstIterator sortedRegionEnd)
Definition Subtree.h:42
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...