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 template <typename must_be_void = void>
00042 struct have_prefetcher
00043 {
00044 static void * untyped_prefetcher;
00045 };
00046
00047 #endif
00048
00049 template <typename block_type,
00050 typename prefetcher_type_>
00051 struct run_cursor2 : public run_cursor<block_type>
00052 #ifdef STXXL_SORT_SINGLE_PREFETCHER
00053 , public have_prefetcher<>
00054 #endif
00055 {
00056 typedef prefetcher_type_ prefetcher_type;
00057 typedef run_cursor2<block_type, prefetcher_type> _Self;
00058 typedef typename block_type::value_type value_type;
00059
00060
00061 using run_cursor<block_type>::pos;
00062 using run_cursor<block_type>::buffer;
00063
00064 #ifdef STXXL_SORT_SINGLE_PREFETCHER
00065 static prefetcher_type * const prefetcher()
00066 {
00067 return reinterpret_cast<prefetcher_type *>(untyped_prefetcher);
00068 }
00069 static void set_prefetcher(prefetcher_type * pfptr)
00070 {
00071 untyped_prefetcher = pfptr;
00072 }
00073 run_cursor2() { }
00074 #else
00075 prefetcher_type * prefetcher_;
00076 prefetcher_type * & prefetcher()
00077 {
00078 return prefetcher_;
00079 }
00080
00081 run_cursor2() { }
00082 run_cursor2(prefetcher_type * p) : prefetcher_(p) { }
00083 #endif
00084
00085 inline bool empty() const
00086 {
00087 return (pos >= block_type::size);
00088 }
00089 inline void operator ++ (int);
00090 inline void make_inf()
00091 {
00092 pos = block_type::size;
00093 }
00094 };
00095
00096 #ifdef STXXL_SORT_SINGLE_PREFETCHER
00097 template <typename must_be_void>
00098 void * have_prefetcher<must_be_void>::untyped_prefetcher = NULL;
00099 #endif
00100
00101 template <typename block_type,
00102 typename prefetcher_type>
00103 void run_cursor2<block_type, prefetcher_type>::operator ++ (int)
00104 {
00105 assert(!empty());
00106 pos++;
00107 if (UNLIKELY(pos >= block_type::size))
00108 {
00109 if (prefetcher()->block_consumed(buffer))
00110 pos = 0;
00111 }
00112 }
00113
00114
00115 template <typename block_type>
00116 struct run_cursor_cmp
00117 {
00118 typedef run_cursor<block_type> cursor_type;
00119
00120
00121
00122
00123
00124 };
00125
00126 __STXXL_END_NAMESPACE
00127
00128
00129 #endif // !STXXL_RUN_CURSOR_HEADER