Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
interval_tree.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 Stanford University, NVIDIA Corporation
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18// templated interval tree
19
20#ifndef REALM_INTERVAL_TREE_H
21#define REALM_INTERVAL_TREE_H
22
23#include <vector>
24#include <set>
25
26namespace Realm {
27
28 template <typename IT, typename LT>
30 public:
33
34 bool empty(void) const;
35 size_t size(void) const;
36
37 void add_interval(IT iv_start, IT iv_end, LT iv_label, bool defer = true);
38
39 template <typename IR>
40 void add_intervals(const IR &iv_ranges, LT iv_label, bool defer = true);
41
42 void remove_interval(IT iv_start, IT iv_end, LT iv_label);
43
44 template <typename IR>
45 void remove_intervals(const IR &iv_ranges, LT iv_label);
46
47 void remove_by_label(LT iv_label);
48
49 void construct_tree(bool rebuild_completely = false);
50
51 template <typename MARKER>
52 void test_interval(IT iv_start, IT iv_end, MARKER &marker) const;
53
54 void test_interval(IT iv_start, IT iv_end, std::vector<bool> &labels_found) const;
55 void test_interval(IT iv_start, IT iv_end, std::set<LT> &labels_found) const;
56
57 template <typename IR, typename MARKER>
58 void test_intervals(const IR &iv_ranges, MARKER &marker) const;
59
60 template <typename IR>
61 void test_intervals(const IR &iv_ranges, std::vector<bool> &labels_found) const;
62
63 template <typename IR>
64 void test_intervals(const IR &iv_ranges, std::set<LT> &labels_found) const;
65
66 template <typename IR, typename MARKER>
67 void test_sorted_intervals(const IR &iv_ranges, MARKER &marker) const;
68
69 template <typename IR>
70 void test_sorted_intervals(const IR &iv_ranges,
71 std::vector<bool> &labels_found) const;
72
73 template <typename IR>
74 void test_sorted_intervals(const IR &iv_ranges, std::set<LT> &labels_found) const;
75
76 struct TreeNode {
79 std::vector<IT> starts, ends;
80 std::vector<LT> labels;
81 std::vector<int> sorted_by_start, sorted_by_end;
82
83 TreeNode(IT _split_val);
84 ~TreeNode(void);
85
86 static TreeNode *build_tree(const std::vector<IT> &pending_starts,
87 const std::vector<IT> &pending_ends,
88 const std::vector<LT> &pending_labels);
89
90 template <typename MARKER>
91 void test_interval(IT iv_start, IT iv_end, MARKER &marker) const;
92
93 template <typename IR, typename MARKER>
94 void test_sorted_intervals(const IR &iv_ranges, int pos, int count,
95 MARKER &marker) const;
96
98 };
99
100 protected:
101 std::vector<IT> pending_starts, pending_ends;
102 std::vector<LT> pending_labels;
104 size_t count;
105 };
106
107}; // namespace Realm
108
109#include "realm/interval_tree.inl"
110
111#endif // ifndef REALM_INTERVAL_TREE_H
Definition interval_tree.h:29
void test_sorted_intervals(const IR &iv_ranges, MARKER &marker) const
std::vector< IT > pending_starts
Definition interval_tree.h:101
void add_interval(IT iv_start, IT iv_end, LT iv_label, bool defer=true)
void test_sorted_intervals(const IR &iv_ranges, std::set< LT > &labels_found) const
void test_interval(IT iv_start, IT iv_end, MARKER &marker) const
void test_intervals(const IR &iv_ranges, MARKER &marker) const
void test_interval(IT iv_start, IT iv_end, std::set< LT > &labels_found) const
void test_interval(IT iv_start, IT iv_end, std::vector< bool > &labels_found) const
bool empty(void) const
void test_intervals(const IR &iv_ranges, std::vector< bool > &labels_found) const
void remove_intervals(const IR &iv_ranges, LT iv_label)
size_t count
Definition interval_tree.h:104
void construct_tree(bool rebuild_completely=false)
std::vector< LT > pending_labels
Definition interval_tree.h:102
void remove_by_label(LT iv_label)
std::vector< IT > pending_ends
Definition interval_tree.h:101
void test_intervals(const IR &iv_ranges, std::set< LT > &labels_found) const
void test_sorted_intervals(const IR &iv_ranges, std::vector< bool > &labels_found) const
void remove_interval(IT iv_start, IT iv_end, LT iv_label)
TreeNode * root
Definition interval_tree.h:103
size_t size(void) const
void add_intervals(const IR &iv_ranges, LT iv_label, bool defer=true)
Definition activemsg.h:38
Definition interval_tree.h:76
static TreeNode * build_tree(const std::vector< IT > &pending_starts, const std::vector< IT > &pending_ends, const std::vector< LT > &pending_labels)
std::vector< int > sorted_by_start
Definition interval_tree.h:81
void test_sorted_intervals(const IR &iv_ranges, int pos, int count, MARKER &marker) const
TreeNode * left
Definition interval_tree.h:78
TreeNode * right
Definition interval_tree.h:78
std::vector< IT > starts
Definition interval_tree.h:79
std::vector< IT > ends
Definition interval_tree.h:79
void test_interval(IT iv_start, IT iv_end, MARKER &marker) const
void repopulate_pending(IntervalTree< IT, LT > *tree)
std::vector< int > sorted_by_end
Definition interval_tree.h:81
IT split_val
Definition interval_tree.h:77
std::vector< LT > labels
Definition interval_tree.h:80