The Sparta Modeling Framework
Loading...
Searching...
No Matches
sparta::Array< DataT, ArrayT > Class Template Reference

Array is essentially a fixed size vector, maintains a concept of validity of its indexes, and provides access via stl iteration and general get methods. More...

#include <Array.hpp>

Inheritance diagram for sparta::Array< DataT, ArrayT >:

Classes

struct  ArrayIterator
 An iterator struct for this array. More...
 

Public Types

typedef DataT value_type
 The data type, STL style.
 
typedef DataT DataType
 Expected typedef for the data that will be stored in this structure.
 
typedef uint32_t size_type
 Typedef for size_type.
 
typedef std::list< uint32_t > AgedList
 Typedef for a list of indexes in age order.
 
typedef ArrayIterator< false > iterator
 Typedef for regular iterator.
 
typedef ArrayIterator< true > const_iterator
 Typedef for constant iterator.
 

Public Member Functions

iterator getCircularIterator (uint32_t idx=0)
 Get an iterator that is circular on the Array (has no end())
 
iterator getUnitializedIterator ()
 Provide a method to get an uninitialized iterator.
 
iterator begin ()
 STL-like begin operation, starts at index 0 (ignores valid bit).
 
const_iterator begin () const
 STL-like begin operation, const, starts at index 0 (ignores valid bit).
 
iterator end ()
 STL-like end operation.
 
const_iterator end () const
 STL-like end operation, const.
 
iterator abegin ()
 STL-like begin operation, starts at the oldest valid index.
 
const_iterator abegin () const
 STL-like begin operation, const, starts at the oldest valid index.
 
iterator aend ()
 STL-like end operation.
 
const_iterator aend () const
 STL-like end operation, const.
 
 Array (const std::string &name, uint32_t num_entries, const Clock *clk, StatisticSet *statset=nullptr, InstrumentationNode::visibility_t stat_vis_general=InstrumentationNode::AUTO_VISIBILITY, InstrumentationNode::visibility_t stat_vis_detailed=InstrumentationNode::VIS_HIDDEN, InstrumentationNode::visibility_t stat_vis_max=InstrumentationNode::AUTO_VISIBILITY, InstrumentationNode::visibility_t stat_vis_avg=InstrumentationNode::AUTO_VISIBILITY)
 Construct an array.
 
virtual ~Array ()
 Virtual destructor.
 
const std::string & getName () const
 Name of this resource.
 
bool isValid (const uint32_t idx) const
 Determine whether an index is currently valid.
 
const DataT & read (const uint32_t idx) const
 Read (only) the data at an index.
 
DataT & access (const uint32_t idx)
 Access (writeable) the data at a position.
 
const_iterator getOldestIndex (const uint32_t nth=0) const
 Return the oldest index in the array.
 
const_iterator getYoungestIndex (const uint32_t nth=0) const
 provide access the youngest index in the array.
 
bool getNextOldestIndex (uint32_t &prev_idx) const
 Sets the input argument to the index containing the location of the next oldest item after input argument. If the input argument is the youngest index, we return false.
 
uint32_t getAge (const uint32_t idx) const
 Provide the age information of the given entry index.
 
const AgedListgetAgedList () const
 Provide access to our aged_list_ internals.
 
size_type capacity () const
 Return the maximum number of elements this Array can hold.
 
size_type numValid () const
 The number of valid entries contained.
 
size_type size () const
 
size_type numFree () const
 The number of free entries.
 
void erase (const iterator &iter)
 Invalidate data at an iterator position.
 
void erase (const uint32_t &idx)
 Invalidate the entry at a certain index.
 
void clear ()
 Clear the array of all data.
 
void write (const uint32_t idx, const DataT &dat)
 Write data to the array.
 
void write (const uint32_t idx, DataT &&dat)
 Write data to the array.
 
void write (const iterator &iter, const DataT &dat)
 Write data at an iterator position.
 
void write (const iterator &iter, DataT &&dat)
 Write data at an iterator position.
 
bool isYounger (uint32_t lhs, uint32_t rhs)
 Determine if an index was written (using write()) to the Array after another index.
 
bool isOlder (uint32_t lhs, uint32_t rhs)
 Determine if an index was written (using write()) to the Array before another index.
 
void enableCollection (TreeNode *parent)
 Set up a auto-collector for this Array.
 

Detailed Description

template<class DataT, ArrayType ArrayT = ArrayType::AGED>
class sparta::Array< DataT, ArrayT >

Array is essentially a fixed size vector, maintains a concept of validity of its indexes, and provides access via stl iteration and general get methods.

