forked from ot/emphf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinternal_memory_model.hpp
79 lines (64 loc) · 2.16 KB
/
internal_memory_model.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once
#include <vector>
#include <algorithm>
namespace emphf {
struct internal_memory_model {
template <typename T>
using vector = std::vector<T>;
template <typename T>
vector<T> make_vector(T const&) const
{
return vector<T>();
}
// for internal memory model, this is just a wrapper for an
// already sorted range
template <typename Iterator,
typename KeyFunctor,
typename PartitionFunctor>
struct sorter {
typedef typename std::iterator_traits<Iterator>::value_type value_type;
typedef Iterator iterator;
sorter(Iterator begin, Iterator end,
KeyFunctor const&,
PartitionFunctor const&)
: m_begin(begin)
, m_end(end)
{}
iterator begin() const
{
return m_begin;
}
iterator end() const
{
return m_end;
}
private:
iterator m_begin;
iterator m_end;
};
template <typename Iterator,
typename KeyFunctor,
typename PartitionFunctor>
sorter<Iterator, KeyFunctor, PartitionFunctor>
make_sorter(Iterator begin, Iterator end,
KeyFunctor const& kf,
PartitionFunctor const& pf) const
{
typedef typename std::iterator_traits<Iterator>::value_type value_type;
std::sort(begin, end,
[&](value_type const& lhs, value_type const& rhs) {
return kf(lhs) < kf(rhs);
});
return sorter<Iterator, KeyFunctor, PartitionFunctor>(begin, end, kf, pf);
}
template <typename Iterator,
typename KeyFunctor,
typename PartitionFunctor>
void sort(Iterator begin, Iterator end,
KeyFunctor const& kf,
PartitionFunctor const& pf) const
{
auto s = make_sorter(begin, end, kf, pf);
}
};
}