14 #ifndef SST_CORE_SPARSEVECTORMAP_H
15 #define SST_CORE_SPARSEVECTORMAP_H
17 #include "sst/core/sst_types.h"
18 #include "sst/core/serialization/serializable.h"
42 template <
typename keyT,
typename classT = keyT>
55 std::vector<classT> data;
56 int binary_search_insert(keyT
id)
const
61 int size = data.size();
64 if ( size == 0 )
return 0;
65 if (
id > data[size-1].key() )
return size;
66 if (
id < data[0].key() )
return 0;
72 while ( bottom <= top ) {
73 middle = bottom + (top - bottom) / 2;
74 if (
id == data[middle].key() )
return -1;
75 if (
id < data[middle].key() ) {
79 if (
id > data[middle-1].key() )
return middle;
101 int binary_search_find(keyT
id)
const
104 int top = data.size() - 1;
107 if ( data.size() == 0 )
return -1;
108 while (bottom <= top) {
109 middle = bottom + ( top - bottom ) / 2;
110 if (
id == data[middle].key() )
return middle;
111 else if (
id < data[middle].key() ) top = middle - 1;
112 else bottom = middle + 1;
143 std::sort(data.begin(),data.end,
144 [] (
const classT& lhs,
const classT& rhs) ->
bool
146 return lhs.key() < rhs.key();
151 typedef typename std::vector<classT>::iterator iterator;
152 typedef typename std::vector<classT>::const_iterator const_iterator;
167 int index = binary_search_insert(val.key());
168 if ( index == -1 )
return data[binary_search_find(val.key())];
169 iterator it = data.begin();
171 data.insert(it, val);
180 iterator
begin() {
return data.begin(); }
187 iterator
end() {
return data.end(); }
194 const_iterator
begin()
const {
return data.begin(); }
201 const_iterator
end()
const {
return data.end(); }
212 if ( binary_search_find(
id) == -1 )
return false;
228 int index = binary_search_find(
id);
248 int index = binary_search_find(
id);
265 size_t size() {
return data.size(); }
287 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() )
return middle;
346 int binary_search_find(keyT
id)
const
349 int top = data.size() - 1;
352 if ( data.size() == 0 )
return -1;
353 while (bottom <= top) {
354 middle = bottom + ( top - bottom ) / 2;
355 if (
id == data[middle]->key() )
return middle;
356 else if (
id < data[middle]->key() ) top = middle - 1;
357 else bottom = middle + 1;
388 std::sort(data.begin(),data.end,
389 [] (
const classT* lhs,
const classT* rhs) ->
bool
391 return lhs->key() < rhs->key();
396 typedef typename std::vector<classT*>::iterator iterator;
397 typedef typename std::vector<classT*>::const_iterator const_iterator;
411 int index = binary_search_insert(val->key());
412 if ( index == -1 )
return data[binary_search_find(val->key())];
413 iterator it = data.begin();
415 data.insert(it, val);
424 iterator
begin() {
return data.begin(); }
431 iterator
end() {
return data.end(); }
438 const_iterator
begin()
const {
return data.begin(); }
445 const_iterator
end()
const {
return data.end(); }
456 if ( binary_search_find(
id) == -1 )
return false;
470 classT* operator[] (keyT
id)
472 int index = binary_search_find(
id);
490 const classT* operator[] (keyT
id)
const
492 int index = binary_search_find(
id);
509 size_t size() {
return data.size(); }
520 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] )
return middle;
579 int binary_search_find(keyT
id)
const
582 int top = data.size() - 1;
585 if ( data.size() == 0 )
return -1;
586 while (bottom <= top) {
587 middle = bottom + ( top - bottom ) / 2;
588 if (
id == data[middle] )
return middle;
589 else if (
id < data[middle] ) top = middle - 1;
590 else bottom = middle + 1;
621 std::sort(data.begin(),data.end,
622 [] (
const keyT& lhs,
const keyT& rhs) ->
bool
630 typedef typename std::vector<keyT>::iterator iterator;
631 typedef typename std::vector<keyT>::const_iterator const_iterator;
645 int index = binary_search_insert(val);
646 if ( index == -1 )
return data[binary_search_find(val)];
647 iterator it = data.begin();
649 data.insert(it, val);
658 iterator
begin() {
return data.begin(); }
665 iterator
end() {
return data.end(); }
672 const_iterator
begin()
const {
return data.begin(); }
679 const_iterator
end()
const {
return data.end(); }
690 if ( binary_search_find(
id) == -1 )
return false;
706 int index = binary_search_find(
id);
726 int index = binary_search_find(
id);
743 size_t size() {
return data.size(); }
753 namespace Serialization {
755 template <
typename keyT,
typename classT>
768 #endif // SST_CORE_CONFIGGRAPH_H
iterator end()
Returns the end iterator to the underlying vector.
Definition: sparseVectorMap.h:665
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:35
const_iterator begin() const
Returns the const begin iterator to the underlying vector.
Definition: sparseVectorMap.h:194
iterator end()
Returns the end iterator to the underlying vector.
Definition: sparseVectorMap.h:431
const_iterator end() const
Returns the const end iterator to the underlying vector.
Definition: sparseVectorMap.h:445
classT & operator[](keyT id)
Operator returns a reference to data with the specified id.
Definition: sparseVectorMap.h:226
bool contains(keyT id)
Checks if the provided id is found in the SparseVectorMap.
Definition: sparseVectorMap.h:688
classT & insert(const classT &val)
Insert new value into SparseVectorMap.
Definition: sparseVectorMap.h:165
A Configuration Graph A graph representing Components and Links.
Definition: configGraph.h:358
iterator end()
Returns the end iterator to the underlying vector.
Definition: sparseVectorMap.h:187
const_iterator end() const
Returns the const end iterator to the underlying vector.
Definition: sparseVectorMap.h:679
iterator begin()
Returns the begin iterator to the underlying vector.
Definition: sparseVectorMap.h:180
size_t size()
Returns the number of items in the SparseVectorMap.
Definition: sparseVectorMap.h:509
size_t size()
Returns the number of items in the SparseVectorMap.
Definition: sparseVectorMap.h:265
Base serialize class.
Definition: serialize.h:33
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:617
iterator begin()
Returns the begin iterator to the underlying vector.
Definition: sparseVectorMap.h:424
const_iterator end() const
Returns the const end iterator to the underlying vector.
Definition: sparseVectorMap.h:201
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:384
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:139
iterator begin()
Returns the begin iterator to the underlying vector.
Definition: sparseVectorMap.h:658
bool contains(keyT id) const
Checks if the provided id is found in the SparseVectorMap.
Definition: sparseVectorMap.h:454
keyT & insert(const keyT &val)
Insert new value into SparseVectorMap.
Definition: sparseVectorMap.h:643
size_t size()
Returns the number of items in the SparseVectorMap.
Definition: sparseVectorMap.h:743
SparseVectorMap()
Default constructor for SparseVectorMap.
Definition: sparseVectorMap.h:124
bool contains(keyT id) const
Checks if the provided id is found in the SparseVectorMap.
Definition: sparseVectorMap.h:210
SparseVectorMap()
Default constructor for SparseVectorMap.
Definition: sparseVectorMap.h:602
const_iterator begin() const
Returns the const begin iterator to the underlying vector.
Definition: sparseVectorMap.h:438
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:672
void clear()
Clears the contents of the SparseVectorMap.
Definition: sparseVectorMap.h:736
SparseVectorMap()
Default constructor for SparseVectorMap.
Definition: sparseVectorMap.h:369
void clear()
Clears the contents of the SparseVectorMap.
Definition: sparseVectorMap.h:258
classT * insert(classT *val)
Insert new value into SparseVectorMap.
Definition: sparseVectorMap.h:409
void clear()
Clears the contents of the SparseVectorMap.
Definition: sparseVectorMap.h:502