14#ifndef CXXUTILS_POINTER_LIST_H
15#define CXXUTILS_POINTER_LIST_H
79 static size_t size (
size_t nelt);
108 unsigned long end_mask,
109 unsigned long end_offs);
239template <
size_t NELT = 15>
259 static_assert (((NELT+1) & NELT) == 0);
Allocator for pointer_list, specialized for NELT.
static const unsigned long END_OFFS
Verify that NELT is one less than a power of two.
allocator(size_t nblock=100)
Constructor.
static bool at_end_static(const void *p)
Test if P is pointing at the end-pointer of a block.
static const unsigned long END_MASK
Forward iterator over the list.
friend class pointer_list
iterator & operator++()
Advance (pre-increment).
std::forward_iterator_tag iterator_category
iterator operator++(int)
Advance (post-increment).
iterator(value_type *p)
Constructor, from a pointer into a pointer_list.
std::ptrdiff_t difference_type
value_type * m_p
Current iteration position.
pointer_list::value_type value_type
bool operator==(const iterator &other) const
Equality comparison.
bool operator!=(const iterator &other) const
Inequality comparison.
reference operator*()
Dereference.
Very simple allocator for use with pointer_list.
unsigned long m_end_mask
Mask for testing for an end pointer.
allocator(size_t nelt, size_t nblock, unsigned long end_mask, unsigned long end_offs)
Constructor.
bool at_end(const void *p) const
Test if P is pointing at the end-pointer of a block.
void refill()
Allocate a new chunk of blocks.
size_t m_nblock
Number of blocks per chunk.
~allocator()
Destructor. Deletes all blocks from this allocator.
chunk * m_chunks
Most recent chunk allocated.
size_t m_nelt
Number of elements per block (excluding the end-pointer).
size_t m_nchunks
Current number of allocated chunks.
unsigned long m_end_offs
Offset for testing for an end pointer.
size_t nelt() const
Return the number of pointers per block (excluding the end-pointer).
size_t nchunks() const
Return the current number of allocated chunks.
size_t m_nthis
Number of blocks allocated so far from that chunk.
list_block * allocate()
Allocate a new block.
list_block::value_type value_type
The stored element type.
void push_back(value_type p)
Add a new element to the end of the container. O(1)
list_block * m_head
The first block in the list.
void nextblock()
Extend the list with another block.
value_type * m_insert
The current insertion point in the list.
void clear()
Erase the container.
bool empty() const
Test to see if the container is empty.
void firstblock()
Allocate the first block of the list.
size_t m_size
The current list size.
pointer_list_base(pool_type &pool)
Constructor. pool gives the allocator for this container.
allocator pool_type
Alias for allocator.
allocator & m_pool
The list allocator.
list_block * getblock()
Allocate a new block.
size_t size() const
The current size of the container. O(1).
iterator end()
Iterator at the end of the container.
iterator begin()
Iterator at the beginning of the container.
pointer_list(pool_type &pool)
Constructor. pool gives the allocator for this container.
void erase(iterator it)
Erase one element. O(n)
pointer_list_base::value_type value_type
Stored value type.
One memory allocation chunk.
list_block * m_blocks
Pointer to the first block contained within this chunk.
chunk * m_next
Link to the next chunk.
A single block in the list.
static size_t size(size_t nelt)
Size in bytes of a block holding nelt elements (excluding the end-pointer).
value_type m_data[1]
The elements.
void * value_type
The element type we store.