STXXL  1.4.1
 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 
21 
22 template <typename BlockType>
23 struct run_cursor
24 {
26  BlockType* buffer;
27 
28  run_cursor() : pos(0), buffer(NULL) { }
29 
30  inline typename BlockType::const_reference current() const
31  {
32  return (*buffer)[pos];
33  }
34  inline void operator ++ ()
35  {
36  ++pos;
37  }
38 };
39 
40 #ifdef STXXL_SORT_SINGLE_PREFETCHER
41 
42 template <typename MustBeVoid = void>
43 struct have_prefetcher
44 {
45  static void* untyped_prefetcher;
46 };
47 
48 #endif
49 
50 template <typename BlockType,
51  typename PrefetcherType>
52 struct run_cursor2 : public run_cursor<BlockType>
53 #ifdef STXXL_SORT_SINGLE_PREFETCHER
54  , public have_prefetcher<>
55 #endif
56 {
57  typedef BlockType block_type;
58  typedef PrefetcherType 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  {
91  assert(!empty());
92  ++pos;
93  if (UNLIKELY(pos >= block_type::size))
94  {
95  if (prefetcher()->block_consumed(buffer))
96  pos = 0;
97  }
98  }
99  inline void make_inf()
100  {
101  pos = block_type::size;
102  }
103 };
104 
105 #ifdef STXXL_SORT_SINGLE_PREFETCHER
106 template <typename MustBeVoid>
107 void* have_prefetcher<MustBeVoid>::untyped_prefetcher = NULL;
108 #endif
109 
110 #if 0
111 template <typename block_type>
112 struct run_cursor_cmp
113 {
114  typedef run_cursor<block_type> cursor_type;
115 
116  inline bool operator () (const cursor_type& a, const cursor_type& b) // greater or equal
117  {
118  return !((*a.buffer)[a.pos] < (*b.buffer)[b.pos]);
119  }
120 };
121 #endif
122 
124 
125 #endif // !STXXL_ALGO_RUN_CURSOR_HEADER
126 // vim: et:ts=4:sw=4
prefetcher_type *& prefetcher()
Definition: run_cursor.h:77
unsigned_type pos
Definition: run_cursor.h:25
bool empty() const
Definition: run_cursor.h:85
uint_pair & operator++()
prefix increment operator (directly manipulates the integer parts)
Definition: uint_types.h:163
block_type::value_type value_type
Definition: run_cursor.h:60
prefetcher_type * prefetcher_
Definition: run_cursor.h:76
BlockType block_type
Definition: run_cursor.h:57
PrefetcherType prefetcher_type
Definition: run_cursor.h:58
#define UNLIKELY(c)
Definition: utils.h:225
run_cursor2< block_type, prefetcher_type > _Self
Definition: run_cursor.h:59
#define STXXL_BEGIN_NAMESPACE
Definition: namespace.h:16
BlockType::const_reference current() const
Definition: run_cursor.h:30
choose_int_types< my_pointer_size >::unsigned_type unsigned_type
Definition: types.h:64
#define STXXL_END_NAMESPACE
Definition: namespace.h:17
BlockType * buffer
Definition: run_cursor.h:26
run_cursor2(prefetcher_type *p=NULL)
Definition: run_cursor.h:82