21 auto index(
const T& value,
const std::vector<T>& values) ->
Index
23 return std::find(values.begin(), values.end(), value) - values.begin();
26 inline auto index(
const std::string& word,
const std::vector<std::string>& strings) ->
Index
28 return index<std::string>(word, strings);
31 template<
typename NamedValues>
32 auto index(
const std::string& name,
const NamedValues& values) ->
Index
35 for(
const auto& value : values)
36 if(value.name() == name)
return idx;
else ++idx;
40 template<
typename NamedValue,
typename NamedValues>
41 auto index(
const NamedValue& value,
const NamedValues& values) ->
Index
43 return index(value.name(), values);
46 template<
typename Names,
typename NamedValues>
49 for(
auto& name :
names)
58 template<
typename NamedValues>
62 idxs.reserve(
names.size());
63 for(
const auto& name :
names)
64 idxs.push_back(
index(name, values));
68 template<
typename NamedValues>
69 auto indices(
const NamedValues& subvalues,
const NamedValues& values) ->
Indices
72 idxs.reserve(subvalues.size());
73 for(
const auto& value : subvalues)
74 idxs.push_back(
index(value, values));
78 inline auto indices(
const std::vector<std::string>& words,
const std::vector<std::string>& strings) ->
Indices
82 for(
const std::string iter : words)
88 template<
typename NamedValues>
89 auto contained(
const std::string& name,
const NamedValues& values) ->
bool
91 return index(name, values) < values.size();
94 template<typename Container, typename = typename std::enable_if<!std::is_same<typename Container::value_type, std::string>::value>::type>
95 auto contained(
const typename Container::value_type& value,
const Container& values) ->
bool
97 return std::count(values.begin(), values.end(), value);
100 template<
typename Container>
101 auto contained(
const Container& values1,
const Container& values2) ->
bool
103 for(
const auto& value : values1)
110 auto unify(
const std::vector<T>& values1,
const std::vector<T>& values2) -> std::vector<T>
114 set.insert(values1.begin(), values1.end());
115 set.insert(values2.begin(), values2.end());
117 return std::vector<T>(set.begin(), set.end());
121 auto intersect(
const std::vector<T>& values1,
const std::vector<T>& values2) -> std::vector<T>
123 std::vector<T> intersection;
125 for(
const T& value : values1)
127 intersection.push_back(value);
133 auto difference(
const std::vector<T>& values1,
const std::vector<T>& values2) -> std::vector<T>
137 for(
const T& value : values1)
139 diff.push_back(value);
147 for(
const T& value : values1)
154 auto emptyDifference(
const std::vector<T>& values1,
const std::vector<T>& values2) ->
bool
156 for(
const T& value : values1)
162 template<
typename Container>
163 auto equal(
const Container& values1,
const Container& values2) ->
bool
165 if(values1.size() != values2.size())
167 for(
const auto& value : values1)
173 template<
typename Container>
176 std::set<Index> tmp(values.begin(), values.end());
177 return tmp.size() == values.size();
181 auto unique(std::vector<T> values) -> std::vector<T>
183 auto it = std::unique(values.begin(), values.end());
185 values.resize(std::distance(values.begin(), it));
191 auto range(T first, T last, T step) -> std::vector<T>
193 unsigned size = unsigned((last - first)/step);
194 std::vector<T>
range(size);
195 for(
unsigned i = 0; i < size; ++i)
196 range[i] = first + i*step;
201 auto range(T first, T last) -> std::vector<T>
203 return range(first, last,
static_cast<T
>(1));
207 auto range(T last) -> std::vector<T>
209 return range(
static_cast<T
>(0), last,
static_cast<T
>(1));
212 template<
typename T,
typename Predicate>
213 auto filter(
const std::vector<T>& values, Predicate predicate) -> std::vector<T>
216 for(
const T& value : values)
218 list.push_back(value);
222 template<
typename T,
typename Predicate>
223 auto remove(
const std::vector<T>& values, Predicate predicate) -> std::vector<T>
226 for(
const T& value : values)
227 if(!predicate(value))
228 list.push_back(value);
235 std::vector<T> extracted_values;
238 extracted_values.push_back(values[idx]);
240 return extracted_values;
243 template<
typename Container>
244 auto minValue(
const Container& values) ->
typename Container::value_type
246 return *std::min_element(values.begin(), values.end());
249 template<
typename Container>
250 auto maxValue(
const Container& values) ->
typename Container::value_type
252 return *std::max_element(values.begin(), values.end());
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