• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List

run_cursor.h

00001 /***************************************************************************
00002  *  include/stxxl/bits/algo/run_cursor.h
00003  *
00004  *  Part of the STXXL. See http://stxxl.sourceforge.net
00005  *
00006  *  Copyright (C) 2003 Roman Dementiev <dementiev@mpi-sb.mpg.de>
00007  *
00008  *  Distributed under the Boost Software License, Version 1.0.
00009  *  (See accompanying file LICENSE_1_0.txt or copy at
00010  *  http://www.boost.org/LICENSE_1_0.txt)
00011  **************************************************************************/
00012 
00013 #ifndef STXXL_RUN_CURSOR_HEADER
00014 #define STXXL_RUN_CURSOR_HEADER
00015 
00016 #include <cstdlib>
00017 #include <stxxl/bits/common/types.h>
00018 
00019 
00020 __STXXL_BEGIN_NAMESPACE
00021 
00022 template <typename block_type>
00023 struct run_cursor
00024 {
00025     unsigned_type pos;
00026     block_type * buffer;
00027 
00028     run_cursor() : pos(0), buffer(NULL) { }
00029 
00030     inline const typename block_type::type & current() const
00031     {
00032         return (*buffer)[pos];
00033     }
00034     inline void operator ++ ()
00035     {
00036         ++pos;
00037     }
00038 };
00039 
00040 #ifdef STXXL_SORT_SINGLE_PREFETCHER
00041 
00042 template <typename must_be_void = void>
00043 struct have_prefetcher
00044 {
00045     static void * untyped_prefetcher;
00046 };
00047 
00048 #endif
00049 
00050 template <typename block_type,
00051           typename prefetcher_type_>
00052 struct run_cursor2 : public run_cursor<block_type>
00053 #ifdef STXXL_SORT_SINGLE_PREFETCHER
00054                      , public have_prefetcher<>
00055 #endif
00056 {
00057     typedef prefetcher_type_ prefetcher_type;
00058     typedef run_cursor2<block_type, prefetcher_type> _Self;
00059     typedef typename block_type::value_type value_type;
00060 
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()    // sorry, a hack
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() // sorry, a hack
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)      // greater or equal
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 // vim: et:ts=4:sw=4

Generated on Sun Oct 17 2010 06:13:44 for Stxxl by  doxygen 1.7.1