SST  12.0.0
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 (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...
 
template<typename filterT >
void filter (filterT &filt)
 Function to filter the contents of the SparseVectorMap. More...
 

Friends

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

Detailed Description

template<typename keyT, typename classT>
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 >
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 >
iterator SST::SparseVectorMap< keyT, classT * >::begin ( )
inline

Returns the begin iterator to the underlying vector.

Returns
begin iterator to data vector
template<typename keyT , typename classT >
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 >
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 >
iterator SST::SparseVectorMap< keyT, classT * >::end ( )
inline

Returns the end iterator to the underlying vector.

Returns
end iterator to data vector
template<typename keyT , typename classT >
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 >
template<typename filterT >
void SST::SparseVectorMap< keyT, classT * >::filter ( filterT &  filt)
inline

Function to filter the contents of the SparseVectorMap.

Takes an object with an overloaded operator() function that takes as argument the current item. The funtion returns the object that should take the place of this object (value returned by key() function must be same for both objects), or returns nullptr if the object should be deleted. When an item is deleted, the size of the map reduces by 1.

Parameters
filtFilter object to use for filtering contents of map
Exceptions
bad_filtered_key_errorfilter returned an object that didn't return the same value on a call to key() as the original object in the map.
template<typename keyT , typename classT >
classT* SST::SparseVectorMap< keyT, classT * >::insert ( 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.
template<typename keyT , typename classT >
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 >
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 >
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: