STXXL  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
run_cursor.h
Go to the documentation of this file.
1 /***************************************************************************
2  * include/stxxl/bits/algo/run_cursor.h
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  * Copyright (C) 2003 Roman Dementiev <[email protected]>
7  * Copyright (C) 2009 Andreas Beckmann <[email protected]>
8  *
9  * Distributed under the Boost Software License, Version 1.0.
10  * (See accompanying file LICENSE_1_0.txt or copy at
11  * http://www.boost.org/LICENSE_1_0.txt)
12  **************************************************************************/
13 
14 #ifndef STXXL_ALGO_RUN_CURSOR_HEADER
15 #define STXXL_ALGO_RUN_CURSOR_HEADER
16 
17 #include <cstdlib>
19 
20 
22 
23 template <typename block_type>
24 struct run_cursor
25 {
27  block_type* buffer;
28 
29  run_cursor() : pos(0), buffer(NULL) { }
30 
31  inline typename block_type::const_reference current() const
32  {
33  return (*buffer)[pos];
34  }
35  inline void operator ++ ()
36  {
37  ++pos;
38  }
39 };
40 
41 #ifdef STXXL_SORT_SINGLE_PREFETCHER
42 
43 template <typename must_be_void = void>
44 struct have_prefetcher
45 {
46  static void* untyped_prefetcher;
47 };
48 
49 #endif
50 
51 template <typename block_type,
52  typename prefetcher_type_>
53 struct run_cursor2 : public run_cursor<block_type>
54 #ifdef STXXL_SORT_SINGLE_PREFETCHER
55  , public have_prefetcher<>
56 #endif
57 {
58  typedef prefetcher_type_ prefetcher_type;
60  typedef typename block_type::value_type value_type;
61 
64 
65 #ifdef STXXL_SORT_SINGLE_PREFETCHER
66  static prefetcher_type* const prefetcher() // sorry, a hack
67  {
68  return reinterpret_cast<prefetcher_type*>(untyped_prefetcher);
69  }
70  static void set_prefetcher(prefetcher_type* pfptr)
71  {
72  untyped_prefetcher = pfptr;
73  }
74  run_cursor2() { }
75 #else
77  prefetcher_type* & prefetcher() // sorry, a hack
78  {
79  return prefetcher_;
80  }
81 
82  run_cursor2(prefetcher_type* p = NULL) : prefetcher_(p) { }
83 #endif
84 
85  inline bool empty() const
86  {
87  return (pos >= block_type::size);
88  }
89  inline void operator ++ ();
90  inline void make_inf()
91  {
92  pos = block_type::size;
93  }
94 };
95 
96 #ifdef STXXL_SORT_SINGLE_PREFETCHER
97 template <typename must_be_void>
98 void* have_prefetcher<must_be_void>::untyped_prefetcher = NULL;
99 #endif
100 
101 template <typename block_type,
102  typename prefetcher_type>
104 {
105  assert(!empty());
106  ++pos;
107  if (UNLIKELY(pos >= block_type::size))
108  {
109  if (prefetcher()->block_consumed(buffer))
110  pos = 0;
111  }
112 }
113 
114 
115 #if 0
116 template <typename block_type>
117 struct run_cursor_cmp
118 {
119  typedef run_cursor<block_type> cursor_type;
120 
121  inline bool operator () (const cursor_type& a, const cursor_type& b) // greater or equal
122  {
123  return !((*a.buffer)[a.pos] < (*b.buffer)[b.pos]);
124  }
125 };
126 #endif
127 
129 
130 
131 #endif // !STXXL_ALGO_RUN_CURSOR_HEADER
132 // vim: et:ts=4:sw=4
block_type * buffer
Definition: run_cursor.h:27
prefetcher_type_ prefetcher_type
Definition: run_cursor.h:58
block_type::const_reference current() const
Definition: run_cursor.h:31
uint_pair & operator++()
prefix increment operator (directly manipulates the integer parts)
Definition: uint_types.h:166
prefetcher_type *& prefetcher()
Definition: run_cursor.h:77
run_cursor2(prefetcher_type *p=NULL)
Definition: run_cursor.h:82
run_cursor2< block_type, prefetcher_type > _Self
Definition: run_cursor.h:59
#define UNLIKELY(c)
Definition: utils.h:226
#define STXXL_BEGIN_NAMESPACE
Definition: namespace.h:16
prefetcher_type * prefetcher_
Definition: run_cursor.h:76
choose_int_types< my_pointer_size >::unsigned_type unsigned_type
Definition: types.h:67
unsigned_type pos
Definition: run_cursor.h:26
block_type::value_type value_type
Definition: run_cursor.h:60
#define STXXL_END_NAMESPACE
Definition: namespace.h:17
bool empty() const
Definition: run_cursor.h:85