24 #ifndef _TPIE_AMI_STACK_H
25 #define _TPIE_AMI_STACK_H
45 inline stack(
double blockFactor = 1.0)
47 , m_buffer(buffer_size(blockFactor))
59 inline stack(
const std::string& path,
double block_factor = 1.0)
61 , m_buffer(buffer_size(block_factor))
77 , m_buffer(buffer_size(block_factor))
103 if (m_buffer.
size() == m_bufferItems) empty_buffer();
104 m_buffer[m_bufferItems++] = t;
111 if (m_bufferItems)
return m_buffer[--m_bufferItems];
120 if (m_bufferItems)
return m_buffer[m_bufferItems-1];
129 inline stream_size_type
size()
const {
156 size_t m_bufferItems;
158 inline void empty_buffer() {
159 if (m_bufferItems == 0)
return;
164 inline static memory_size_type buffer_size(
double blockFactor) {
183 m_ulate(m_tempFile) {
196 : m_tempFile(path, true)
197 , m_ulate(m_tempFile)
234 return m_ulate.size();
241 return m_ulate.empty();
284 TP_LOG_WARNING_ID(
"Using AMI_stack<T>::stream_len() is deprecated.");
324 const T & res = m_ulate.pop();
346 const T & res = m_ulate.top();
365 switch (usage_type) {
374 *usage +=
sizeof(*this);
378 tp_assert(0,
"Unknown mem::stream_usage type added.");
390 #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.
file_stream< T > m_file_stream
The file_stream used to store the items.
void unused(const T &x)
Declare that a variable is unused on purpose.
TPIE_OS_OFFSET stream_len() const
~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.
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.
stack(temp_file &tempFile, double block_factor=1.0)
Initialize temporary 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 the existence of 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.
memory_size_type block_size() const
Get the size of a block in bytes.
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.
Simple class acting both as file and a file::stream.
err
Legacy TPIE error codes.
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)
stack(const std::string &path, double block_factor=1.0)
Initialize named, nontemporary stack.
static stream_size_type memory_usage(stream_size_type size)
Return the number of bytes required to create a data structure supporting a given number of elements...
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.