Libosmium  2.20.0
Fast and flexible C++ library for working with OpenStreetMap data
Classes | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
osmium::index::map::FlexMem< TId, TValue > Class Template Reference

#include <flex_mem.hpp>

Inheritance diagram for osmium::index::map::FlexMem< TId, TValue >:
Inheritance graph
[legend]
Collaboration diagram for osmium::index::map::FlexMem< TId, TValue >:
Collaboration graph
[legend]

Classes

struct  entry
 

Public Member Functions

 FlexMem (bool use_dense=false)
 
bool is_dense () const noexcept
 
std::size_t size () const noexcept final
 
std::size_t used_memory () const noexcept final
 
void set (const TId id, const TValue value) final
 Set the field with id to value. More...
 
TValue get_noexcept (const TId id) const noexcept final
 
TValue get (const TId id) const final
 
void clear () final
 
void sort () final
 
void switch_to_dense ()
 
std::pair< std::size_t, std::size_t > stats () const noexcept
 
- Public Member Functions inherited from osmium::index::map::Map< TId, TValue >
 Map () noexcept=default
 
 Map (const Map &)=delete
 
Mapoperator= (const Map &)=delete
 
virtual ~Map () noexcept=default
 
virtual void reserve (const std::size_t)
 
virtual void set (const TId id, const TValue value)=0
 Set the field with id to value. More...
 
virtual TValue get (const TId id) const =0
 
virtual TValue get_noexcept (const TId id) const noexcept=0
 
virtual std::size_t size () const =0
 
virtual std::size_t used_memory () const =0
 
virtual void clear ()=0
 
virtual void sort ()
 
virtual void dump_as_list (const int)
 
virtual void dump_as_array (const int)
 

Private Types

enum  { bits = 16 }
 
enum  : uint64_t { block_size = 1ULL << bits }
 
enum  : int64_t { min_dense_entries = 0xffffff }
 
enum  { density_factor = 3 }
 

Private Member Functions

void assure_block (const uint64_t num)
 
void set_sparse (const uint64_t id, const TValue value)
 
TValue get_sparse (const uint64_t id) const noexcept
 
void set_dense (const uint64_t id, const TValue value)
 
TValue get_dense (const uint64_t id) const noexcept
 

Static Private Member Functions

static uint64_t block (const uint64_t id) noexcept
 
static uint64_t offset (const uint64_t id) noexcept
 

Private Attributes

std::vector< entrym_sparse_entries
 
std::vector< std::vector< TValue > > m_dense_blocks
 
uint64_t m_max_id = 0
 
bool m_dense
 

Additional Inherited Members

- Public Types inherited from osmium::index::map::Map< TId, TValue >
using key_type = TId
 The "key" type, usually osmium::unsigned_object_id_type. More...
 
using value_type = TValue
 The "value" type, usually a Location or size_t. More...
 
- Protected Member Functions inherited from osmium::index::map::Map< TId, TValue >
 Map (Map &&) noexcept=default
 
Mapoperator= (Map &&) noexcept=default
 

Detailed Description

template<typename TId, typename TValue>
class osmium::index::map::FlexMem< TId, TValue >

This is an autoscaling index that works well with small and large input data. All data will be held in memory. For small input data a sparse array will be used, if this becomes inefficient, the class will switch automatically to a dense index.

Member Enumeration Documentation

◆ anonymous enum

template<typename TId , typename TValue >
anonymous enum
private
Enumerator
bits 

◆ anonymous enum

template<typename TId , typename TValue >
anonymous enum : uint64_t
private
Enumerator
block_size 

◆ anonymous enum

template<typename TId , typename TValue >
anonymous enum : int64_t
private
Enumerator
min_dense_entries 

◆ anonymous enum

template<typename TId , typename TValue >
anonymous enum
private
Enumerator
density_factor 

Constructor & Destructor Documentation

◆ FlexMem()

template<typename TId , typename TValue >
osmium::index::map::FlexMem< TId, TValue >::FlexMem ( bool  use_dense = false)
inlineexplicit

Create FlexMem index.

Parameters
use_denseUsually FlexMem indexes start out as sparse indexes and will switch to dense when they think it is better. Set this to force dense indexing from the start. This is usually only useful for testing.

Member Function Documentation

◆ assure_block()

template<typename TId , typename TValue >
void osmium::index::map::FlexMem< TId, TValue >::assure_block ( const uint64_t  num)
inlineprivate

◆ block()

template<typename TId , typename TValue >
static uint64_t osmium::index::map::FlexMem< TId, TValue >::block ( const uint64_t  id)
inlinestaticprivatenoexcept

◆ clear()

template<typename TId , typename TValue >
void osmium::index::map::FlexMem< TId, TValue >::clear ( )
inlinefinalvirtual

