suanPan
container.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright (C) 2017-2024 Theodore Chang
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  ******************************************************************************/
26 #ifndef CONTAINER_H
27 #define CONTAINER_H
28 
29 #include <suanPan.h>
30 
31 #ifdef SUANPAN_MT
32 #include <oneapi/tbb/concurrent_set.h>
33 #include <oneapi/tbb/concurrent_map.h>
34 #include <oneapi/tbb/concurrent_unordered_set.h>
35 #include <oneapi/tbb/concurrent_unordered_map.h>
36 
37 namespace suanpan {
38  template<typename T> using vector = tbb::concurrent_vector<T>;
39  template<typename T> using set = tbb::concurrent_set<T>;
40  template<typename T> using unordered_set = tbb::concurrent_unordered_set<T, std::hash<T>>;
41  template<typename T, typename D> using map = tbb::concurrent_map<T, D, std::hash<T>>;
42  template<typename T, typename D> using unordered_map = tbb::concurrent_unordered_map<T, D, std::hash<T>>;
43 
44  template<typename T> using graph = vector<set<T>>;
45 }
46 #else
47 #include <set>
48 #include <map>
49 #include <unordered_set>
50 #include <unordered_map>
51 
52 namespace suanpan {
53  template<typename T> using vector = std::vector<T>;
54  template<typename T> using set = std::set<T>;
55  template<typename T> using unordered_set = std::unordered_set<T>;
56  template<typename T, typename D> using map = std::map<T, D>;
57  template<typename T, typename D> using unordered_map = std::unordered_map<T, D>;
58 
59  template<typename T> using graph = vector<set<T>>;
60 }
61 #endif
62 
63 template<sp_i T> uvec to_uvec(const suanpan::set<T>& in) {
64  uvec out(in.size(), fill::none);
65  auto I = 0llu;
66  for(const auto J : in) out(I++) = static_cast<uword>(J);
67  return out;
68 }
69 
70 template<sp_i T> uvec to_uvec(const suanpan::unordered_set<T>& in) {
71  uvec out(in.size(), fill::none);
72  auto I = 0llu;
73  for(const auto J : in) out(I++) = static_cast<uword>(J);
74  return out;
75 }
76 
77 #endif
78 
uvec to_uvec(const suanpan::set< T > &in)
Definition: container.h:63
Definition: MatrixModifier.hpp:36
std::vector< T > vector
Definition: container.h:53
std::unordered_set< T > unordered_set
Definition: container.h:55
vector< set< T > > graph
Definition: container.h:59
std::unordered_map< T, D > unordered_map
Definition: container.h:57
std::set< T > set
Definition: container.h:54
std::map< T, D > map
Definition: container.h:56