Skip to content

Commit b103ae1

Browse files
committed
Checkpoint: growable linked list (untested)
1 parent 8bdc6c8 commit b103ae1

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

include/nbl/core/containers/GrowableDoublyLinkedList.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,20 @@ class GrowableDoublyLinkedList : public DoublyLinkedListBase<Value>
4242

4343
inline void grow(uint32_t newCapacity)
4444
{
45+
// Same as code found in ContiguousMemoryLinkedListBase to create aligned space
4546
const auto firstPart = core::alignUp(address_allocator_t::reserved_size(1u, newCapacity, 1u), alignof(node_t));
4647
void* newReservedSpace = _NBL_ALIGNED_MALLOC(firstPart + newCapacity * sizeof(node_t), alignof(node_t));
4748
node_t* newArray = reinterpret_cast<node_t*>(reinterpret_cast<uint8_t*>(newReservedSpace) + firstPart);
4849

50+
// Copy memory over to new buffer, then free old one
4951
memcpy(reinterpret_cast<void*>(newArray), reinterpret_cast<void*>(this->m_array), m_cap * sizeof(node_t));
52+
_NBL_ALIGNED_FREE(m_reservedSpace);
5053

51-
//this->m_addressAllocator = std::unique_ptr<address_allocator_t>(new address_allocator_t(newCapacity, std::move(this->m_addressAllocator)));
52-
this->m_cap = capacity;
53-
this->m_back = invalid_iterator;
54-
this->m_begin = invalid_iterator;
54+
// Finally, create new address allocator from old one
55+
this->m_addressAllocator = std::unique_ptr<address_allocator_t>(new address_allocator_t(newCapacity, std::move(*(this->m_addressAllocator)), newReservedSpace));
56+
this->m_cap = newCapacity;
57+
this->m_array = newArray;
58+
this->m_reservedSpace = newReservedSpace;
5559
}
5660
};
5761

include/nbl/core/containers/lists/DoublyLinkedListBase.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class DoublyLinkedListBase : public impl::ContiguousMemoryLinkedListBase<SDoubly
6969
_NBL_STATIC_INLINE_CONSTEXPR uint32_t invalid_iterator = base_t::invalid_iterator;
7070

7171
//remove the last element in the list
72-
inline virtual void popBack() final
72+
inline virtual void popBack() override final
7373
{
7474
if (this->m_back == invalid_iterator)
7575
return;
@@ -83,7 +83,7 @@ class DoublyLinkedListBase : public impl::ContiguousMemoryLinkedListBase<SDoubly
8383
}
8484

8585
//remove a node at nodeAddr from the list
86-
inline virtual void erase(const uint32_t nodeAddr) final
86+
inline virtual void erase(const uint32_t nodeAddr) override final
8787
{
8888
assert(nodeAddr != invalid_iterator);
8989
assert(nodeAddr < this->m_cap);
@@ -99,7 +99,7 @@ class DoublyLinkedListBase : public impl::ContiguousMemoryLinkedListBase<SDoubly
9999
}
100100

101101
//move a node at nodeAddr to the front of the list
102-
inline virtual void moveToFront(const uint32_t nodeAddr) final
102+
inline virtual void moveToFront(const uint32_t nodeAddr) override final
103103
{
104104
if (this->m_begin == nodeAddr || nodeAddr == invalid_iterator)
105105
return;
@@ -137,7 +137,7 @@ class DoublyLinkedListBase : public impl::ContiguousMemoryLinkedListBase<SDoubly
137137

138138
private:
139139
//create a new node which stores data at already allocated address,
140-
inline virtual void insertAt(uint32_t addr, value_t&& val) final
140+
inline virtual void insertAt(uint32_t addr, value_t&& val) override final
141141
{
142142
assert(addr < this->m_cap);
143143
assert(addr != invalid_iterator);
@@ -152,7 +152,7 @@ class DoublyLinkedListBase : public impl::ContiguousMemoryLinkedListBase<SDoubly
152152
this->m_begin = addr;
153153
}
154154

155-
inline virtual void common_detach(node_t* node) final
155+
inline virtual void common_detach(node_t* node) override final
156156
{
157157
if (node->next != invalid_iterator)
158158
this->get(node->next)->prev = node->prev;

0 commit comments

Comments
 (0)