dyng
DynamicGraphLayout
live_set.h
1 /*
2  Copyright 2020 František Bráblík
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 #pragma once
17 
18 #include <vector>
19 #include <algorithm> // set functions
20 #include <iterator> // set functions
21 
22 namespace dyng {
23 
24 namespace detail {
25 
27 
30 class live_set {
31 public:
32  void add(unsigned time) {
33  m_values.push_back(time);
34  }
35 
36  live_set intersection(const live_set& other) const {
37  live_set result;
38  std::set_intersection(m_values.begin(), m_values.end(),
39  other.m_values.begin(), other.m_values.end(),
40  std::back_inserter(result.m_values));
41  return result;
42  }
43 
44  live_set setunion(const live_set& other) const {
45  live_set result;
46  std::set_union(m_values.begin(), m_values.end(),
47  other.m_values.begin(), other.m_values.end(),
48  std::back_inserter(result.m_values));
49  return result;
50  }
51 
52  // adds all values from other to this
53  void join(const live_set& other) {
54  m_values = setunion(other).m_values;
55  }
56 
57  bool empty() const { return m_values.empty(); }
58 
59 private:
60  std::vector<unsigned> m_values;
61 };
62 
63 } // namespace detail
64 
65 } // namespace dyng
dyng::detail::live_set
Represents a set of all states where a node or an edge exists.
Definition: live_set.h:30