TPIE

2362a60
tpie::serialization_bits::internal_sort< T, pred_t > Class Template Reference

Public Member Functions

 internal_sort (memory_bucket_ref buffer_bucket, memory_bucket_ref item_bucket, pred_t pred=pred_t())
 
void begin (memory_size_type memAvail)
 
bool push (const T &item)
 True if all items up to and including this one fits in buffer. More...
 
memory_size_type get_largest_item_size ()
 
memory_size_type current_serialized_size ()
 Get the serialized size of the items written. More...
 
memory_size_type memory_usage ()
 Compute current memory usage. More...
 
bool can_shrink_buffer ()
 
void shrink_buffer ()
 
void sort ()
 
const T * begin () const
 
const T * end () const
 
void free ()
 Deallocate buffer and call reset(). More...
 
void reset ()
 Reset sorter, but keep the remembered largest item size and buffer size. More...
 

Detailed Description

template<typename T, typename pred_t>
class tpie::serialization_bits::internal_sort< T, pred_t >

Definition at line 89 of file serialization_sorter.h.

Member Function Documentation

template<typename T , typename pred_t >
memory_size_type tpie::serialization_bits::internal_sort< T, pred_t >::current_serialized_size ( )
inline

Get the serialized size of the items written.

This is exactly the size the current run will use when serialized to disk.

Definition at line 165 of file serialization_sorter.h.

165  {
166  return m_item_bucket->count;
167  }
template<typename T , typename pred_t >
void tpie::serialization_bits::internal_sort< T, pred_t >::free ( )
inline

Deallocate buffer and call reset().

Definition at line 207 of file serialization_sorter.h.

References tpie::serialization_bits::internal_sort< T, pred_t >::reset(), and tpie::array< T, Allocator >::resize().

207  {
208  reset();
209  m_buffer.resize(0);
210  }
void reset()
Reset sorter, but keep the remembered largest item size and buffer size.
void resize(size_t size, const T &elm)
Change the size of the array.
Definition: array.h:485
template<typename T , typename pred_t >
memory_size_type tpie::serialization_bits::internal_sort< T, pred_t >::memory_usage ( )
inline

Compute current memory usage.

This includes the item buffer array as well as the extra serialized size of the items already written to the buffer. This assumes that items use as much primary memory as their serialized size. If this assumption does not hold, the memory usage reported may be useless. Nevertheless, this is the memory usage we use in our calculations.

Definition at line 179 of file serialization_sorter.h.

179  {
180  return m_buffer_bucket->count + m_item_bucket->count;
181  }
template<typename T , typename pred_t >
bool tpie::serialization_bits::internal_sort< T, pred_t >::push ( const T &  item)
inline

True if all items up to and including this one fits in buffer.

Once push() returns false, it will keep returning false until the sequence is sorted, read out, and the buffer has been cleared.

Definition at line 131 of file serialization_sorter.h.

References tpie::array< T, Allocator >::size().

131  {
132  if (m_full) return false;
133 
134  if (m_items == m_buffer.size()) {
135  m_full = true;
136  return false;
137  }
138 
139  size_t oldSize = m_item_bucket->count;
140  set_owner(m_item_bucket, item);
141 
142  if (m_item_bucket->count > m_memForItems) {
143  unset_owner(m_item_bucket, item);
144  m_full = true;
145  return false;
146  }
147 
148  m_largestItem = std::max(m_largestItem, m_item_bucket->count - oldSize);
149 
150  m_buffer[m_items++] = item;
151 
152  return true;
153  }
size_type size() const
Return the size of the array.
Definition: array.h:526
template<typename T , typename pred_t >
void tpie::serialization_bits::internal_sort< T, pred_t >::reset ( )
inline

Reset sorter, but keep the remembered largest item size and buffer size.

Definition at line 216 of file serialization_sorter.h.

Referenced by tpie::serialization_bits::internal_sort< T, pred_t >::free().

216  {
217  for (size_t i = 0 ; i < m_items ; ++i)
218  unset_owner(m_item_bucket, m_buffer[i]);
219  m_item_bucket->count = 0;
220  m_items = 0;
221  m_full = false;
222  }

The documentation for this class was generated from the following file: