TPIE

v1.1rc1-6-g0c97303
tpie::serialization_bits::internal_sort< T, pred_t > Class Template Reference

Public Member Functions

 internal_sort (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 63 of file serialization_sort.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 142 of file serialization_sort.h.

142  {
143  return m_serializedSize;
144  }
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 185 of file serialization_sort.h.

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

185  {
186  m_buffer.resize(0);
187  reset();
188  }
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:431
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 156 of file serialization_sort.h.

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

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

156  {
157  return m_buffer.size() * sizeof(T)
158  + (m_serializedSize - m_items * sizeof(T));
159  }
size_type size() const
Return the size of the array.
Definition: array.h:472
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 99 of file serialization_sort.h.

References tpie::serialization_bits::internal_sort< T, pred_t >::memory_usage(), tpie::serialized_size(), and tpie::array< T, Allocator >::size().

99  {
100  if (m_full) return false;
101 
102  if (m_items == m_buffer.size()) {
103  m_full = true;
104  return false;
105  }
106 
107  memory_size_type serSize = serialized_size(item);
108 
109  if (serSize > sizeof(T)) {
110  // amount of memory this item needs for its extra stuff (stuff not in the buffer).
111  memory_size_type serializedExtra = serSize - sizeof(T);
112 
113  // amount of memory not used for the buffer and not used for extra stuff already.
114  memory_size_type memRemainingExtra = m_memAvail - memory_usage();
115 
116  if (serializedExtra > memRemainingExtra) {
117  m_full = true;
118  return false;
119  }
120 
121  if (serSize > m_largestItem)
122  m_largestItem = serSize;
123  }
124 
125  m_serializedSize += serSize;
126 
127  m_buffer[m_items++] = item;
128 
129  return true;
130  }
size_t serialized_size(const T &v)
Given a serializable, serialize it and measure its serialized size.
size_type size() const
Return the size of the array.
Definition: array.h:472
memory_size_type memory_usage()
Compute current memory usage.
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 194 of file serialization_sort.h.

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

194  {
195  m_items = m_serializedSize = 0;
196  m_full = false;
197  }

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