Reaktoro
A unified framework for modeling chemically reactive systems
SetUtils.hpp
1 // Reaktoro is a unified framework for modeling chemically reactive systems.
2 //
3 // Copyright (C) 2014-2018 Allan Leal
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library. If not, see <http://www.gnu.org/licenses/>.
17 
18 #pragma once
19 
20 // C++ includes
21 #include <algorithm>
22 #include <set>
23 #include <vector>
24 #include <string>
25 
26 // Reaktoro includes
27 #include <Reaktoro/Common/Index.hpp>
28 #include <Reaktoro/Common/TraitsUtils.hpp>
29 
30 namespace Reaktoro {
31 
33 template<typename T>
34 auto index(const T& value, const std::vector<T>& values) -> Index;
35 
37 auto index(const std::string& word, const std::vector<std::string>& strings) -> Index;
38 
40 template<typename NamedValues>
41 auto index(const std::string& name, const NamedValues& values) -> Index;
42 
44 template<typename NamedValue, typename NamedValues>
45 auto index(const NamedValue& value, const NamedValues& values) -> Index;
46 
48 template<typename Names, typename NamedValues>
49 auto indexAny(const Names& names, const NamedValues& values) -> Index;
50 
52 template<typename NamedValues>
53 auto indices(const std::vector<std::string>& names, const NamedValues& values) -> Indices;
54 
56 template<typename NamedValues>
57 auto indices(const NamedValues& subvalues, const NamedValues& values) -> Indices;
58 
60 auto indices(const std::vector<std::string>& words, const std::vector<std::string>& strings) -> Indices;
61 
63 //template<typename Container, typename = typename std::enable_if<!std::is_same<typename Container::value_type, std::string>::value>::type>
64 //auto contained(const typename Container::value_type& value, const Container& values) -> bool;
65 
67 template<typename Container>
68 auto contained(const Container& values1, const Container& values2) -> bool;
69 
71 template<typename NamedValues>
72 auto contained(const std::string& name, const NamedValues& values) -> bool;
73 
75 template<typename T>
76 auto unify(const std::vector<T>& values1, const std::vector<T>& values2) -> std::vector<T>;
77 
79 template<typename T>
80 auto intersect(const std::vector<T>& values1, const std::vector<T>& values2) -> std::vector<T>;
81 
83 template<typename T>
84 auto difference(const std::vector<T>& values1, const std::vector<T>& values2) -> std::vector<T>;
85 
87 template<typename T>
88 auto emptyIntersection(const std::vector<T>& values1, const std::vector<T>& values2) -> bool;
89 
91 template<typename T>
92 auto emptyDifference(const std::vector<T>& values1, const std::vector<T>& values2) -> bool;
93 
95 template<typename Container>
96 auto equal(const Container& values1, const Container& values2) -> bool;
97 
99 template<typename Container>
100 auto isunique(Container values) -> bool;
101 
103 template<typename T>
104 auto unique(std::vector<T> values) -> std::vector<T>;
105 
110 template<typename T>
111 auto range(T first, T last, T step) -> std::vector<T>;
112 
116 template<typename T>
117 auto range(T first, T last) -> std::vector<T>;
118 
121 template<typename T>
122 auto range(T last) -> std::vector<T>;
123 
125 template<typename T, typename Predicate>
126 auto filter(const std::vector<T>& values, Predicate predicate) -> std::vector<T>;
127 
129 template<typename T, typename Predicate>
130 auto remove(const std::vector<T>& values, Predicate predicate) -> std::vector<T>;
131 
136 template<typename T>
137 auto extract(const std::vector<T>& values, const Indices& indices) -> std::vector<T>;
138 
140 template<typename Container>
141 auto minValue(const Container& values) -> typename Container::value_type;
142 
144 template<typename Container>
145 auto maxValue(const Container& values) -> typename Container::value_type;
146 
147 } // namespace Reaktoro
148 
149 #include <Reaktoro/Common/SetUtils.hxx>
auto indices(const std::vector< std::string > &names, const NamedValues &values) -> Indices
Return the indices of some entries in a container.
Definition: SetUtils.hxx:59
auto index(const T &value, const std::vector< T > &values) -> Index
Find the index of a value in a container of values.
Definition: SetUtils.hxx:21
auto names(const NamedValues &values) -> std::vector< std::string >
Return the names of the entries in a container.
Definition: Utils.hxx:22
auto extract(const std::vector< T > &values, const Indices &indices) -> std::vector< T >
Extract values from a vector given a list of indices.
Definition: SetUtils.hxx:233
auto unify(const std::vector< T > &values1, const std::vector< T > &values2) -> std::vector< T >
Determine the union of two containers.
Definition: SetUtils.hxx:110
auto equal(const Container &values1, const Container &values2) -> bool
Check if two containers are equal.
Definition: SetUtils.hxx:163
auto emptyDifference(const std::vector< T > &values1, const std::vector< T > &values2) -> bool
Check if two containers have empty difference.
Definition: SetUtils.hxx:154
auto indexAny(const Names &names, const NamedValues &values) -> Index
Return the index of the first entry in a container of named values with any of the given names.
Definition: SetUtils.hxx:47
auto emptyIntersection(const std::vector< T > &values1, const std::vector< T > &values2) -> bool
Check if two containers have empty intersection.
Definition: SetUtils.hxx:145
auto minValue(const Container &values) -> typename Container::value_type
Return the minimum value in a STL compatible container.
Definition: SetUtils.hxx:244
auto range(T first, T last, T step) -> std::vector< T >
Return a range of values.
Definition: SetUtils.hxx:191
auto filter(const std::vector< T > &values, Predicate predicate) -> std::vector< T >
Filter the values that pass on the predicate.
Definition: SetUtils.hxx:213
The namespace containing all components of the Reaktoro library.
Definition: ChemicalScalar.hpp:24
auto difference(const std::vector< T > &values1, const std::vector< T > &values2) -> std::vector< T >
Determine the difference of two containers.
Definition: SetUtils.hxx:133
auto isunique(Container values) -> bool
Check if a container has unique values.
Definition: SetUtils.hxx:174
std::size_t Index
Define a type that represents an index.
Definition: Index.hpp:26
std::vector< Index > Indices
Define a type that represents a collection of indices.
Definition: Index.hpp:29
auto contained(const Container &values1, const Container &values2) -> bool
Check if a value is contained in a container of values.
Definition: SetUtils.hxx:101
auto remove(const std::vector< T > &values, Predicate predicate) -> std::vector< T >
Remove the values that pass on the predicate.
Definition: SetUtils.hxx:223
auto maxValue(const Container &values) -> typename Container::value_type
Return the maximum value in a STL compatible container.
Definition: SetUtils.hxx:250
auto unique(std::vector< T > values) -> std::vector< T >
Create a container with unique values from another.
Definition: SetUtils.hxx:181
auto intersect(const std::vector< T > &values1, const std::vector< T > &values2) -> std::vector< T >
Determine the intersection of two containers.
Definition: SetUtils.hxx:121