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(); }
286 template <
typename keyT,
typename classT>
300 std::vector<classT*> data;
301 int binary_search_insert(keyT
id)
const
306 int size = data.size();
309 if ( size == 0 )
return 0;
310 if (
id > data[size - 1]->key() )
return size;
311 if (
id < data[0]->key() )
return 0;
317 while ( bottom <= top ) {
318 middle = bottom + (top - bottom) / 2;
319 if (
id == data[middle]->key() )
return -1;
320 if (
id < data[middle]->key() ) {
324 if (
id > data[middle - 1]->key() )
347 int binary_search_find(keyT
id)
const
350 int top = data.size() - 1;
353 if ( data.size() == 0 )
return -1;
354 while ( bottom <= top ) {
355 middle = bottom + (top - bottom) / 2;
356 if (
id == data[middle]->key() )
358 else if (
id < data[middle]->key() )
391 std::sort(data.begin(), data.end, [](
const classT* lhs,
const classT* rhs) ->
bool {
392 return lhs->key() < rhs->key();
397 typedef typename std::vector<classT*>::iterator iterator;
398 typedef typename std::vector<classT*>::const_iterator const_iterator;
412 int index = binary_search_insert(val->key());
413 if ( index == -1 )
return data[binary_search_find(val->key())];
414 iterator it = data.begin();
416 data.insert(it, val);
425 iterator
begin() {
return data.begin(); }
432 iterator
end() {
return data.end(); }
439 const_iterator
begin()
const {
return data.begin(); }
446 const_iterator
end()
const {
return data.end(); }
457 if ( binary_search_find(
id) == -1 )
return false;
473 int index = binary_search_find(
id);
493 int index = binary_search_find(
id);
510 size_t size() {
return data.size(); }
519 template <
typename keyT>
533 std::vector<keyT> data;
534 int binary_search_insert(keyT
id)
const
539 int size = data.size();
542 if ( size == 0 )
return 0;
543 if (
id < data[0] )
return 0;
544 if (
id > data[size - 1] )
return size;
550 while ( bottom <= top ) {
551 middle = bottom + (top - bottom) / 2;
552 if (
id == data[middle] )
return -1;
553 if (
id < data[middle] ) {
557 if (
id > data[middle - 1] )
580 int binary_search_find(keyT
id)
const
583 int top = data.size() - 1;
586 if ( data.size() == 0 )
return -1;
587 while ( bottom <= top ) {
588 middle = bottom + (top - bottom) / 2;
589 if (
id == data[middle] )
591 else if (
id < data[middle] )
624 std::sort(data.begin(), data.end, [](
const keyT& lhs,
const keyT& rhs) ->
bool {
return lhs < rhs; });
628 typedef typename std::vector<keyT>::iterator iterator;
629 typedef typename std::vector<keyT>::const_iterator const_iterator;
643 int index = binary_search_insert(val);
644 if ( index == -1 )
return data[binary_search_find(val)];
645 iterator it = data.begin();
647 data.insert(it, val);
656 iterator
begin() {
return data.begin(); }
663 iterator
end() {
return data.end(); }
670 const_iterator
begin()
const {
return data.begin(); }
677 const_iterator
end()
const {
return data.end(); }
688 if ( binary_search_find(
id) == -1 )
return false;
704 int index = binary_search_find(
id);
724 int index = binary_search_find(
id);
741 size_t size() {
return data.size(); }
748 namespace Serialization {
750 template <
typename keyT,
typename classT>
760 #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:491
iterator end()
Returns the end iterator to the underlying vector.
Definition: sparseVectorMap.h:663
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:432
const_iterator end() const
Returns the const end iterator to the underlying vector.
Definition: sparseVectorMap.h:446
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:686
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:471
A Configuration Graph A graph representing Components and Links.
Definition: configGraph.h:375
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:677
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:722
size_t size()
Returns the number of items in the SparseVectorMap.
Definition: sparseVectorMap.h:510
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:702
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:620
iterator begin()
Returns the begin iterator to the underlying vector.
Definition: sparseVectorMap.h:425
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:387
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:656
bool contains(keyT id) const
Checks if the provided id is found in the SparseVectorMap.
Definition: sparseVectorMap.h:455
keyT & insert(const keyT &val)
Insert new value into SparseVectorMap.
Definition: sparseVectorMap.h:641
size_t size()
Returns the number of items in the SparseVectorMap.
Definition: sparseVectorMap.h:741
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:605
const_iterator begin() const
Returns the const begin iterator to the underlying vector.
Definition: sparseVectorMap.h:439
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:670
void clear()
Clears the contents of the SparseVectorMap.
Definition: sparseVectorMap.h:734
SparseVectorMap()
Default constructor for SparseVectorMap.
Definition: sparseVectorMap.h:372
void clear()
Clears the contents of the SparseVectorMap.
Definition: sparseVectorMap.h:259
classT * insert(classT *val)
Insert new value into SparseVectorMap.
Definition: sparseVectorMap.h:410
void clear()
Clears the contents of the SparseVectorMap.
Definition: sparseVectorMap.h:503