Template Parameters
DataTthe data type stored in the Array.
ArrayTthe type of array ArrayType::AGED vs ArrayType::NORMAL

The Array class maintains a list of elements, constrained to the number of entries, allowing a user to add/remove entries from the middle, beginning, or end without collapsing. If the template parameter ArrayType::AGED is provided (default), the array will keep track of the age of the internal components.

The methods begin() and end() will return iterators to the array, with begin() always returning an iterator pointing to index 0 and end() pointing beyond it. The iterator might not be pointing to valid data, so a call to isValid() on the iterator is required before dereferencing.

To iterator over the aged list, use the methods abegin() and aend().

Definition at line 57 of file Array.hpp.

Member Typedef Documentation

◆ AgedList

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
typedef std::list<uint32_t> sparta::Array< DataT, ArrayT >::AgedList

Typedef for a list of indexes in age order.

Definition at line 96 of file Array.hpp.

◆ const_iterator

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
typedef ArrayIterator<true> sparta::Array< DataT, ArrayT >::const_iterator

Typedef for constant iterator.

Definition at line 379 of file Array.hpp.

◆ DataType

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
typedef DataT sparta::Array< DataT, ArrayT >::DataType

Expected typedef for the data that will be stored in this structure.

Definition at line 90 of file Array.hpp.

◆ iterator

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
typedef ArrayIterator<false> sparta::Array< DataT, ArrayT >::iterator

Typedef for regular iterator.

Definition at line 376 of file Array.hpp.

◆ size_type

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
typedef uint32_t sparta::Array< DataT, ArrayT >::size_type

Typedef for size_type.

Definition at line 93 of file Array.hpp.

◆ value_type

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
typedef DataT sparta::Array< DataT, ArrayT >::value_type

The data type, STL style.

Definition at line 87 of file Array.hpp.

Constructor & Destructor Documentation

◆ Array()

template<class DataT , ArrayType ArrayT>
sparta::Array< DataT, ArrayT >::Array ( const std::string &  name,
uint32_t  num_entries,
const Clock clk,
StatisticSet statset = nullptr,
InstrumentationNode::visibility_t  stat_vis_general = InstrumentationNode::AUTO_VISIBILITY,
InstrumentationNode::visibility_t  stat_vis_detailed = InstrumentationNode::VIS_HIDDEN,
InstrumentationNode::visibility_t  stat_vis_max = InstrumentationNode::AUTO_VISIBILITY,
InstrumentationNode::visibility_t  stat_vis_avg = InstrumentationNode::AUTO_VISIBILITY 
)

Construct an array.

Parameters
nameThe name of the buffer
num_entriesThe number of entries this buffer can hold
clkThe clock this buffer belongs to
statsetPointer to the counter set to register utilization counts; default nullptr. This works for timed and untimed.
stat_vis_generalSets the visibility of the stat counters for the 0th and last index of the utilization counts, so the empty and full counts.
stat_vis_detailedSets the visibility of the stat counts between 0 and the last index. i.e. more detailed than the general stats, default VIS_HIDDEN
stat_vis_maxSets the visibility for a stat that contains the maximum utilization for this buffer. The default is AUTO_VISIBILITY.
stat_vis_avgSets the visibility for a stat that contains the weighted utilization average for this buffer. The default is AUTO_VISIBILITY.
Warning
By default the stat_vis_* options are set to VIS_SPARTA_DEFAULT, for this structure AUTO_VISIBILITY resolves to CONTAINER_DEFAULT_VISIBILITY which at the time of writing this comment is set to VIS_HIDDEN. If you rely on the stats from this container you should explicitly set the visibility.

Definition at line 1020 of file Array.hpp.

◆ ~Array()

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
virtual sparta::Array< DataT, ArrayT >::~Array ( )
inlinevirtual

Virtual destructor.

Definition at line 526 of file Array.hpp.

Here is the call graph for this function:

Member Function Documentation

◆ abegin() [1/2]

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
iterator sparta::Array< DataT, ArrayT >::abegin ( )
inline

STL-like begin operation, starts at the oldest valid index.

Returns
iterator to the oldest entry in the array

Definition at line 441 of file Array.hpp.

Here is the call graph for this function:

◆ abegin() [2/2]

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
const_iterator sparta::Array< DataT, ArrayT >::abegin ( ) const
inline

STL-like begin operation, const, starts at the oldest valid index.

Returns
iterator to the oldest entry in the array

Definition at line 454 of file Array.hpp.

Here is the call graph for this function:

