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()) {
130 #ifdef OSMIUM_ITEM_STORAGE_GC_DEBUG 131 int64_t m_gc_time = 0;
137 std::size_t m_pos = 0;
146 while (m_index[m_pos] != old_offset) {
148 assert(m_pos < m_index.size());
150 m_index[m_pos] = new_offset;
157 assert(handle.valid() &&
"handle must be valid");
158 assert(handle.value <= m_index.size());
159 auto& offset = m_index[handle.value - 1];
166 assert(handle.valid() &&
"handle must be valid");
167 assert(handle.value <= m_index.size());
168 const auto& offset = m_index[handle.value - 1];
184 if (m_count_removed < 10 * 1000) {
187 if (m_count_removed > 5 * 1000 * 1000) {
190 if (m_count_removed * 5 < m_count_items) {
211 m_index.capacity() *
sizeof(std::size_t);
220 std::size_t
size() const noexcept {
256 const auto offset = m_buffer.
committed();
259 m_index.push_back(offset);
293 template <
typename T>
295 return static_cast<T&
>(
get_item(handle));
307 #ifdef OSMIUM_ITEM_STORAGE_GC_DEBUG 308 std::cerr <<
"GC items=" << m_count_items <<
" removed=" << m_count_removed <<
" buffer.committed=" << m_buffer.
committed() <<
" buffer.capacity=" << m_buffer.
capacity() <<
"\n";
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");
352 #endif // OSMIUM_STORAGE_ITEM_STASH_HPP std::size_t capacity() const noexcept
Definition: buffer.hpp:348
std::size_t commit()
Definition: buffer.hpp:468
std::size_t m_count_items
Definition: item_stash.hpp:128
std::size_t value
Definition: item_stash.hpp:75
handle_type add_item(const osmium::memory::Item &item)
Definition: item_stash.hpp:251
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:141
std::size_t count_removed() const noexcept
Definition: item_stash.hpp:230
Definition: item_stash.hpp:71
osmium::memory::Item & get_item(handle_type handle) const
Definition: item_stash.hpp:274
Definition: item_stash.hpp:119
std::size_t used_memory() const noexcept
Definition: item_stash.hpp:208
std::size_t m_count_removed
Definition: item_stash.hpp:129
std::size_t clear()
Definition: buffer.hpp:499
Definition: item_stash.hpp:123
std::size_t committed() const noexcept
Definition: buffer.hpp:356
osmium::memory::Buffer m_buffer
Definition: item_stash.hpp:126
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:601
std::vector< std::size_t > m_index
Definition: item_stash.hpp:127
void purge_removed(TCallbackClass *callback)
Definition: buffer.hpp:854
T & get(const std::size_t offset) const
Definition: buffer.hpp:518
bool should_gc() const noexcept
Definition: item_stash.hpp:183
ItemStash()
Definition: item_stash.hpp:198
void garbage_collect()
Definition: item_stash.hpp:306
void moving_in_buffer(std::size_t old_offset, std::size_t new_offset)
Definition: item_stash.hpp:145
std::vector< std::size_t > & m_index
Definition: item_stash.hpp:136
std::size_t size() const noexcept
Definition: item_stash.hpp:220
friend class ItemStash
Definition: item_stash.hpp:73
Definition: buffer.hpp:97
void remove_item(handle_type handle)
Definition: item_stash.hpp:338
bool valid() const noexcept
Is this a valid handle?
Definition: item_stash.hpp:95
void set_removed(const bool removed) noexcept
Definition: item.hpp:179
std::size_t & get_item_offset_ref(handle_type handle) noexcept
Definition: item_stash.hpp:156
void clear()
Definition: item_stash.hpp:238
std::size_t get_item_offset(handle_type handle) const noexcept
Definition: item_stash.hpp:165
Definition: item_stash.hpp:134