24 #ifndef _TPIE_AMI_STACK_H
25 #define _TPIE_AMI_STACK_H
30 #include <tpie/stream.h>
48 , m_buffer(buffer_size(blockFactor))
61 stack(
const std::string & path,
double blockFactor=1.0)
63 , m_buffer(buffer_size(blockFactor))
69 m_stream.seek(0, file_stream_base::end);
80 , m_buffer(buffer_size(blockFactor))
86 m_stream.seek(0, file_stream_base::end);
106 if (m_buffer.
size() == m_bufferItems) empty_buffer();
107 m_buffer[m_bufferItems++] = t;
114 if (m_bufferItems)
return m_buffer[--m_bufferItems];
115 const T & item =
m_stream.read_back();
123 if (m_bufferItems)
return m_buffer[m_bufferItems-1];
132 stream_size_type
size()
const {
133 return m_stream.offset()+m_bufferItems;
159 size_t m_bufferItems;
161 inline void empty_buffer() {
162 if (m_bufferItems == 0)
return;
168 static memory_size_type buffer_size(
double blockFactor) {
187 m_ulate(m_tempFile) {
200 : m_tempFile(path, true)
201 , m_ulate(m_tempFile)
238 return m_ulate.size();
245 return m_ulate.empty();
288 TP_LOG_WARNING_ID(
"Using AMI_stack<T>::stream_len() is deprecated.");
333 const T & res = m_ulate.pop();
357 const T & res = m_ulate.top();
376 switch (usage_type) {
385 *usage +=
sizeof(*this);
389 tp_assert(0,
"Unknown mem::stream_usage type added.");
401 #endif // _TPIE_AMI_STACK_H
Defines the tp_assert macro.
stack()
Initializes the stack.
Maximum additional amount used by each substream created.
PERSIST_DELETE
Delete the stream from the disk when it is destructed.
Max amount that will ever be used.
static memory_size_type memory_usage(memory_size_type size)
Return the number of bytes required to create a data structure supporting a given number of elements...
stack(const std::string &path, double blockFactor=1.0)
Initialize named, nontemporary stack.
void unused(const T &x)
Declare that a variable is unused on purpose.
TPIE_OS_OFFSET stream_len() const
file_stream< T > m_stream
The stream used to store the items.
stack(temp_file &tempFile, double blockFactor=1.0)
Initialize temporary stack.
~stack()
Closes the underlying stream and truncates it to the logical end of the stack.
const T & pop()
Pops one item from the stack.
Macros for deprecating classes, methods and typedefs.
err push(const T &t)
Pushes one item onto the stack.
An implementation of an external-memory stack.
This file contains a few deprecated definitions for legacy code.
Overhead of the object without the buffer.
Compressed stream public API.
TPIE_OS_OFFSET size() const
Returns the number of items currently on the stack.
void set_persistent(bool p)
Set persistence.
stack(const std::string &path, stream_type type=READ_WRITE_STREAM)
Initializes the stack by (re-)opening the file given.
A low level I/O error occurred.
Generic internal array with known memory requirements.
persistence persist() const
Returns the persistence status of the (stream underlying the) stack.
stream_size_type size() const
Returns the number of items currently on the stack.
void persist(persistence p)
Set the persistence status of the (stream underlying the) stack.
Class representing a reference to a temporary file.
err trim()
Truncates the underlying stream to the exact size (rounded up to the next block) of items...
An implementation of an external-memory stack compatible with the old AMI interface.
stream_type
AMI stream types passed to constructors.
PERSIST_PERSISTENT
Do not delete the stream from the disk when it is destructed.
bool is_empty() const
Returns whether the stack is empty or not.
bool is_persistent() const
err pop(const T **t)
Pops one item from the stack.
bool empty() const
Returns whether the stack is empty or not.
err
Legacy TPIE error codes.
Compress some blocks according to available resources (time, memory).
void push(const T &t)
Pushes one item onto the stack.
static memory_size_type memory_usage(float blockFactor=1.0)
Compute the memory used by a stack.
iterator begin()
Return an iterator to the beginning of the array.
stack(double blockFactor=1.0)
Initialize anonymous stack.
size_type size() const
Return the size of the array.
const T & top()
Peeks at the topmost item on the stack.
#define tp_assert(condition, message)
Neither sequential access nor random access is intended.
An attempt was made to read past the end of a stream or write past the end of a substream.
err main_memory_usage(TPIE_OS_SIZE_T *usage, stream_usage usage_type) const
Compute the memory used by the stack and the aggregated stream.
Max amount ever used by a buffer.
err peek(const T **t)
Peeks at the topmost item on the stack.
Open a file for reading or writing.