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>
25 template <
typename keyT,
typename classT = keyT>
30 std::vector<classT> data;
31 int binary_search_insert(keyT
id)
const
36 int size = data.size();
39 if ( size == 0 )
return 0;
40 if (
id < data[0].key() )
return 0;
41 if (
id > data[size-1].key() )
return size;
47 while ( bottom <= top ) {
48 middle = bottom + (top - bottom) / 2;
49 if (
id == data[middle].key() )
return -1;
50 if (
id < data[middle].key() ) {
54 if (
id > data[middle-1].key() )
return middle;
67 int binary_search_find(keyT
id)
const
70 int top = data.size() - 1;
73 if ( data.size() == 0 )
return -1;
74 while (bottom <= top) {
75 middle = bottom + ( top - bottom ) / 2;
76 if (
id == data[middle].key() )
return middle;
77 else if (
id < data[middle].key() ) top = middle - 1;
78 else bottom = middle + 1;
86 typedef typename std::vector<classT>::iterator iterator;
87 typedef typename std::vector<classT>::const_iterator const_iterator;
92 void push_back(
const classT& val)
96 if ( data.size() == 0 ) {
100 if ( val.key() > data[data.size()-1].key() ) {
109 void insert(
const classT& val)
111 int index = binary_search_insert(val.key());
112 if ( index == -1 )
return;
113 iterator it = data.begin();
115 data.insert(it, val);
118 iterator begin() {
return data.begin(); }
119 iterator end() {
return data.end(); }
121 const_iterator begin()
const {
return data.begin(); }
122 const_iterator end()
const {
return data.end(); }
124 bool contains(keyT
id)
const
126 if ( binary_search_find(
id) == -1 )
return false;
130 classT& operator[] (keyT
id)
132 int index = binary_search_find(
id);
139 const classT& operator[] (keyT
id)
const
141 int index = binary_search_find(
id);
148 void clear() { data.clear(); }
149 size_t size() {
return data.size(); }
153 template <
typename keyT>
158 std::vector<keyT> data;
159 int binary_search_insert(keyT
id)
const
164 int size = data.size();
167 if ( size == 0 )
return 0;
168 if (
id < data[0] )
return 0;
169 if (
id > data[size-1] )
return size;
175 while ( bottom <= top ) {
176 middle = bottom + (top - bottom) / 2;
177 if (
id == data[middle] )
return -1;
178 if (
id < data[middle] ) {
182 if (
id > data[middle-1] )
return middle;
195 int binary_search_find(keyT
id)
const
198 int top = data.size() - 1;
201 if ( data.size() == 0 )
return -1;
202 while (bottom <= top) {
203 middle = bottom + ( top - bottom ) / 2;
204 if (
id == data[middle] )
return middle;
205 else if (
id < data[middle] ) top = middle - 1;
206 else bottom = middle + 1;
214 typedef typename std::vector<keyT>::iterator iterator;
215 typedef typename std::vector<keyT>::const_iterator const_iterator;
220 void push_back(
const keyT& val)
224 if ( data.size() == 0 ) {
228 if ( val.key() > data[data.size()-1].key() ) {
237 void insert(
const keyT& val)
239 int index = binary_search_insert(val);
240 if ( index == -1 )
return;
241 iterator it = data.begin();
243 data.insert(it, val);
246 iterator begin() {
return data.begin(); }
247 iterator end() {
return data.end(); }
249 const_iterator begin()
const {
return data.begin(); }
250 const_iterator end()
const {
return data.end(); }
252 bool contains(keyT
id)
254 if ( binary_search_find(
id) == -1 )
return false;
258 keyT& operator[] (keyT
id)
260 int index = binary_search_find(
id);
267 const keyT& operator[] (keyT
id)
const
269 int index = binary_search_find(
id);
276 void clear() { data.clear(); }
277 size_t size() {
return data.size(); }
287 namespace Serialization {
289 template <
typename keyT,
typename classT>
302 #endif // SST_CORE_CONFIGGRAPH_H
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:35
A Configuration Graph A graph representing Components and Links.
Definition: configGraph.h:294
Base serialize class.
Definition: serialize.h:33
Definition: sparseVectorMap.h:26