15 #ifndef STXXL_STREAM_STREAM_HEADER
16 #define STXXL_STREAM_STREAM_HEADER
26 #ifndef STXXL_VERBOSE_MATERIALIZE
27 #define STXXL_VERBOSE_MATERIALIZE STXXL_VERBOSE3
45 template <
class InputIterator>
52 typedef typename std::iterator_traits<InputIterator>::value_type
value_type;
55 : m_current(begin), m_end(end)
59 : m_current(a.m_current), m_end(a.m_end)
76 assert(m_end != m_current);
84 return (m_current == m_end);
92 template <
class InputIterator>
99 template <
class InputIterator>
110 template <
class InputIterator>
114 typedef buf_istream<
typename InputIterator::block_type,
129 typedef typename std::iterator_traits<InputIterator>::value_type
value_type;
133 : m_current(begin), m_end(end),
140 typename InputIterator::bids_container_iterator end_iter
141 = end.bid() + ((end.block_offset()) ? 1 : 0);
143 if (end_iter - begin.bid() > 0)
146 begin.bid(), end_iter, nbuffers ? nbuffers :
147 (2 * config::get_instance()->disks_number())
151 InputIterator cur = begin - begin.block_offset();
154 for ( ; cur != begin; ++cur)
160 : m_current(a.m_current), m_end(a.m_end), in(a.in.release())
177 assert(m_end != m_current);
189 return (m_current == m_end);
205 template <
typename ValueType,
typename AllocStr,
typename SizeType,
206 typename DiffType,
unsigned BlockSize,
typename PagerType,
208 vector_iterator2stream<
210 DiffType, BlockSize, PagerType, PageSize>
214 DiffType, BlockSize, PagerType, PageSize> begin,
216 DiffType, BlockSize, PagerType, PageSize> end,
222 DiffType, BlockSize, PagerType, PageSize>
223 >(begin, end, nbuffers);
226 template <
typename ValueType,
typename AllocStr,
typename SizeType,
227 typename DiffType,
unsigned BlockSize,
typename PagerType,
231 DiffType, BlockSize, PagerType, PageSize>
236 DiffType, BlockSize, PagerType, PageSize>
248 template <
typename ValueType,
typename AllocStr,
typename SizeType,
249 typename DiffType,
unsigned BlockSize,
typename PagerType,
253 DiffType, BlockSize, PagerType, PageSize>
257 DiffType, BlockSize, PagerType, PageSize> begin,
259 DiffType, BlockSize, PagerType, PageSize> end,
262 STXXL_VERBOSE1(
"streamify for const_vector_iterator range is called");
265 DiffType, BlockSize, PagerType, PageSize>
266 >(begin, end, nbuffers);
269 template <
typename ValueType,
typename AllocStr,
typename SizeType,
270 typename DiffType,
unsigned BlockSize,
typename PagerType,
274 DiffType, BlockSize, PagerType, PageSize>
279 DiffType, BlockSize, PagerType, PageSize>
289 template <
class InputIterator>
301 typedef typename std::iterator_traits<InputIterator>::value_type
value_type;
306 if (end - begin < block_type::size)
308 STXXL_VERBOSE1(
"vector_iterator2stream_sr::vector_iterator2stream_sr: Choosing iterator2stream<InputIterator>");
310 vec_it_stream = NULL;
314 STXXL_VERBOSE1(
"vector_iterator2stream_sr::vector_iterator2stream_sr: Choosing vector_iterator2stream<InputIterator>");
321 : vec_it_stream(a.vec_it_stream), it_stream(a.it_stream)
330 return **vec_it_stream;
336 return &(**it_stream);
338 return &(**vec_it_stream);
357 return it_stream->empty();
359 return vec_it_stream->empty();
367 delete vec_it_stream;
373 template <
typename ValueType,
typename AllocStr,
typename SizeType,
374 typename DiffType,
unsigned BlockSize,
typename PagerType,
376 vector_iterator2stream_sr<
378 DiffType, BlockSize, PagerType, PageSize>
382 DiffType, BlockSize, PagerType, PageSize> begin,
384 DiffType, BlockSize, PagerType, PageSize> end,
387 STXXL_VERBOSE1(
"streamify_sr for vector_iterator range is called");
390 DiffType, BlockSize, PagerType, PageSize>
391 >(begin, end, nbuffers);
396 template <
typename ValueType,
typename AllocStr,
typename SizeType,
397 typename DiffType,
unsigned BlockSize,
typename PagerType,
399 vector_iterator2stream_sr<
401 DiffType, BlockSize, PagerType, PageSize>
405 DiffType, BlockSize, PagerType, PageSize> begin,
407 DiffType, BlockSize, PagerType, PageSize> end,
410 STXXL_VERBOSE1(
"streamify_sr for const_vector_iterator range is called");
413 DiffType, BlockSize, PagerType, PageSize>
414 >(begin, end, nbuffers);
427 template <
class OutputIterator,
class StreamAlgorithm>
428 OutputIterator
materialize(StreamAlgorithm& in, OutputIterator out)
449 template <
class OutputIterator,
class StreamAlgorithm>
451 OutputIterator outbegin, OutputIterator outend)
454 while ((!in.empty()) && outend != outbegin)
474 template <
typename ValueType,
typename AllocStr,
typename SizeType,
475 typename DiffType,
unsigned BlockSize,
typename PagerType,
476 unsigned PageSize,
class StreamAlgorithm>
478 DiffType, BlockSize, PagerType, PageSize>
481 DiffType, BlockSize, PagerType, PageSize> outbegin,
483 DiffType, BlockSize, PagerType, PageSize> outend,
491 while (outbegin.block_offset())
494 if (in.empty() || outbegin == outend)
503 nbuffers = 2 * config::get_instance()->disks_number();
508 buf_ostream_type outstream(outbegin.bid(), nbuffers);
510 assert(outbegin.block_offset() == 0);
514 ConstExtIterator prev_block = outbegin;
516 while (!in.empty() && outend != outbegin)
518 if (outbegin.block_offset() == 0) {
519 if (prev_block != outbegin) {
520 prev_block.block_externally_updated();
521 prev_block = outbegin;
531 ConstExtIterator const_out = outbegin;
533 while (const_out.block_offset())
535 *outstream = *const_out;
540 if (prev_block != outbegin)
541 prev_block.block_externally_updated();
556 template <
typename ValueType,
typename AllocStr,
typename SizeType,
557 typename DiffType,
unsigned BlockSize,
typename PagerType,
558 unsigned PageSize,
class StreamAlgorithm>
560 DiffType, BlockSize, PagerType, PageSize>
563 DiffType, BlockSize, PagerType, PageSize> out,
576 while (out.block_offset())
588 nbuffers = 2 * config::get_instance()->disks_number();
593 buf_ostream_type outstream(out.bid(), nbuffers);
595 assert(out.block_offset() == 0);
599 ConstExtIterator prev_block = out;
603 if (out.block_offset() == 0) {
604 if (prev_block != out) {
605 prev_block.block_externally_updated();
617 ConstExtIterator const_out = out;
620 while (const_out.block_offset())
622 *outstream = *const_out;
627 if (prev_block != out)
628 prev_block.block_externally_updated();
639 template <
class StreamAlgorithm>
656 template <
class Generator,
typename T =
typename Generator::value_type>
669 : gen_(g), m_current(gen_())
702 template <
class Generator>
724 template <
class Operation,
751 transform(Operation& o, Input1& i1_, Input2& i2_, Input3& i3_, Input4& i4_,
752 Input5& i5_, Input5& i6_)
753 : op(o), i1(i1_), i2(i2_), i3(i3_), i4(i4_), i5(i5_), i6(i6_)
756 current = op(*i1, *i2, *i3, *i4, *i5, *i6);
780 current = op(*i1, *i2, *i3, *i4, *i5, *i6);
788 return i1.empty() || i2.empty() || i3.empty() ||
789 i4.empty() || i5.empty() || i6.empty();
805 template <
class Operation,
867 template <
class Operation,
886 transform(Operation& o, Input1& i1_, Input2& i2_) : op(o), i1(i1_), i2(i2_)
889 current = op(*i1, *i2);
909 current = op(*i1, *i2);
917 return i1.empty() || i2.empty();
933 template <
class Operation,
954 transform(Operation& o, Input1& i1_, Input2& i2_, Input3& i3_)
955 : op(o), i1(i1_), i2(i2_), i3(i3_)
958 current = op(*i1, *i2, *i3);
979 current = op(*i1, *i2, *i3);
987 return i1.empty() || i2.empty() || i3.empty();
1004 template <
class Operation,
1027 transform(Operation& o, Input1& i1_, Input2& i2_, Input3& i3_, Input4& i4_)
1028 : op(o), i1(i1_), i2(i2_), i3(i3_), i4(i4_)
1031 current = op(*i1, *i2, *i3, *i4);
1053 current = op(*i1, *i2, *i3, *i4);
1061 return i1.empty() || i2.empty() || i3.empty() || i4.empty();
1079 template <
class Operation,
1104 transform(Operation& o, Input1& i1_, Input2& i2_, Input3& i3_,
1105 Input4& i4_, Input5& i5_)
1106 : op(o), i1(i1_), i2(i2_), i3(i3_), i4(i4_), i5(i5_)
1109 current = op(*i1, *i2, *i3, *i4, *i5);
1132 current = op(*i1, *i2, *i3, *i4, *i5);
1140 return i1.empty() || i2.empty() || i3.empty() || i4.empty() || i5.empty();
1156 template <
class Input1,
1158 class Input3 = Stopper,
1159 class Input4 = Stopper,
1160 class Input5 = Stopper,
1161 class Input6 = Stopper
1175 typename Input1::value_type,
1176 typename Input2::value_type,
1177 typename Input3::value_type,
1178 typename Input4::value_type,
1179 typename Input5::value_type,
1180 typename Input6::value_type
1194 : i1(i1_), i2(i2_), i3(i3_), i4(i4_), i5(i5_), i6(i6_)
1197 current =
value_type(*i1, *i2, *i3, *i4, *i5, *i6);
1222 current =
value_type(*i1, *i2, *i3, *i4, *i5, *i6);
1230 return i1.empty() || i2.empty() || i3.empty() ||
1231 i4.empty() || i5.empty() || i6.empty();
1240 template <
class Input1,
1251 typename Input1::value_type,
1252 typename Input2::value_type
1294 return i1.empty() || i2.empty();
1304 template <
class Input1,
1317 typename Input1::value_type,
1318 typename Input2::value_type,
1319 typename Input3::value_type
1330 : i1(i1_), i2(i2_), i3(i3_)
1363 return i1.empty() || i2.empty() || i3.empty();
1374 template <
class Input1,
1389 typename Input1::value_type,
1390 typename Input2::value_type,
1391 typename Input3::value_type,
1392 typename Input4::value_type
1404 : i1(i1_), i2(i2_), i3(i3_), i4(i4_)
1438 return i1.empty() || i2.empty() || i3.empty() ||
1469 typename Input1::value_type,
1470 typename Input2::value_type,
1471 typename Input3::value_type,
1472 typename Input4::value_type,
1473 typename Input5::value_type
1486 : i1(i1_), i2(i2_), i3(i3_), i4(i4_), i5(i5_)
1489 current =
value_type(*i1, *i2, *i3, *i4, *i5);
1513 current =
value_type(*i1, *i2, *i3, *i4, *i5);
1521 return i1.empty() || i2.empty() || i3.empty() ||
1522 i4.empty() || i5.empty();
1535 #endif // !STXXL_STREAM_STREAM_HEADER
iterator2stream< InputIterator > streamify(InputIterator begin, InputIterator end)
Input iterator range to stream converter.
Const external vector iterator, model of ext_random_access_iterator concept.
iterator2stream< InputIterator > * it_stream
std::iterator_traits< InputIterator >::value_type value_type
Standard stream typedef.
vector_iterator2stream< InputIterator > * vec_it_stream
vector_iterator2stream< stxxl::const_vector_iterator< ValueType, AllocStr, SizeType, DiffType, BlockSize, PagerType, PageSize > > stream_type
#define STXXL_VERBOSE_MATERIALIZE
A model of stream that retrieves the data from an input iterator. For convenience use streamify funct...
Traits class of streamify function.
std::iterator_traits< InputIterator >::value_type value_type
Standard stream typedef.
bool empty() const
Standard stream method.
vector_iterator2stream(const self_type &a)
iterator2stream(InputIterator begin, InputIterator end)
Version of iterator2stream. Switches between vector_iterator2stream and iterator2stream ...
self_type & flush()
Force flush of current block, for finishing writing within a block.
uint_pair & operator++()
prefix increment operator (directly manipulates the integer parts)
virtual ~vector_iterator2stream_sr()
vector_iterator2stream_sr(const self_type &a)
bool empty() const
Standard stream method.
vector_iterator2stream_sr< InputIterator > self_type
std::auto_ptr< Type > result
vector_iterator2stream_sr(InputIterator begin, InputIterator end, unsigned_type nbuffers=0)
A model of stream that retrieves data from an external stxxl::vector iterator. It is more efficient t...
Creates stream of 6-tuples from 6 input streams.
A model of stream that outputs data from an adaptable generator functor. For convenience use streamif...
buf_istream_unique_ptr_type in
iterator2stream(const iterator2stream &a)
T value_type
Standard stream typedef.
bool empty() const
Standard stream method.
#define STXXL_BEGIN_NAMESPACE
#define STXXL_VERBOSE1(x)
iterator2stream< InputIterator > stream_type
return type (stream type) of streamify for InputIterator.
bool empty() const
Standard stream method.
External vector iterator, model of ext_random_access_iterator concept.
bool empty() const
Standard stream method.
OutputIterator materialize(StreamAlgorithm &in, OutputIterator out)
Stores consecutively stream content to an output iterator.
generator2stream(Generator g)
generator2stream(const generator2stream &a)
choose_int_types< my_pointer_size >::unsigned_type unsigned_type
vector_iterator2stream_sr< stxxl::vector_iterator< ValueType, AllocStr, SizeType, DiffType, BlockSize, PagerType, PageSize > > streamify_sr(stxxl::vector_iterator< ValueType, AllocStr, SizeType, DiffType, BlockSize, PagerType, PageSize > begin, stxxl::vector_iterator< ValueType, AllocStr, SizeType, DiffType, BlockSize, PagerType, PageSize > end, unsigned_type nbuffers=0)
Version of streamify. Switches from vector_iterator2stream to iterator2stream for small ranges...
vector_iterator2stream(InputIterator begin, InputIterator end, unsigned_type nbuffers=0)
void discard(StreamAlgorithm &in)
Reads stream content and discards it. Useful where you do not need the processed stream anymore...
make_tuple(Input1 &i1_, Input2 &i2_, Input3 &i3_, Input4 &i4_, Input5 &i5_, Input6 &i6_)
Construction.
vector_iterator2stream< stxxl::vector_iterator< ValueType, AllocStr, SizeType, DiffType, BlockSize, PagerType, PageSize > > stream_type
#define STXXL_PRETTY_FUNCTION_NAME
std::iterator_traits< InputIterator >::value_type value_type
Standard stream typedef.
buf_istream< typename InputIterator::block_type, typename InputIterator::bids_container_iterator > buf_istream_type
stxxl::compat_unique_ptr< buf_istream_type >::result buf_istream_unique_ptr_type
stxxl::tuple< typename Input1::value_type, typename Input2::value_type, typename Input3::value_type, typename Input4::value_type, typename Input5::value_type, typename Input6::value_type > value_type
Standard stream typedef.
virtual ~vector_iterator2stream()
#define STXXL_END_NAMESPACE
InputIterator::block_type block_type
vector_iterator2stream< InputIterator > self_type