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>
105 friend inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out,
const ItemStash::handle_type& handle) {
106 if (handle.valid()) {
125 #ifdef OSMIUM_ITEM_STORAGE_GC_DEBUG 126 int64_t m_gc_time = 0;
132 std::size_t m_pos = 0;
141 while (m_index[m_pos] != old_offset) {
143 assert(m_pos < m_index.size());
145 m_index[m_pos] = new_offset;
152 assert(handle.valid() &&
"handle must be valid");
153 assert(handle.value <= m_index.size());
154 auto& offset = m_index[handle.value - 1];
155 assert(offset != removed_item_offset);
161 assert(handle.valid() &&
"handle must be valid");
162 assert(handle.value <= m_index.size());
163 const auto& offset = m_index[handle.value - 1];
164 assert(offset != removed_item_offset);
179 if (m_count_removed < 10 * 1000) {
182 if (m_count_removed > 5 * 1000 * 1000) {
185 if (m_count_removed * 5 < m_count_items) {
194 m_buffer(initial_buffer_size,
osmium::memory::Buffer::auto_grow::yes) {
206 m_index.capacity() *
sizeof(std::size_t);
215 std::size_t
size() const noexcept {
251 const auto offset = m_buffer.
committed();
254 m_index.push_back(offset);
288 template <
typename T>
290 return static_cast<T&
>(
get_item(handle));
302 #ifdef OSMIUM_ITEM_STORAGE_GC_DEBUG 303 std::cerr <<
"GC items=" << m_count_items <<
" removed=" << m_count_removed <<
" buffer.committed=" << m_buffer.
committed() <<
" buffer.capacity=" << m_buffer.
capacity() <<
"\n";
304 using clock = std::chrono::high_resolution_clock;
305 std::chrono::time_point<clock> start = clock::now();
312 #ifdef OSMIUM_ITEM_STORAGE_GC_DEBUG 313 std::chrono::time_point<clock> stop = clock::now();
314 const int64_t time = std::chrono::duration_cast<std::chrono::microseconds>(stop - start).count();
316 std::cerr <<
" time=" << time
317 <<
"us total=" << m_gc_time <<
"us\n";
336 assert(!item.removed() &&
"can not call remove_item() on already removed item");
347 #endif // OSMIUM_STORAGE_ITEM_STASH_HPP std::size_t capacity() const noexcept
Definition: buffer.hpp:253
std::size_t commit()
Definition: buffer.hpp:348
std::size_t m_count_items
Definition: item_stash.hpp:123
std::size_t value
Definition: item_stash.hpp:75
handle_type add_item(const osmium::memory::Item &item)
Definition: item_stash.hpp:246
handle_type() noexcept
The default constructor creates an invalid handle.
Definition: item_stash.hpp:90
cleanup_helper(std::vector< std::size_t > &index)
Definition: item_stash.hpp:136
std::size_t count_removed() const noexcept
Definition: item_stash.hpp:225
Definition: item_stash.hpp:71
static constexpr const std::size_t initial_buffer_size
Definition: item_stash.hpp:118
osmium::memory::Item & get_item(handle_type handle) const
Definition: item_stash.hpp:269
std::size_t used_memory() const noexcept
Definition: item_stash.hpp:203
std::size_t m_count_removed
Definition: item_stash.hpp:124
std::size_t clear()
Definition: buffer.hpp:379
std::size_t committed() const noexcept
Definition: buffer.hpp:261
static constexpr const std::size_t removed_item_offset
Definition: item_stash.hpp:119
osmium::memory::Buffer m_buffer
Definition: item_stash.hpp:121
Definition: item_stash.hpp:57
handle_type(std::size_t new_value) noexcept
Definition: item_stash.hpp:82
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
T & add_item(const T &item)
Definition: buffer.hpp:476
std::vector< std::size_t > m_index
Definition: item_stash.hpp:122
void purge_removed(TCallbackClass *callback)
Definition: buffer.hpp:724
T & get(const std::size_t offset) const
Definition: buffer.hpp:398
bool should_gc() const noexcept
Definition: item_stash.hpp:178
ItemStash()
Definition: item_stash.hpp:193
void garbage_collect()
Definition: item_stash.hpp:301
void moving_in_buffer(std::size_t old_offset, std::size_t new_offset)
Definition: item_stash.hpp:140
void set_removed(bool removed) noexcept
Definition: item.hpp:177
std::vector< std::size_t > & m_index
Definition: item_stash.hpp:131
std::size_t size() const noexcept
Definition: item_stash.hpp:215
friend class ItemStash
Definition: item_stash.hpp:73
Definition: buffer.hpp:97
void remove_item(handle_type handle)
Definition: item_stash.hpp:333
bool valid() const noexcept
Is this a valid handle?
Definition: item_stash.hpp:95
std::size_t & get_item_offset_ref(handle_type handle) noexcept
Definition: item_stash.hpp:151
void clear()
Definition: item_stash.hpp:233
std::size_t get_item_offset(handle_type handle) const noexcept
Definition: item_stash.hpp:160
Definition: item_stash.hpp:129