◆ access()

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
DataT & sparta::Array< DataT, ArrayT >::access ( const uint32_t  idx)
inline

Access (writeable) the data at a position.

Parameters
idxThe index to access.

Definition at line 560 of file Array.hpp.

Here is the call graph for this function:

◆ aend() [1/2]

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
iterator sparta::Array< DataT, ArrayT >::aend ( )
inline

STL-like end operation.

Returns
iterator to the element past the youngest entry

Definition at line 466 of file Array.hpp.

◆ aend() [2/2]

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
const_iterator sparta::Array< DataT, ArrayT >::aend ( ) const
inline

STL-like end operation, const.

Returns
iterator to the element one past the youngest entry

Definition at line 475 of file Array.hpp.

◆ begin() [1/2]

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
iterator sparta::Array< DataT, ArrayT >::begin ( )
inline

STL-like begin operation, starts at index 0 (ignores valid bit).

Returns
iterator to the beginning of the Array

Definition at line 405 of file Array.hpp.

◆ begin() [2/2]

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
const_iterator sparta::Array< DataT, ArrayT >::begin ( ) const
inline

STL-like begin operation, const, starts at index 0 (ignores valid bit).

Returns
iterator to the beginning of the Array

Definition at line 414 of file Array.hpp.

◆ capacity()

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
size_type sparta::Array< DataT, ArrayT >::capacity ( ) const
inline

Return the maximum number of elements this Array can hold.

Returns
The number of positions this array was constructed with

Definition at line 680 of file Array.hpp.

◆ clear()

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
void sparta::Array< DataT, ArrayT >::clear ( )
inline

Clear the array of all data.

Definition at line 748 of file Array.hpp.

◆ enableCollection()

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
void sparta::Array< DataT, ArrayT >::enableCollection ( TreeNode parent)
inline

Set up a auto-collector for this Array.

Parameters
parentthe parent tree node under which to create the collection

Definition at line 848 of file Array.hpp.

Here is the call graph for this function:

◆ end() [1/2]

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
iterator sparta::Array< DataT, ArrayT >::end ( )
inline

STL-like end operation.

Returns
iterator to the end of the Array, past the last element

Definition at line 423 of file Array.hpp.

◆ end() [2/2]

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
const_iterator sparta::Array< DataT, ArrayT >::end ( ) const
inline

STL-like end operation, const.

Returns
iterator to the end of the Array, past the last element

Definition at line 432 of file Array.hpp.

◆ erase() [1/2]

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
void sparta::Array< DataT, ArrayT >::erase ( const iterator iter)
inline

Invalidate data at an iterator position.

Parameters
iterAn iterator used to invalidate – must be valid

Definition at line 710 of file Array.hpp.

Here is the call graph for this function:

◆ erase() [2/2]

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
void sparta::Array< DataT, ArrayT >::erase ( const uint32_t &  idx)
inline

Invalidate the entry at a certain index.

Parameters
idxThe index to invalidate.

Definition at line 719 of file Array.hpp.

Here is the call graph for this function:

◆ getAge()

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
uint32_t sparta::Array< DataT, ArrayT >::getAge ( const uint32_t  idx) const
inline

Provide the age information of the given entry index.

Returns
The age of the index. The less, the older.

Definition at line 659 of file Array.hpp.

Here is the call graph for this function:

◆ getAgedList()

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
const AgedList & sparta::Array< DataT, ArrayT >::getAgedList ( ) const
inline

Provide access to our aged_list_ internals.

Definition at line 669 of file Array.hpp.

◆ getCircularIterator()

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
iterator sparta::Array< DataT, ArrayT >::getCircularIterator ( uint32_t  idx = 0)
inline

Get an iterator that is circular on the Array (has no end())

Parameters
idxWhere to start from
Returns
iterator type that a ++ will never == end()

Definition at line 386 of file Array.hpp.

◆ getName()

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
const std::string & sparta::Array< DataT, ArrayT >::getName ( ) const
inline

Name of this resource.

Definition at line 533 of file Array.hpp.

◆ getNextOldestIndex()

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
bool sparta::Array< DataT, ArrayT >::getNextOldestIndex ( uint32_t &  prev_idx) const
inline

Sets the input argument to the index containing the location of the next oldest item after input argument. If the input argument is the youngest index, we return false.

Definition at line 645 of file Array.hpp.

◆ getOldestIndex()

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
const_iterator sparta::Array< DataT, ArrayT >::getOldestIndex ( const uint32_t  nth = 0) const
inline

Return the oldest index in the array.

