33 #ifndef __H__UG__page_container_impl__
34 #define __H__UG__page_container_impl__
45 template <
class T,
int MAX_PAGE_SIZE,
class Allocator>
48 m_numPageEntries((size_t)(MAX_PAGE_SIZE / sizeof(T))),
53 template <
class T,
int MAX_PAGE_SIZE,
class Allocator>
56 m_numPageEntries((size_t)(MAX_PAGE_SIZE / sizeof(T)))
61 template <
class T,
int MAX_PAGE_SIZE,
class Allocator>
66 for(
size_t i = 0; i < m_pages.size(); ++i){
67 m_alloc.deallocate(m_pages[i], m_numPageEntries);
71 template <
class T,
int MAX_PAGE_SIZE,
class Allocator>
80 template <
class T,
int MAX_PAGE_SIZE,
class Allocator>
87 template <
class T,
int MAX_PAGE_SIZE,
class Allocator>
91 return m_pages.size() * m_numPageEntries;
94 template <
class T,
int MAX_PAGE_SIZE,
class Allocator>
96 resize(
size_t size,
const T& val)
106 while(m_size < size){
107 T* page = get_page(m_size);
108 size_t offset = get_page_offset(m_size);
109 const size_t maxI = min(m_numPageEntries, offset + size - m_size);
111 for(
size_t i = offset; i < maxI; ++i)
112 m_alloc.construct(page + i, val);
114 m_size += maxI - offset;
119 while(m_size > size){
120 T* page = get_page(m_size - 1);
121 size_t maxI = get_page_offset(m_size - 1) + 1;
123 const size_t diff = m_size - size;
125 minI = (maxI) - diff;
127 for(
size_t i = minI; i < maxI; ++i)
128 m_alloc.destroy(page + i);
130 m_size -= (maxI - minI);
135 template <
class T,
int MAX_PAGE_SIZE,
class Allocator>
142 while(m_pages.size() * m_numPageEntries < size){
144 T* buf = m_alloc.allocate(m_numPageEntries);
146 m_pages.push_back(buf);
151 template <
class T,
int MAX_PAGE_SIZE,
class Allocator>
158 template <
class T,
int MAX_PAGE_SIZE,
class Allocator>
162 assert(ind < m_size);
163 return get_page(ind)[get_page_offset(ind)];
166 template <
class T,
int MAX_PAGE_SIZE,
class Allocator>
170 assert(ind < m_size);
171 return get_page(ind)[get_page_offset(ind)];
174 template <
class T,
int MAX_PAGE_SIZE,
class Allocator>
179 Allocator talloc = m_alloc;
188 template <
class T,
int MAX_PAGE_SIZE,
class Allocator>
198 while(m_size < pc.
m_size){
199 T* page = get_page(m_size);
201 size_t offset = get_page_offset(m_size);
202 const size_t maxI = min(m_numPageEntries, offset + pc.
m_size - m_size);
204 for(
size_t i = offset; i < maxI; ++i)
205 m_alloc.construct(page + i, srcPage[i]);
211 template <
class T,
int MAX_PAGE_SIZE,
class Allocator>
215 assert(get_page_index(ind) < m_pages.size());
216 return m_pages[get_page_index(ind)];
219 template <
class T,
int MAX_PAGE_SIZE,
class Allocator>
223 return ind / m_numPageEntries;
226 template <
class T,
int MAX_PAGE_SIZE,
class Allocator>
230 return ind % m_numPageEntries;
Definition: page_container.h:46
size_t capacity() const
Definition: page_container_impl.h:89
PageContainer()
Definition: page_container_impl.h:47
size_t m_size
Definition: page_container.h:92
Allocator m_alloc
Definition: page_container.h:93
T * get_page(size_t ind) const
returns the page in which the data for the given index lies
Definition: page_container_impl.h:213
void reserve(size_t size)
Definition: page_container_impl.h:137
size_t get_page_offset(size_t ind) const
returns the offset that a index has in its page
Definition: page_container_impl.h:228
size_t size() const
Definition: page_container_impl.h:82
void resize(size_t size, const T &val=T())
Definition: page_container_impl.h:96
std::vector< T * > m_pages
Definition: page_container.h:90
void clear()
Definition: page_container_impl.h:153
~PageContainer()
Definition: page_container_impl.h:63
PageContainer & operator=(const PageContainer &pc)
Definition: page_container_impl.h:74
size_t get_page_index(size_t ind) const
returns the index of the page in which the data for the given index lies
Definition: page_container_impl.h:221
T & operator[](size_t ind)
Definition: page_container_impl.h:160
void assign_container(const PageContainer &pc)
Definition: page_container_impl.h:190
void swap(PageContainer &pc)
Definition: page_container_impl.h:176
Definition: smart_pointer.h:814
bool resize(size_t newRows, size_t newCols)