Clear memory used for this storage. After this you can not use the storage container any more.

Implements osmium::index::map::Map< TId, TValue >.

◆ get()

template<typename TId , typename TValue >
TValue osmium::index::map::FlexMem< TId, TValue >::get ( const TId  id) const
inlinefinalvirtual

Retrieve value by id.

Parameters
idThe id to look for.
Returns
Value.
Exceptions
osmium::not_foundif the id could not be found.

Implements osmium::index::map::Map< TId, TValue >.

◆ get_dense()

template<typename TId , typename TValue >
TValue osmium::index::map::FlexMem< TId, TValue >::get_dense ( const uint64_t  id) const
inlineprivatenoexcept

◆ get_noexcept()

template<typename TId , typename TValue >
TValue osmium::index::map::FlexMem< TId, TValue >::get_noexcept ( const TId  id) const
inlinefinalvirtualnoexcept

Retrieve value by id.

Parameters
idThe id to look for.
Returns
Value or, if not found, the empty value as defined by osmium::index::empty_value<TValue>() which is usually the default constructed value of type TValue.

Implements osmium::index::map::Map< TId, TValue >.

◆ get_sparse()

template<typename TId , typename TValue >
TValue osmium::index::map::FlexMem< TId, TValue >::get_sparse ( const uint64_t  id) const
inlineprivatenoexcept

◆ is_dense()

template<typename TId , typename TValue >
bool osmium::index::map::FlexMem< TId, TValue >::is_dense ( ) const
inlinenoexcept

◆ offset()

template<typename TId , typename TValue >
static uint64_t osmium::index::map::FlexMem< TId, TValue >::offset ( const uint64_t  id)
inlinestaticprivatenoexcept

◆ set()

template<typename TId , typename TValue >
void osmium::index::map::FlexMem< TId, TValue >::set ( const TId  id,
const TValue  value 
)
inlinefinalvirtual

Set the field with id to value.

Implements osmium::index::map::Map< TId, TValue >.

◆ set_dense()

template<typename TId , typename TValue >
void osmium::index::map::FlexMem< TId, TValue >::set_dense ( const uint64_t  id,
const TValue  value 
)
inlineprivate

◆ set_sparse()

template<typename TId , typename TValue >
void osmium::index::map::FlexMem< TId, TValue >::set_sparse ( const uint64_t  id,
const TValue  value 
)
inlineprivate

◆ size()

template<typename TId , typename TValue >
std::size_t osmium::index::map::FlexMem< TId, TValue >::size ( ) const
inlinefinalvirtualnoexcept

Get the approximate number of items in the storage. The storage might allocate memory in blocks, so this size might not be accurate. You can not use this to find out how much memory the storage uses. Use used_memory() for that.

Implements osmium::index::map::Map< TId, TValue >.

◆ sort()

template<typename TId , typename TValue >
void osmium::index::map::FlexMem< TId, TValue >::sort ( )
inlinefinalvirtual

Sort data in map. Call this after writing all data and before reading. Not all implementations need this.

Reimplemented from osmium::index::map::Map< TId, TValue >.

◆ stats()

template<typename TId , typename TValue >
std::pair< std::size_t, std::size_t > osmium::index::map::FlexMem< TId, TValue >::stats ( ) const
inlinenoexcept

◆ switch_to_dense()

template<typename TId , typename TValue >
void osmium::index::map::FlexMem< TId, TValue >::switch_to_dense ( )
inline

Switch from using a sparse to a dense index. Usually you do not need to call this, because the FlexMem class will do this automatically if it thinks the dense index is more efficient.

Does nothing if the index is already in dense mode.

◆ used_memory()

template<typename TId , typename TValue >
std::size_t osmium::index::map::FlexMem< TId, TValue >::used_memory ( ) const
inlinefinalvirtualnoexcept

Get the memory used for this storage in bytes. Note that this is not necessarily entirely accurate but an approximation. For storage classes that store the data in memory, this is the main memory used, for storage classes storing data on disk this is the memory used on disk.

Implements osmium::index::map::Map< TId, TValue >.

Member Data Documentation

◆ m_dense

template<typename TId , typename TValue >
bool osmium::index::map::FlexMem< TId, TValue >::m_dense
private

◆ m_dense_blocks

template<typename TId , typename TValue >
std::vector<std::vector<TValue> > osmium::index::map::FlexMem< TId, TValue >::m_dense_blocks
private

◆ m_max_id

template<typename TId , typename TValue >
uint64_t osmium::index::map::FlexMem< TId, TValue >::m_max_id = 0
private

◆ m_sparse_entries

template<typename TId , typename TValue >
std::vector<entry> osmium::index::map::FlexMem< TId, TValue >::m_sparse_entries
private

The documentation for this class was generated from the following file: