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-2015 Allan Leal
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program 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
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. 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 
29 namespace Reaktoro {
30 
32 template<typename T>
33 auto index(const T& value, const std::vector<T>& values) -> Index;
34 
36 auto index(const std::string& word, const std::vector<std::string>& strings) -> Index;
37 
39 template<typename NamedValues>
40 auto index(const std::string& name, const NamedValues& values) -> Index;
41 
43 template<typename NamedValue, typename NamedValues>
44 auto index(const NamedValue& value, const NamedValues& values) -> Index;
45 
47 template<typename Names, typename NamedValues>
48 auto indexAny(const Names& names, const NamedValues& values) -> Index;
49 
51 template<typename NamedValues>
52 auto indices(const std::vector<std::string>& names, const NamedValues& values) -> Indices;
53 
55 template<typename NamedValues>
56 auto indices(const NamedValues& subvalues, const NamedValues& values) -> Indices;
57 
59 auto indices(const std::vector<std::string>& words, const std::vector<std::string>& strings) -> Indices;
60 
62 template<typename Container>
63 auto contained(const typename Container::value_type& value, const Container& values) -> bool;
64 
66 template<typename Container>
67 auto contained(const Container& values1, const Container& values2) -> bool;
68 
70 template<typename NamedValues>
71 auto contained(const std::string& name, const NamedValues& values) -> bool;
72 
74 template<typename T>
75 auto unify(const std::vector<T>& values1, const std::vector<T>& values2) -> std::vector<T>;
76 
78 template<typename T>
79 auto intersect(const std::vector<T>& values1, const std::vector<T>& values2) -> std::vector<T>;
80 
82 template<typename T>
83 auto difference(const std::vector<T>& values1, const std::vector<T>& values2) -> std::vector<T>;
84 
86 template<typename T>
87 auto emptyIntersection(const std::vector<T>& values1, const std::vector<T>& values2) -> bool;
88 
90 template<typename T>
91 auto emptyDifference(const std::vector<T>& values1, const std::vector<T>& values2) -> bool;
92 
94 template<typename Container>
95 auto equal(const Container& values1, const Container& values2) -> bool;
96 
98 template<typename Container>
99 auto isunique(Container values) -> bool;
100 
102 template<typename T>
103 auto unique(std::vector<T> values) -> std::vector<T>;
104 
109 template<typename T>
110 auto range(T first, T last, T step) -> std::vector<T>;
111 
115 template<typename T>
116 auto range(T first, T last) -> std::vector<T>;
117 
120 template<typename T>
121 auto range(T last) -> std::vector<T>;
122 
124 template<typename T, typename Predicate>
125 auto filter(const std::vector<T>& values, Predicate predicate) -> std::vector<T>;
126 
128 template<typename T, typename Predicate>
129 auto remove(const std::vector<T>& values, Predicate predicate) -> std::vector<T>;
130 
135 template<typename T>
136 auto extract(const std::vector<T>& values, const Indices& indices) -> std::vector<T>;
137 
139 template<typename Container>
140 auto min(const Container& values) -> typename Container::value_type;
141 
143 template<typename Container>
144 auto max(const Container& values) -> typename Container::value_type;
145 
146 } // namespace Reaktoro
147 
148 #include <Reaktoro/Common/SetUtils.hxx>
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
std::vector< Index > Indices
Define a type that represents a collection of indices.
Definition: Index.hpp:29
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 filter(const std::vector< T > &values, Predicate predicate) -> std::vector< T >
Filter the values that pass on the predicate.
Definition: SetUtils.hxx:213
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 intersect(const std::vector< T > &values1, const std::vector< T > &values2) -> std::vector< T >
Determine the intersection of two containers.
Definition: SetUtils.hxx:121
auto unique(std::vector< T > values) -> std::vector< T >
Create a container with unique values from another.
Definition: SetUtils.hxx:181
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 equal(const Container &values1, const Container &values2) -> bool
Check if two containers are equal.
Definition: SetUtils.hxx:163
std::size_t Index
Define a type that represents an index.
Definition: Index.hpp:26
auto range(T first, T last, T step) -> std::vector< T >
Return a range of values.
Definition: SetUtils.hxx:191
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 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 emptyIntersection(const std::vector< T > &values1, const std::vector< T > &values2) -> bool
Check if two containers have empty intersection.
Definition: SetUtils.hxx:145
auto contained(const typename Container::value_type &value, const Container &values) -> bool
Check if a value is contained in a container of values.
Definition: SetUtils.hxx:95
The namespace containing all components of the Reaktoro library.
Definition: ChemicalScalar.hpp:24
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 isunique(Container values) -> bool
Check if a container has unique values.
Definition: SetUtils.hxx:174