[go: up one dir, main page]

Menu

[19aa1c]: / algo / run_cursor.h  Maximize  Restore  History

Download this file

113 lines (92 with data), 2.3 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
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
#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++;
}
};
#ifdef STXXL_SORT_SINGLE_PREFETCHER
struct have_prefetcher
{
static void * untyped_prefetcher;
};
#endif
template <typename block_type,
typename prefetcher_type_>
struct run_cursor2:public run_cursor<block_type>
#ifdef STXXL_SORT_SINGLE_PREFETCHER
,public have_prefetcher
#endif
{
typedef prefetcher_type_ prefetcher_type;
typedef run_cursor2<block_type,prefetcher_type> _Self;
typedef typename block_type::value_type value_type;
#ifdef STXXL_SORT_SINGLE_PREFETCHER
static prefetcher_type *& prefetcher() // sorry, a hack
{
return (prefetcher_type * &) untyped_prefetcher;
}
run_cursor2 () { }
#else
prefetcher_type * prefetcher_;
prefetcher_type *& prefetcher() // sorry, a hack
{
return prefetcher_;
}
private:
run_cursor2();// intentionally not defined to forbid default construction
public:
run_cursor2(prefetcher_type * p):prefetcher_(p) {}
#endif
inline bool empty () const
{
return (pos >= block_type::size);
};
inline void operator ++ (int);
inline void make_inf ()
{
pos = block_type::size;
};
};
#ifdef STXXL_SORT_SINGLE_PREFETCHER
void * have_prefetcher::untyped_prefetcher = NULL;
#endif
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