00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef STXXL_RUN_CURSOR_HEADER
00015 #define STXXL_RUN_CURSOR_HEADER
00016
00017 #include <cstdlib>
00018 #include <stxxl/bits/common/types.h>
00019
00020
00021 __STXXL_BEGIN_NAMESPACE
00022
00023 template <typename block_type>
00024 struct run_cursor
00025 {
00026 unsigned_type pos;
00027 block_type * buffer;
00028
00029 run_cursor() : pos(0), buffer(NULL) { }
00030
00031 inline typename block_type::const_reference current() const
00032 {
00033 return (*buffer)[pos];
00034 }
00035 inline void operator ++ ()
00036 {
00037 ++pos;
00038 }
00039 };
00040
00041 #ifdef STXXL_SORT_SINGLE_PREFETCHER
00042
00043 template <typename must_be_void = void>
00044 struct have_prefetcher
00045 {
00046 static void * untyped_prefetcher;
00047 };
00048
00049 #endif
00050
00051 template <typename block_type,
00052 typename prefetcher_type_>
00053 struct run_cursor2 : public run_cursor<block_type>
00054 #ifdef STXXL_SORT_SINGLE_PREFETCHER
00055 , public have_prefetcher<>
00056 #endif
00057 {
00058 typedef prefetcher_type_ prefetcher_type;
00059 typedef run_cursor2<block_type, prefetcher_type> _Self;
00060 typedef typename block_type::value_type value_type;
00061
00062 using run_cursor<block_type>::pos;
00063 using run_cursor<block_type>::buffer;
00064
00065 #ifdef STXXL_SORT_SINGLE_PREFETCHER
00066 static prefetcher_type * const prefetcher()
00067 {
00068 return reinterpret_cast<prefetcher_type *>(untyped_prefetcher);
00069 }
00070 static void set_prefetcher(prefetcher_type * pfptr)
00071 {
00072 untyped_prefetcher = pfptr;
00073 }
00074 run_cursor2() { }
00075 #else
00076 prefetcher_type * prefetcher_;
00077 prefetcher_type * & prefetcher()
00078 {
00079 return prefetcher_;
00080 }
00081
00082 run_cursor2() { }
00083 run_cursor2(prefetcher_type * p) : prefetcher_(p) { }
00084 #endif
00085
00086 inline bool empty() const
00087 {
00088 return (pos >= block_type::size);
00089 }
00090 inline void operator ++ ();
00091 inline void make_inf()
00092 {
00093 pos = block_type::size;
00094 }
00095 };
00096
00097 #ifdef STXXL_SORT_SINGLE_PREFETCHER
00098 template <typename must_be_void>
00099 void * have_prefetcher<must_be_void>::untyped_prefetcher = NULL;
00100 #endif
00101
00102 template <typename block_type,
00103 typename prefetcher_type>
00104 void run_cursor2<block_type, prefetcher_type>::operator ++ ()
00105 {
00106 assert(!empty());
00107 ++pos;
00108 if (UNLIKELY(pos >= block_type::size))
00109 {
00110 if (prefetcher()->block_consumed(buffer))
00111 pos = 0;
00112 }
00113 }
00114
00115
00116 #if 0
00117 template <typename block_type>
00118 struct run_cursor_cmp
00119 {
00120 typedef run_cursor<block_type> cursor_type;
00121
00122 inline bool operator () (const cursor_type & a, const cursor_type & b)
00123 {
00124 return !((*a.buffer)[a.pos] < (*b.buffer)[b.pos]);
00125 }
00126 };
00127 #endif
00128
00129 __STXXL_END_NAMESPACE
00130
00131
00132 #endif // !STXXL_RUN_CURSOR_HEADER
00133