Stxxl  1.3.2
sorted_runs.h
1 /***************************************************************************
2  * include/stxxl/bits/stream/sorted_runs.h
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  * Copyright (C) 2002-2005 Roman Dementiev <[email protected]>
7  * Copyright (C) 2009, 2010 Andreas Beckmann <[email protected]>
8  *
9  * Distributed under the Boost Software License, Version 1.0.
10  * (See accompanying file LICENSE_1_0.txt or copy at
11  * http://www.boost.org/LICENSE_1_0.txt)
12  **************************************************************************/
13 
14 #ifndef STXXL_STREAM__SORTED_RUNS_H
15 #define STXXL_STREAM__SORTED_RUNS_H
16 
17 #include <vector>
18 #include <stxxl/bits/mng/mng.h>
19 #include <stxxl/bits/mng/typed_block.h>
20 #include <stxxl/bits/algo/adaptor.h>
21 
22 
23 __STXXL_BEGIN_NAMESPACE
24 
25 namespace stream
26 {
29 
30 
32  // SORTED RUNS //
34 
36  template <typename TriggerEntryType>
37  struct sorted_runs
38  {
39  typedef TriggerEntryType trigger_entry_type;
40  typedef typename trigger_entry_type::block_type block_type;
41  typedef typename block_type::value_type value_type; // may differ from trigger_entry_type::value_type
42  typedef std::vector<trigger_entry_type> run_type;
43  typedef std::vector<value_type> small_run_type;
44  typedef stxxl::external_size_type size_type;
45  typedef typename std::vector<run_type>::size_type run_index_type;
46 
47  size_type elements;
48  std::vector<run_type> runs;
49  std::vector<size_type> runs_sizes;
50 
51  // Optimization:
52  // if the input is small such that its total size is
53  // at most B (block_type::size)
54  // then input is sorted internally
55  // and kept in the array "small"
56  small_run_type small_;
57 
58  sorted_runs() : elements(0) { }
59 
60  const small_run_type & small_run() const
61  {
62  return small_;
63  }
64 
70  {
71  block_manager * bm = block_manager::get_instance();
72  for (unsigned_type i = 0; i < runs.size(); ++i)
73  bm->delete_blocks(make_bid_iterator(runs[i].begin()), make_bid_iterator(runs[i].end()));
74 
75  runs.clear();
76  }
77 
78  // returns number of elements in all runs together
79  size_type size() const
80  {
81  return elements;
82  }
83  };
84 
85 
87 }
88 
89 __STXXL_END_NAMESPACE
90 
91 #endif // !STXXL_STREAM__SORTED_RUNS_H
92 // vim: et:ts=4:sw=4
All sorted runs of a sort operation.
Definition: sorted_runs.h:37
void delete_blocks(const BIDIteratorClass &bidbegin, const BIDIteratorClass &bidend)
Deallocates blocks.
Definition: mng.h:218
void deallocate_blocks()
Deallocates the blocks which the runs occupy.
Definition: sorted_runs.h:69
Block manager class.
Definition: mng.h:59