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