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