1 #ifndef OSMIUM_ITEM_STASH_HPP 2 #define OSMIUM_ITEM_STASH_HPP 42 #ifdef OSMIUM_ITEM_STORAGE_GC_DEBUG 79 assert(new_value > 0);
99 template <
typename TChar,
typename TTraits>
100 friend inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out,
const ItemStash::handle_type& handle) {
101 if (handle.valid()) {
120 #ifdef OSMIUM_ITEM_STORAGE_GC_DEBUG 121 int64_t m_gc_time = 0;
127 std::size_t m_pos = 0;
136 while (m_index[m_pos] != old_offset) {
138 assert(m_pos < m_index.size());
140 m_index[m_pos] = new_offset;
147 assert(handle.valid() &&
"handle must be valid");
148 assert(handle.value <= m_index.size());
149 auto& offset = m_index[handle.value - 1];
150 assert(offset != removed_item_offset);
156 assert(handle.valid() &&
"handle must be valid");
157 assert(handle.value <= m_index.size());
158 const auto& offset = m_index[handle.value - 1];
159 assert(offset != removed_item_offset);
174 if (m_count_removed < 10 * 1000) {
177 if (m_count_removed > 5 * 1000 * 1000) {
180 if (m_count_removed * 5 < m_count_items) {
189 m_buffer(initial_buffer_size,
osmium::memory::Buffer::auto_grow::yes) {
201 m_index.capacity() *
sizeof(std::size_t);
210 std::size_t
size() const noexcept {
246 const auto offset = m_buffer.
committed();
249 m_index.push_back(offset);
283 template <
typename T>
285 return static_cast<T&
>(
get_item(handle));
297 #ifdef OSMIUM_ITEM_STORAGE_GC_DEBUG 298 std::cerr <<
"GC items=" << m_count_items <<
" removed=" << m_count_removed <<
" buffer.committed=" << m_buffer.
committed() <<
" buffer.capacity=" << m_buffer.
capacity() <<
"\n";
299 using clock = std::chrono::high_resolution_clock;
300 std::chrono::time_point<clock> start = clock::now();
307 #ifdef OSMIUM_ITEM_STORAGE_GC_DEBUG 308 std::chrono::time_point<clock> stop = clock::now();
309 const int64_t time = std::chrono::duration_cast<std::chrono::microseconds>(stop - start).count();
311 std::cerr <<
" time=" << time
312 <<
"us total=" << m_gc_time <<
"us\n";
331 assert(!item.removed() &&
"can not call remove_item() on already removed item");
342 #endif // OSMIUM_ITEM_STASH_HPP std::size_t capacity() const noexcept
Definition: buffer.hpp:260
std::size_t commit()
Definition: buffer.hpp:355
std::size_t m_count_items
Definition: item_stash.hpp:118
std::size_t value
Definition: item_stash.hpp:75
handle_type add_item(const osmium::memory::Item &item)
Definition: item_stash.hpp:241
handle_type() noexcept
The defalt constructor creates an invalid handle.
Definition: item_stash.hpp:85
cleanup_helper(std::vector< std::size_t > &index)
Definition: item_stash.hpp:131
std::size_t count_removed() const noexcept
Definition: item_stash.hpp:220
Definition: item_stash.hpp:71
static constexpr const std::size_t initial_buffer_size
Definition: item_stash.hpp:113
osmium::memory::Item & get_item(handle_type handle) const
Definition: item_stash.hpp:264
std::size_t used_memory() const noexcept
Definition: item_stash.hpp:198
std::size_t m_count_removed
Definition: item_stash.hpp:119
std::size_t clear()
Definition: buffer.hpp:386
std::size_t committed() const noexcept
Definition: buffer.hpp:268
static constexpr const std::size_t removed_item_offset
Definition: item_stash.hpp:114
osmium::memory::Buffer m_buffer
Definition: item_stash.hpp:116
Definition: item_stash.hpp:57
handle_type(std::size_t new_value) noexcept
Definition: item_stash.hpp:77
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
T & add_item(const T &item)
Definition: buffer.hpp:483
std::vector< std::size_t > m_index
Definition: item_stash.hpp:117
void purge_removed(TCallbackClass *callback)
Definition: buffer.hpp:731
T & get(const std::size_t offset) const
Definition: buffer.hpp:405
bool should_gc() const noexcept
Definition: item_stash.hpp:173
ItemStash()
Definition: item_stash.hpp:188
void garbage_collect()
Definition: item_stash.hpp:296
void moving_in_buffer(std::size_t old_offset, std::size_t new_offset)
Definition: item_stash.hpp:135
void set_removed(bool removed) noexcept
Definition: item.hpp:177
std::vector< std::size_t > & m_index
Definition: item_stash.hpp:126
std::size_t size() const noexcept
Definition: item_stash.hpp:210
friend class ItemStash
Definition: item_stash.hpp:73
Definition: buffer.hpp:98
void remove_item(handle_type handle)
Definition: item_stash.hpp:328
bool valid() const noexcept
Is this a valid handle?
Definition: item_stash.hpp:90
std::size_t & get_item_offset_ref(handle_type handle) noexcept
Definition: item_stash.hpp:146
void clear()
Definition: item_stash.hpp:228
std::size_t get_item_offset(handle_type handle) const noexcept
Definition: item_stash.hpp:155
Definition: item_stash.hpp:124