From 43da08a1e3620cc296d27ef5cdf387693b063c68 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 16 Feb 2020 21:36:24 +0100 Subject: Fix style, minor code fixes, and add review comments. --- src/memory_heap.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/memory_heap.h') diff --git a/src/memory_heap.h b/src/memory_heap.h index e2901b8..d90c50c 100644 --- a/src/memory_heap.h +++ b/src/memory_heap.h @@ -51,9 +51,9 @@ public: template Index emplace(Args&&... args); - Index add(T const& element); + Index add(const T& element); T& get(Index index); - T const& get(Index index) const; + const T& get(Index index) const; void remove(Index index); private: @@ -62,7 +62,7 @@ private: }; template -auto MemoryHeap::add(T const& element) -> Index +auto MemoryHeap::add(const T& element) -> Index { if (free_indices.empty()) { @@ -92,6 +92,8 @@ auto MemoryHeap::emplace(Args&&... args) -> Index return free_index; } +// Note: MemoryHeap never really deletes anything -- it just overwrites, so +// old indices will always return a valid item wrt. memory. template T& MemoryHeap::get(Index index) { @@ -100,7 +102,7 @@ T& MemoryHeap::get(Index index) } template -T const& MemoryHeap::get(Index index) const +const T& MemoryHeap::get(Index index) const { assert(index < memory.size()); return memory[index]; -- cgit v1.2.3