1#ifndef OSMIUM_STORAGE_ITEM_STASH_HPP
2#define OSMIUM_STORAGE_ITEM_STASH_HPP
45#ifdef OSMIUM_ITEM_STORAGE_GC_DEBUG
84 assert(new_value > 0);
104 template <
typename TChar,
typename TTraits>
106 if (handle.
valid()) {
130#ifdef OSMIUM_ITEM_STORAGE_GC_DEBUG
131 int64_t m_gc_time = 0;
157 assert(handle.valid() &&
"handle must be valid");
158 assert(handle.value <=
m_index.size());
159 auto& offset =
m_index[handle.value - 1];
161 assert(offset <
m_buffer.committed());
166 assert(handle.valid() &&
"handle must be valid");
167 assert(handle.value <=
m_index.size());
168 const auto& offset =
m_index[handle.value - 1];
170 assert(offset <
m_buffer.committed());
211 m_index.capacity() *
sizeof(std::size_t);
220 std::size_t
size() const noexcept {
256 const auto offset =
m_buffer.committed();
293 template <
typename T>
295 return static_cast<T&
>(
get_item(handle));
307#ifdef OSMIUM_ITEM_STORAGE_GC_DEBUG
309 using clock = std::chrono::high_resolution_clock;
310 std::chrono::time_point<clock> start = clock::now();
317#ifdef OSMIUM_ITEM_STORAGE_GC_DEBUG
318 std::chrono::time_point<clock> stop = clock::now();
319 const int64_t time = std::chrono::duration_cast<std::chrono::microseconds>(stop - start).count();
321 std::cerr <<
" time=" << time
322 <<
"us total=" << m_gc_time <<
"us\n";
341 assert(!item.removed() &&
"can not call remove_item() on already removed item");
342 item.set_removed(
true);
Definition: item_stash.hpp:134
std::vector< std::size_t > & m_index
Definition: item_stash.hpp:136
cleanup_helper(std::vector< std::size_t > &index)
Definition: item_stash.hpp:141
void moving_in_buffer(std::size_t old_offset, std::size_t new_offset)
Definition: item_stash.hpp:145
std::size_t m_pos
Definition: item_stash.hpp:137
Definition: item_stash.hpp:71
bool valid() const noexcept
Is this a valid handle?
Definition: item_stash.hpp:95
handle_type(std::size_t new_value) noexcept
Definition: item_stash.hpp:82
friend std::basic_ostream< TChar, TTraits > & operator<<(std::basic_ostream< TChar, TTraits > &out, const ItemStash::handle_type &handle)
Definition: item_stash.hpp:105
handle_type() noexcept
The default constructor creates an invalid handle.
Definition: item_stash.hpp:90
std::size_t value
Definition: item_stash.hpp:75
Definition: item_stash.hpp:57
T & get(handle_type handle) const
Definition: item_stash.hpp:294
void remove_item(handle_type handle)
Definition: item_stash.hpp:338
@ initial_buffer_size
Definition: item_stash.hpp:119
std::size_t get_item_offset(handle_type handle) const noexcept
Definition: item_stash.hpp:165
std::size_t & get_item_offset_ref(handle_type handle) noexcept
Definition: item_stash.hpp:156
osmium::memory::Item & get_item(handle_type handle) const
Definition: item_stash.hpp:274
std::vector< std::size_t > m_index
Definition: item_stash.hpp:127
handle_type add_item(const osmium::memory::Item &item)
Definition: item_stash.hpp:251
void clear()
Definition: item_stash.hpp:238
std::size_t m_count_items
Definition: item_stash.hpp:128
std::size_t size() const noexcept
Definition: item_stash.hpp:220
std::size_t count_removed() const noexcept
Definition: item_stash.hpp:230
void garbage_collect()
Definition: item_stash.hpp:306
@ removed_item_offset
Definition: item_stash.hpp:123
std::size_t used_memory() const noexcept
Definition: item_stash.hpp:208
ItemStash()
Definition: item_stash.hpp:198
osmium::memory::Buffer m_buffer
Definition: item_stash.hpp:126
bool should_gc() const noexcept
Definition: item_stash.hpp:183
std::size_t m_count_removed
Definition: item_stash.hpp:129
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53