Loading...
Searching...
No Matches
Serial-Impl.hpp
Go to the documentation of this file.
1// This code is based on Jet framework.
2// Copyright (c) 2018 Doyub Kim
3// CubbyFlow is voxel-based fluid simulation engine for computer games.
4// Copyright (c) 2020 CubbyFlow Team
5// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6// AI Part: Dongheon Cho, Minseo Kim
7// We are making my contributions/submissions to this project solely in our
8// personal capacity and are not conveying any rights to any intellectual
9// property of any third parties.
10
11#ifndef CUBBYFLOW_SERIAL_IMPL_HPP
12#define CUBBYFLOW_SERIAL_IMPL_HPP
13
14#include <algorithm>
15#include <functional>
16
17namespace CubbyFlow
18{
19template <typename RandomIterator, typename T>
20void SerialFill(const RandomIterator& begin, const RandomIterator& end,
21 const T& value)
22{
23 size_t size = static_cast<size_t>(end - begin);
24
25 SerialFor(static_cast<size_t>(0), size,
26 [begin, value](size_t i) { begin[i] = value; });
27}
28
29template <typename IndexType, typename Function>
31 const Function& function)
32{
33 for (IndexType i = beginIndex; i < endIndex; ++i)
34 {
35 function(i);
36 }
37}
38
39template <typename IndexType, typename Function>
42 const Function& function)
43{
44 for (IndexType j = beginIndexY; j < endIndexY; ++j)
45 {
46 for (IndexType i = beginIndexX; i < endIndexX; ++i)
47 {
48 function(i, j);
49 }
50 }
51}
52
53template <typename IndexType, typename Function>
57 const Function& function)
58{
59 for (IndexType k = beginIndexZ; k < endIndexZ; ++k)
60 {
61 for (IndexType j = beginIndexY; j < endIndexY; ++j)
62 {
63 for (IndexType i = beginIndexX; i < endIndexX; ++i)
64 {
65 function(i, j, k);
66 }
67 }
68 }
69}
70
71template <typename RandomIterator>
73{
74 SerialSort(begin, end, std::less<typename RandomIterator::value_type>());
75}
76
77template <typename RandomIterator, typename SortingFunction>
80{
81 std::sort(begin, end, sortingFunction);
82}
83} // namespace CubbyFlow
84
85#endif
Definition Matrix.hpp:30
Definition pybind11Utils.hpp:21
void SerialSort(RandomIterator begin, RandomIterator end)
Sorts a container.
Definition Serial-Impl.hpp:72
void SerialFill(const RandomIterator &begin, const RandomIterator &end, const T &value)
Fills from begin to end with value.
Definition Serial-Impl.hpp:20
Matrix< T, Rows, 1 > Vector
Definition Matrix.hpp:738
void SerialFor(IndexType beginIndex, IndexType endIndex, const Function &function)
Makes a for-loop from beginIndex to endIndex.
Definition Serial-Impl.hpp:30