www.cemf.ir
VectorAlgorithm.hpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 
22 namespace pFlow
23 {
24 
25 template<typename T, typename Allocator>
26 inline auto count(const Vector<T, Allocator>& vec, const T& val)
27 {
28  return std::count(vec.begin(), vec.end(), val);
29 }
30 
31 template<typename T, typename Allocator, typename UnaryPredicate>
32 inline auto count_if(const Vector<T, Allocator>& vec, UnaryPredicate p)
33 {
34  return std::count_if(vec.begin(), vec.end(), p);
35 }
36 
37 template<typename T, typename Allocator>
38 inline void fill_n(Vector<T, Allocator>& vec, size_t n, const T& val)
39 {
40  std::fill_n(vec.begin(), n, val);
41 }
42 
43 template<typename T, typename Allocator>
44 inline void fill(Vector<T, Allocator>& vec, const T& val)
45 {
46  std::fill(vec.begin(), vec.end(), val);
47 }
48 
49 template<typename T, typename Allocator>
50 inline void fillSequence(Vector<T, Allocator>& vec, int32 start, int32 end, const T& startVal)
51 {
52  pFlow::algorithms::STD::fillSequence<T, false>(vec.data()+start, end-start, startVal);
53 }
54 
55 template<typename T, typename Allocator>
56 inline void fillSequence(Vector<T, Allocator>& vec, const T& startVal)
57 {
58  pFlow::fillSequence(vec, 0, vec.size(), startVal);
59 }
60 
61 template<typename T, typename Allocator>
62 inline void sort(Vector<T, Allocator>& vec)
63 {
64  std::sort(vec.begin(), vec.end());
65 }
66 
67 
68 template<typename T, typename Allocator>
69 inline int64 find(Vector<T, Allocator>& vec, const T& val)
70 {
71  ForAll( i,vec)
72  {
73  if ( vec[i] == val) return static_cast<int64>(i);
74  }
75  return -1;
76 }
77 
78 
79 } // pFlow
80 
count
auto count(const Vector< T, Allocator > &vec, const T &val)
pFlow::fill
void fill(Vector< T, Allocator > &vec, const T &val)
Definition: VectorAlgorithm.hpp:44
pFlow::count_if
auto count_if(const Vector< T, Allocator > &vec, UnaryPredicate p)
Definition: VectorAlgorithm.hpp:32
pFlow::find
int64 find(Vector< T, Allocator > &vec, const T &val)
Definition: VectorAlgorithm.hpp:69
count_if
auto count_if(const Vector< T, Allocator > &vec, UnaryPredicate p)
pFlow::int64
long long int int64
Definition: builtinTypes.hpp:52
pFlow::Vector::size
auto size() const
Size of the vector.
Definition: Vector.hpp:265
pFlow
Definition: demGeometry.hpp:27
fill_n
void fill_n(Vector< T, Allocator > &vec, size_t n, const T &val)
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:75
fill
void fill(Vector< T, Allocator > &vec, const T &val)
pFlow::count
auto count(const Vector< T, Allocator > &vec, const T &val)
Definition: VectorAlgorithm.hpp:26
sort
void sort(Vector< T, Allocator > &vec)
n
uint32 n
Definition: NBSLoop.hpp:24
pFlow::sort
void sort(Vector< T, Allocator > &vec)
Definition: VectorAlgorithm.hpp:62
pFlow::fillSequence
void fillSequence(internalField< T, MemorySpace > &iField, const T &startVal)
Definition: internalFieldAlgorithms.hpp:198
pFlow::Vector
Definition: Vector.hpp:48
pFlow::fill_n
void fill_n(Vector< T, Allocator > &vec, size_t n, const T &val)
Definition: VectorAlgorithm.hpp:38