[go: up one dir, main page]

Menu

[5a71d8]: / algo / run_cursor.h  Maximize  Restore  History

Download this file

95 lines (74 with data), 1.9 kB

 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef RUN_CURSOR_HEADER
#define RUN_CURSOR_HEADER
/***************************************************************************
* run_cursor.h
*
* Mon Jan 20 10:38:01 2003
* Copyright 2003 Roman Dementiev
* dementiev@mpi-sb.mpg.de
****************************************************************************/
#include "../common/utils.h"
__STXXL_BEGIN_NAMESPACE
template <typename block_type>
struct run_cursor
{
unsigned int pos;
block_type *buffer;
inline const typename block_type::type & current () const
{
return (*buffer)[pos];
}
inline void operator ++ (int)
{
pos++;
}
};
struct have_prefetcher
{
static void * untyped_prefetcher;
};
template <typename block_type,
typename prefetcher_type_>
struct run_cursor2:public run_cursor<block_type>,public have_prefetcher
{
typedef prefetcher_type_ prefetcher_type;
typedef run_cursor2<block_type,prefetcher_type> _Self;
typedef typename block_type::value_type value_type;
static prefetcher_type *& prefetcher() // sorry, a hack
{
return (prefetcher_type * &) untyped_prefetcher;
};
run_cursor2 () { };
inline bool empty () const
{
return (pos >= block_type::size);
};
inline void operator ++ (int);
inline void make_inf ()
{
pos = block_type::size;
};
};
void * have_prefetcher::untyped_prefetcher = NULL;
template <typename block_type,
typename prefetcher_type>
void
run_cursor2<block_type,prefetcher_type>::operator ++ (int)
{
pos++;
if (UNLIKELY(pos >= block_type::size))
{
if( prefetcher()->block_consumed(buffer) ) pos = 0;
}
};
template <typename block_type>
struct run_cursor_cmp
{
typedef run_cursor<block_type> cursor_type;
inline bool operator () (const cursor_type & a, const cursor_type & b) // greater or equal
{
return !((*a.buffer)[a.pos] < (*b.buffer)[b.pos]);
};
};
__STXXL_END_NAMESPACE
#endif