SST  12.0.1
StructuralSimulationToolkit
SST::SparseVectorMap< keyT, classT > Class Template Reference

Class that stores data in a vector, but can access the data similar to a map. More...

#include <sparseVectorMap.h>

Public Types

typedef std::vector< classT >
::iterator 
iterator
 
typedef std::vector< classT >
::const_iterator 
const_iterator
 

Public Member Functions

 SparseVectorMap ()
 Default constructor for SparseVectorMap.
 
 SparseVectorMap (std::vector< classT > &new_data, bool sorted=false)
 Constructor that allows you to pass an already filled in array with data. More...
 
classT & insert (const classT &val)
 Insert new value into SparseVectorMap. More...
 
iterator begin ()
 Returns the begin iterator to the underlying vector. More...
 
iterator end ()
 Returns the end iterator to the underlying vector. More...
 
const_iterator begin () const
 Returns the const begin iterator to the underlying vector. More...
 
const_iterator end () const
 Returns the const end iterator to the underlying vector. More...
 
bool contains (keyT id) const
 Checks if the provided id is found in the SparseVectorMap. More...
 
classT & operator[] (keyT id)
 Operator returns a reference to data with the specified id. More...
 
const classT & operator[] (keyT id) const
 Operator returns a const reference to data with the specified id. More...
 
void clear ()
 Clears the contents of the SparseVectorMap.
 
size_t size ()
 Returns the number of items in the SparseVectorMap. More...
 

Friends

class SST::Core::Serialization::serialize< SparseVectorMap< keyT, classT > >
 
class ConfigGraph
 

Detailed Description

template<typename keyT, typename classT = keyT>
class SST::SparseVectorMap< keyT, classT >

Class that stores data in a vector, but can access the data similar to a map.

The data structure is O(log n) on reads, but is O(n) to insert. The primary use case is when data is inserted in order, but accessed randomly. You can also create the SparseVectorMap with a vector already loaded with the data. If the data is not already sorted, it will call std::sort on the data, which likely has an average complexity of O(n log n). This data structure should not be used for large lists where inserts do not happen in sorted order.

NOTE: Since the data is stored in the vector, reference returned from the various accessor functions will not be valid longterm. If an insert causes the vector to be resized, all references returned before that reallocation may (likely will) be invalid. References are only guaranteed to be valid until the next write to the data structure.

Constructor & Destructor Documentation

template<typename keyT, typename classT = keyT>
SST::SparseVectorMap< keyT, classT >::SparseVectorMap ( std::vector< classT > &  new_data,
bool  sorted = false 
)
inline

Constructor that allows you to pass an already filled in array with data.

The data in the passed in vector will be swapped into the data vector of the sparsevectormap and the passed in vector will be empty.

Parameters
new_dataVector of data to swap into the sparsevectormap data
sortedSpecifies whether the vector is already sorted in ascending order. if not, it will be sorted after swapping the data in.

Member Function Documentation

template<typename keyT, typename classT = keyT>
iterator SST::SparseVectorMap< keyT, classT >::begin ( )
inline
template<typename keyT, typename classT = keyT>
const_iterator SST::SparseVectorMap< keyT, classT >::begin ( ) const
inline

Returns the const begin iterator to the underlying vector.

Returns
const begin iterator to data vector
template<typename keyT, typename classT = keyT>
bool SST::SparseVectorMap< keyT, classT >::contains ( keyT  id) const
inline

Checks if the provided id is found in the SparseVectorMap.

Parameters
idid to check for
Returns
true if id is found, false otherwise
template<typename keyT, typename classT = keyT>
iterator SST::SparseVectorMap< keyT, classT >::end ( )
inline
template<typename keyT, typename classT = keyT>
const_iterator SST::SparseVectorMap< keyT, classT >::end ( ) const
inline

Returns the const end iterator to the underlying vector.

Returns
const end iterator to data vector
template<typename keyT, typename classT = keyT>
classT& SST::SparseVectorMap< keyT, classT >::insert ( const classT &  val)
inline

Insert new value into SparseVectorMap.

The inserted class must have a key() function with return type keyT.

Parameters
valvalue to add to SparseVectorMap
Returns
reference to the inserted item, or to the existing item if it was already present in the map.

Referenced by SST::IMPL::Partition::SimplePartitioner::performPartition().

template<typename keyT, typename classT = keyT>
classT& SST::SparseVectorMap< keyT, classT >::operator[] ( keyT  id)
inline

Operator returns a reference to data with the specified id.

Value can be modified. This will only return references to existing values, you must use insert() for new values.

Parameters
idid of the value to return (value returned by key())
Returns
reference to the requested item.
template<typename keyT, typename classT = keyT>
const classT& SST::SparseVectorMap< keyT, classT >::operator[] ( keyT  id) const
inline

Operator returns a const reference to data with the specified id.

Value cannot be modified. This will only return references to existing values, you must use insert() for new values.

Parameters
idid of the value to return (value returned by key())
Returns
const reference to the requested item.
template<typename keyT, typename classT = keyT>
size_t SST::SparseVectorMap< keyT, classT >::size ( )
inline

Returns the number of items in the SparseVectorMap.

Returns
number of items

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