14 #ifndef SST_CORE_SPARSEVECTORMAP_H
15 #define SST_CORE_SPARSEVECTORMAP_H
17 #include "sst/core/serialization/serializable.h"
18 #include "sst/core/sst_types.h"
42 template <
typename keyT,
typename classT = keyT>
56 std::vector<classT> data;
57 int binary_search_insert(keyT
id)
const
62 int size = data.size();
65 if ( size == 0 )
return 0;
66 if (
id > data[size - 1].key() )
return size;
67 if (
id < data[0].key() )
return 0;
73 while ( bottom <= top ) {
74 middle = bottom + (top - bottom) / 2;
75 if (
id == data[middle].key() )
return -1;
76 if (
id < data[middle].key() ) {
80 if (
id > data[middle - 1].key() )
103 int binary_search_find(keyT
id)
const
106 int top = data.size() - 1;
109 if ( data.size() == 0 )
return -1;
110 while ( bottom <= top ) {
111 middle = bottom + (top - bottom) / 2;
112 if (
id == data[middle].key() )
114 else if (
id < data[middle].key() )
147 std::sort(data.begin(), data.end, [](
const classT& lhs,
const classT& rhs) ->
bool {
148 return lhs.key() < rhs.key();
153 typedef typename std::vector<classT>::iterator iterator;
154 typedef typename std::vector<classT>::const_iterator const_iterator;
168 int index = binary_search_insert(val.key());
169 if ( index == -1 )
return data[binary_search_find(val.key())];
170 iterator it = data.begin();
172 data.insert(it, val);
181 iterator
begin() {
return data.begin(); }
188 iterator
end() {
return data.end(); }
195 const_iterator
begin()
const {
return data.begin(); }
202 const_iterator
end()
const {
return data.end(); }
213 if ( binary_search_find(
id) == -1 )
return false;
229 int index = binary_search_find(
id);
249 int index = binary_search_find(
id);
266 size_t size() {
return data.size(); }
299 template <
typename keyT,
typename classT>
313 std::vector<classT*> data;
314 int binary_search_insert(keyT
id)
const
319 int size = data.size();
322 if ( size == 0 )
return 0;
323 if (
id > data[size - 1]->key() )
return size;
324 if (
id < data[0]->key() )
return 0;
330 while ( bottom <= top ) {
331 middle = bottom + (top - bottom) / 2;
332 if (
id == data[middle]->key() )
return -1;
333 if (
id < data[middle]->key() ) {
337 if (
id > data[middle - 1]->key() )
360 int binary_search_find(keyT
id)
const
363 int top = data.size() - 1;
366 if ( data.size() == 0 )
return -1;
367 while ( bottom <= top ) {
368 middle = bottom + (top - bottom) / 2;
369 if (
id == data[middle]->key() )
371 else if (
id < data[middle]->key() )
404 std::sort(data.begin(), data.end, [](
const classT* lhs,
const classT* rhs) ->
bool {
405 return lhs->key() < rhs->key();
410 typedef typename std::vector<classT*>::iterator iterator;
411 typedef typename std::vector<classT*>::const_iterator const_iterator;
425 int index = binary_search_insert(val->key());
426 if ( index == -1 )
return data[binary_search_find(val->key())];
427 iterator it = data.begin();
429 data.insert(it, val);
438 iterator
begin() {
return data.begin(); }
445 iterator
end() {
return data.end(); }
452 const_iterator
begin()
const {
return data.begin(); }
459 const_iterator
end()
const {
return data.end(); }
470 if ( binary_search_find(
id) == -1 )
return false;
486 int index = binary_search_find(
id);
506 int index = binary_search_find(
id);
523 size_t size() {
return data.size(); }
541 template <
typename filterT>
545 for (
size_t i = 0; i < data.size(); ++i ) {
546 auto key = data[i]->key();
547 data[write_ptr] = filt(data[i]);
548 if ( data[write_ptr] !=
nullptr ) {
550 if ( UNLIKELY(data[write_ptr]->key() != key) ) {
553 "ERROR: Filter object passed to SparseVectorMap::filter returned an object that had a "
554 "different value of key() than what was passed into the filter. The filter object must return "
555 "either an object with the same value of key(), or nullptr if the object should be removed.");
565 data.resize(write_ptr);
566 data.shrink_to_fit();
576 template <
typename keyT>
590 std::vector<keyT> data;
591 int binary_search_insert(keyT
id)
const
596 int size = data.size();
599 if ( size == 0 )
return 0;
600 if (
id < data[0] )
return 0;
601 if (
id > data[size - 1] )
return size;
607 while ( bottom <= top ) {
608 middle = bottom + (top - bottom) / 2;
609 if (
id == data[middle] )
return -1;
610 if (
id < data[middle] ) {
614 if (
id > data[middle - 1] )
637 int binary_search_find(keyT
id)
const
640 int top = data.size() - 1;
643 if ( data.size() == 0 )
return -1;
644 while ( bottom <= top ) {
645 middle = bottom + (top - bottom) / 2;
646 if (
id == data[middle] )
648 else if (
id < data[middle] )
681 std::sort(data.begin(), data.end, [](
const keyT& lhs,
const keyT& rhs) ->
bool {
return lhs < rhs; });
685 typedef typename std::vector<keyT>::iterator iterator;
686 typedef typename std::vector<keyT>::const_iterator const_iterator;
700 int index = binary_search_insert(val);
701 if ( index == -1 )
return data[binary_search_find(val)];
702 iterator it = data.begin();
704 data.insert(it, val);
713 iterator
begin() {
return data.begin(); }
720 iterator
end() {
return data.end(); }
727 const_iterator
begin()
const {
return data.begin(); }
734 const_iterator
end()
const {
return data.end(); }
745 if ( binary_search_find(
id) == -1 )
return false;
761 int index = binary_search_find(
id);
781 int index = binary_search_find(
id);
798 size_t size() {
return data.size(); }
805 namespace Serialization {
807 template <
typename keyT,
typename classT>
817 #endif // SST_CORE_SPARSEVECTORMAP_H
const classT * operator[](keyT id) const
Operator returns a const reference to data with the specified id.
Definition: sparseVectorMap.h:504
iterator end()
Returns the end iterator to the underlying vector.
Definition: sparseVectorMap.h:720
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:34
const_iterator begin() const
Returns the const begin iterator to the underlying vector.
Definition: sparseVectorMap.h:195
iterator end()
Returns the end iterator to the underlying vector.
Definition: sparseVectorMap.h:445
const_iterator end() const
Returns the const end iterator to the underlying vector.
Definition: sparseVectorMap.h:459
classT & operator[](keyT id)
Operator returns a reference to data with the specified id.
Definition: sparseVectorMap.h:227
bool contains(keyT id)
Checks if the provided id is found in the SparseVectorMap.
Definition: sparseVectorMap.h:743
classT & insert(const classT &val)
Insert new value into SparseVectorMap.
Definition: sparseVectorMap.h:166
classT * operator[](keyT id)
Operator returns a reference to data with the specified id.
Definition: sparseVectorMap.h:484
A Configuration Graph A graph representing Components and Links.
Definition: configGraph.h:389
iterator end()
Returns the end iterator to the underlying vector.
Definition: sparseVectorMap.h:188
const_iterator end() const
Returns the const end iterator to the underlying vector.
Definition: sparseVectorMap.h:734
iterator begin()
Returns the begin iterator to the underlying vector.
Definition: sparseVectorMap.h:181
const keyT & operator[](keyT id) const
Operator returns a const reference to data with the specified id.
Definition: sparseVectorMap.h:779
size_t size()
Returns the number of items in the SparseVectorMap.
Definition: sparseVectorMap.h:523
size_t size()
Returns the number of items in the SparseVectorMap.
Definition: sparseVectorMap.h:266
Base serialize class.
Definition: serialize.h:31
const classT & operator[](keyT id) const
Operator returns a const reference to data with the specified id.
Definition: sparseVectorMap.h:247
keyT & operator[](keyT id)
Operator returns a reference to data with the specified id.
Definition: sparseVectorMap.h:759
void filter(filterT &filt)
Function to filter the contents of the SparseVectorMap.
Definition: sparseVectorMap.h:542
SparseVectorMap(std::vector< keyT > &new_data, bool sorted=false)
Constructor that allows you to pass an already filled in array with data.
Definition: sparseVectorMap.h:677
iterator begin()
Returns the begin iterator to the underlying vector.
Definition: sparseVectorMap.h:438
const_iterator end() const
Returns the const end iterator to the underlying vector.
Definition: sparseVectorMap.h:202
SparseVectorMap(std::vector< classT * > &new_data, bool sorted=false)
Constructor that allows you to pass an already filled in array with data.
Definition: sparseVectorMap.h:400
SparseVectorMap(std::vector< classT > &new_data, bool sorted=false)
Constructor that allows you to pass an already filled in array with data.
Definition: sparseVectorMap.h:143
iterator begin()
Returns the begin iterator to the underlying vector.
Definition: sparseVectorMap.h:713
bool contains(keyT id) const
Checks if the provided id is found in the SparseVectorMap.
Definition: sparseVectorMap.h:468
keyT & insert(const keyT &val)
Insert new value into SparseVectorMap.
Definition: sparseVectorMap.h:698
size_t size()
Returns the number of items in the SparseVectorMap.
Definition: sparseVectorMap.h:798
SparseVectorMap()
Default constructor for SparseVectorMap.
Definition: sparseVectorMap.h:128
bool contains(keyT id) const
Checks if the provided id is found in the SparseVectorMap.
Definition: sparseVectorMap.h:211
SparseVectorMap()
Default constructor for SparseVectorMap.
Definition: sparseVectorMap.h:662
const_iterator begin() const
Returns the const begin iterator to the underlying vector.
Definition: sparseVectorMap.h:452
Class that stores data in a vector, but can access the data similar to a map.
Definition: sparseVectorMap.h:43
const_iterator begin() const
Returns the const begin iterator to the underlying vector.
Definition: sparseVectorMap.h:727
void clear()
Clears the contents of the SparseVectorMap.
Definition: sparseVectorMap.h:791
Exception that is thrown by SparseVectorMap::filter() if the filtering object returns an object that ...
Definition: sparseVectorMap.h:275
SparseVectorMap()
Default constructor for SparseVectorMap.
Definition: sparseVectorMap.h:385
void clear()
Clears the contents of the SparseVectorMap.
Definition: sparseVectorMap.h:259
classT * insert(classT *val)
Insert new value into SparseVectorMap.
Definition: sparseVectorMap.h:423
void clear()
Clears the contents of the SparseVectorMap.
Definition: sparseVectorMap.h:516