Parameters
nthIs the nth oldest entry you are looking for. nth=0 is the oldest entry, nth = 1 is the second oldest, etc..
Returns
the index of the nth oldest entry.
Warning
this method may be expensive for larger nth values. Low values should be very quick.
Note
This method is only accessible if the template parameter FullArrayType == AGED

Definition at line 578 of file Array.hpp.

Here is the call graph for this function:

◆ getUnitializedIterator()

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
iterator sparta::Array< DataT, ArrayT >::getUnitializedIterator ( )
inline

Provide a method to get an uninitialized iterator.

Definition at line 395 of file Array.hpp.

◆ getYoungestIndex()

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
const_iterator sparta::Array< DataT, ArrayT >::getYoungestIndex ( const uint32_t  nth = 0) const
inline

provide access the youngest index in the array.

Parameters
nthIs the nth youngest entry to be found. nth=0 is the youngest, nth=1 is the second youngest, etc.
Returns
the index of the nth youngest index.
Warning
this method may get expensive for larger nth values.
Note
This method is only accessible if the template parameter FullArrayType == AGED.

Definition at line 616 of file Array.hpp.

Here is the call graph for this function:

◆ isOlder()

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
bool sparta::Array< DataT, ArrayT >::isOlder ( uint32_t  lhs,
uint32_t  rhs 
)
inline

Determine if an index was written (using write()) to the Array before another index.

Parameters
lhsan index to compare.
rhsan index to compare.
Returns
true if lhs was written at less recently than rhs was written at.

Definition at line 836 of file Array.hpp.

◆ isValid()

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
bool sparta::Array< DataT, ArrayT >::isValid ( const uint32_t  idx) const
inline

Determine whether an index is currently valid.

Returns
true if valid.

Definition at line 541 of file Array.hpp.

◆ isYounger()

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
bool sparta::Array< DataT, ArrayT >::isYounger ( uint32_t  lhs,
uint32_t  rhs 
)
inline

Determine if an index was written (using write()) to the Array after another index.

Parameters
lhsan index to compare.
rhsan index to compare.
Returns
true if lhs was written more recently than rhs to the array.

Definition at line 821 of file Array.hpp.

◆ numFree()

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
size_type sparta::Array< DataT, ArrayT >::numFree ( ) const
inline

The number of free entries.

Returns
The number of free spaces in the array.

Definition at line 701 of file Array.hpp.

◆ numValid()

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
size_type sparta::Array< DataT, ArrayT >::numValid ( ) const
inline

The number of valid entries contained.

Returns
The number of valid elements in the array

Definition at line 688 of file Array.hpp.

◆ read()

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
const DataT & sparta::Array< DataT, ArrayT >::read ( const uint32_t  idx) const
inline

Read (only) the data at an index.

Parameters
idxthe index to access.
Returns
A const reference to the data.

Definition at line 550 of file Array.hpp.

Here is the call graph for this function:

◆ size()

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
size_type sparta::Array< DataT, ArrayT >::size ( ) const
inline
Returns
numValid() – function for stl compatibility.

Definition at line 693 of file Array.hpp.

Here is the call graph for this function:

◆ write() [1/4]

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
void sparta::Array< DataT, ArrayT >::write ( const iterator iter,
const DataT &  dat 
)
inline

Write data at an iterator position.

Parameters
iterThe iterator pointing to the data
datThe data to write at the iterator location

This will write to the location at iter, whether the iterator is valid or not.

Definition at line 796 of file Array.hpp.

Here is the call graph for this function:

◆ write() [2/4]

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
void sparta::Array< DataT, ArrayT >::write ( const iterator iter,
DataT &&  dat 
)
inline

Write data at an iterator position.

Parameters
iterThe iterator pointing to the data
datThe data to write at the iterator location

This will write to the location at iter, whether the iterator is valid or not.

Definition at line 809 of file Array.hpp.

Here is the call graph for this function:

◆ write() [3/4]

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
void sparta::Array< DataT, ArrayT >::write ( const uint32_t  idx,
const DataT &  dat 
)
inline

Write data to the array.

Parameters
idxThe index to write at
datThe data to write at that index.

This will write to the location at idx, whether the position is valid or not.

Definition at line 770 of file Array.hpp.

◆ write() [4/4]

template<class DataT , ArrayType ArrayT = ArrayType::AGED>
void sparta::Array< DataT, ArrayT >::write ( const uint32_t  idx,
DataT &&  dat 
)
inline

Write data to the array.

Parameters
idxThe index to write at
datThe data to write at that index.

This will write to the location at idx, whether the position is valid or not.

Definition at line 783 of file Array.hpp.


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