forked from asrivast28/bn-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUintSet.hpp
170 lines (131 loc) · 3.81 KB
/
UintSet.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/**
* @file UintSet.hpp
* @brief Declaration of the UintSet and related classes.
* @author Ankit Srivastava <[email protected]>
*
* Copyright 2020 Georgia Institute of Technology
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef UINTSET_HPP_
#define UINTSET_HPP_
#include "mxx/comm.hpp"
#include <cstdint>
#include <initializer_list>
#include <type_traits>
#include <vector>
/**
* @brief Type trait class for uint_type sets.
*/
template <typename Size>
class UintTypeTrait;
/**
* @brief Computes the number of 64-bit elements that are required
* for safely storing the given datatype.
*/
template <typename Element>
constexpr
int
maxSize();
/**
* @brief STL style interface for the uint_type sets from the SABNAtk library.
*
* @tparam Element Datatype of the value contained by the set.
* @tparam Size Number of 64-bit elements used for storage by the set.
*/
template <typename Element, typename Size = std::integral_constant<int, maxSize<Element>()>>
class UintSet {
static_assert(Size::value <= maxSize<Element>(), "Provided size is bigger than the maximum required");
public:
class Enumerator;
public:
using Impl = typename UintTypeTrait<Size>::Set;
using ReduceType = typename UintTypeTrait<Size>::ArrayType;
// Required typedefs
using value_type = Element;
using iterator = Enumerator;
public:
static
constexpr
Element
capacity();
public:
UintSet(const Element = capacity());
UintSet(const std::initializer_list<Element>&, const Element = capacity());
UintSet(const iterator&, const iterator&, const Element = capacity());
UintSet(const typename std::vector<Element>::iterator&, const typename std::vector<Element>::iterator&, const Element = capacity());
UintSet(const Impl&, const Element = capacity());
const Impl&
operator*() const;
Impl&
operator*();
bool
operator==(const UintSet&) const;
bool
operator!=(const UintSet&) const;
iterator
insert(const Element);
iterator
insert(const iterator&, const Element);
void
erase(const Element);
void
clear();
Element
max() const;
Element
size() const;
bool
empty() const;
bool
contains(const Element) const;
iterator
begin() const;
iterator
end() const;
iterator
find(const Element) const;
UintSet
subset(const std::vector<bool>&) const;
public:
template <typename Set, typename Var>
friend
Set
set_init(Set&&, const Var);
template <typename Set>
friend
void
set_bcast(Set&, const int, const mxx::comm&);
template <typename Set, typename Var>
friend
void
set_bcast(std::vector<std::reference_wrapper<Set>>&, const Var, const int, const mxx::comm&);
template <typename Var, typename Set, template <typename> class Functor, typename RType>
friend
void
uintset_allreduce(Set&, Functor<RType>, const mxx::comm&);
template <typename Var, typename Set, template <typename> class Functor, typename RType>
friend
void
uintset_allreduce_indexed(std::unordered_map<Var, Set>&, const Set&, const Var, Functor<RType>, const mxx::comm&);
template <typename Set, typename Var>
friend
std::vector<Set>
set_allgatherv(const std::vector<Set>&, const std::vector<size_t>&, const Var, const mxx::comm&);
private:
Impl m_set;
Element m_max;
mutable Element m_size;
}; // class UintSet
#include "detail/UintSet.hpp"
#endif // UINTSET_HPP_