SST  15.1.0
StructuralSimulationToolkit
sparseVectorMap.h
1 // -*- c++ -*-
2 
3 // Copyright 2009-2025 NTESS. Under the terms
4 // of Contract DE-NA0003525 with NTESS, the U.S.
5 // Government retains certain rights in this software.
6 //
7 // Copyright (c) 2009-2025, NTESS
8 // All rights reserved.
9 //
10 // This file is part of the SST software package. For license
11 // information, see the LICENSE file in the top level directory of the
12 // distribution.
13 
14 #ifndef SST_CORE_SPARSEVECTORMAP_H
15 #define SST_CORE_SPARSEVECTORMAP_H
16 
17 #include "sst/core/serialization/serializable.h"
18 #include "sst/core/sst_types.h"
19 
20 #include <algorithm>
21 #include <cstddef>
22 #include <stdexcept>
23 #include <string>
24 #include <vector>
25 
26 namespace SST {
27 
28 /**
29  Class that stores data in a vector, but can access the data similar
30  to a map. The data structure is O(log n) on reads, but is O(n) to
31  insert. The primary use case is when data is inserted in order, but
32  accessed randomly. You can also create the SparseVectorMap with a
33  vector already loaded with the data. If the data is not already
34  sorted, it will call std::sort on the data, which likely has an
35  average complexity of O(n log n). This data structure should not
36  be used for large lists where inserts do not happen in sorted order.
37 
38  NOTE: Since the data is stored in the vector, reference returned
39  from the various accessor functions will not be valid longterm. If
40  an insert causes the vector to be resized, all references returned
41  before that reallocation may (likely will) be invalid. References
42  are only guaranteed to be valid until the next write to the data
43  structure.
44  */
45 template <typename keyT, typename classT = keyT>
47 {
48 private:
50 
51  /**
52  Finds the insertion point for new data
53 
54  @param id ID of the data that needs to be inserted.
55 
56  @return Index where new data should be inserted. If key is
57  already in the map, it will return -1.
58  */
59  std::vector<classT> data;
60  int binary_search_insert(keyT id) const
61  {
62  // For insert, we've found the right place when id < n && id >
63  // n-1. We then insert at n.
64 
65  int size = data.size();
66 
67  // Check to see if it goes top or bottom
68  if ( size == 0 ) return 0;
69  if ( id > data[size - 1].key() ) return size;
70  if ( id < data[0].key() ) return 0;
71 
72  int bottom = 0;
73  int top = size - 1;
74  int middle;
75 
76  while ( bottom <= top ) {
77  middle = bottom + (top - bottom) / 2;
78  if ( id == data[middle].key() ) return -1; // Already in map
79  if ( id < data[middle].key() ) {
80  // May be the right place, need to see if id is greater
81  // than the one before the current middle. If so, then we
82  // have the right place.
83  if ( id > data[middle - 1].key() )
84  return middle;
85  else {
86  top = middle - 1;
87  }
88  }
89  else {
90  bottom = middle + 1;
91  }
92  }
93  /* Shouldn't be reached */
94  return -1;
95  }
96 
97  /**
98  Finds the index where the data associated with the given key is
99  found in the vector
100 
101  @param id ID of the data that needs to be found.
102 
103  @return Index where data for the provided ID is found. It
104  returns -1 if the key is not found in the data vector.
105  */
106  int binary_search_find(keyT id) const
107  {
108  int bottom = 0;
109  int top = data.size() - 1;
110  int middle;
111 
112  if ( data.size() == 0 ) return -1;
113  while ( bottom <= top ) {
114  middle = bottom + (top - bottom) / 2;
115  if ( id == data[middle].key() )
116  return middle;
117  else if ( id < data[middle].key() )
118  top = middle - 1;
119  else
120  bottom = middle + 1;
121  }
122  return -1;
123  }
124 
125  friend class ConfigGraph;
126 
127 public:
128  /**
129  Default constructor for SparseVectorMap
130  */
132 
133  /**
134  Constructor that allows you to pass an already filled in array
135  with data. The data in the passed in vector will be swapped
136  into the data vector of the sparsevectormap and the passed in
137  vector will be empty.
138 
139  @param new_data Vector of data to swap into the sparsevectormap
140  data
141 
142  @param sorted Specifies whether the vector is already sorted in
143  ascending order. if not, it will be sorted after swapping the
144  data in.
145  */
146  SparseVectorMap(std::vector<classT>& new_data, bool sorted = false)
147  {
148  data.swap(new_data);
149  if ( !sorted ) {
150  sort();
151  }
152  }
153 
154  /**
155  Force a sort of the data
156  */
157  void sort()
158  {
159  std::sort(data.begin(), data.end(),
160  [](const classT& lhs, const classT& rhs) -> bool { return lhs.key() < rhs.key(); });
161  }
162 
163  using iterator = typename std::vector<classT>::iterator;
164  using const_iterator = typename std::vector<classT>::const_iterator;
165 
166  /**
167  Insert new value into SparseVectorMap. The inserted class must
168  have a key() function with return type keyT.
169 
170  @param val value to add to SparseVectorMap
171 
172  @return reference to the inserted item, or to the existing item
173  if it was already present in the map.
174 
175  */
176  classT& insert(const classT& val)
177  {
178  int index = binary_search_insert(val.key());
179  if ( index == -1 ) return data[binary_search_find(val.key())]; // already in the map
180  iterator it = data.begin();
181  it += index;
182  data.insert(it, val);
183  return data[index];
184  }
185 
186  /**
187  Returns the begin iterator to the underlying vector.
188 
189  @return begin iterator to data vector
190  */
191  iterator begin() { return data.begin(); }
192 
193  /**
194  Returns the end iterator to the underlying vector.
195 
196  @return end iterator to data vector
197  */
198  iterator end() { return data.end(); }
199 
200  /**
201  Returns the const begin iterator to the underlying vector.
202 
203  @return const begin iterator to data vector
204  */
205  const_iterator begin() const { return data.begin(); }
206 
207  /**
208  Returns the const end iterator to the underlying vector.
209 
210  @return const end iterator to data vector
211  */
212  const_iterator end() const { return data.end(); }
213 
214  /**
215  Checks if the provided id is found in the SparseVectorMap
216 
217  @param id id to check for
218 
219  @return true if id is found, false otherwise
220  */
221  bool contains(keyT id) const
222  {
223  if ( binary_search_find(id) == -1 ) return false;
224  return true;
225  }
226 
227  /**
228  Operator returns a reference to data with the specified id.
229  Value can be modified. This will only return references to
230  existing values, you must use insert() for new values.
231 
232  @param id id of the value to return (value returned by key())
233 
234  @return reference to the requested item.
235 
236  @exception std::out_of_range try to access an element that doesn't exist in the SparseVectorMap
237  */
238  classT& operator[](keyT id)
239  {
240  int index = binary_search_find(id);
241  if ( index == -1 ) {
242  throw std::out_of_range("SparseVectorMap: trying to access element that does not exist");
243  }
244  return data[index];
245  }
246 
247  /**
248  Operator returns a const reference to data with the specified
249  id. Value cannot be modified. This will only return
250  references to existing values, you must use insert() for new
251  values.
252 
253  @param id id of the value to return (value returned by key())
254 
255  @return const reference to the requested item.
256 
257  @exception std::out_of_range try to access an element that doesn't exist in the SparseVectorMap
258  */
259  const classT& operator[](keyT id) const
260  {
261  int index = binary_search_find(id);
262  if ( index == -1 ) {
263  throw std::out_of_range("SparseVectorMap: trying to access element that does not exist");
264  }
265  return data[index];
266  }
267 
268  /**
269  Clears the contents of the SparseVectorMap
270  */
271  void clear() { data.clear(); }
272 
273  /**
274  Returns the number of items in the SparseVectorMap
275 
276  @return number of items
277  */
278  size_t size() { return data.size(); }
279 };
280 
281 
282 /**
283  Exception that is thrown by SparseVectorMap::filter() if the
284  filtering object returns an object that returns a different value
285  from the key() function than what was passed into the filter.
286  */
287 class bad_filtered_key_error : public std::runtime_error
288 {
289 public:
290  explicit bad_filtered_key_error(const std::string& what_arg) :
291  runtime_error(what_arg)
292  {}
293 };
294 
295 
296 /**
297  Class that stores data in a vector, but can access the data similar
298  to a map. The data structure is O(log n) on reads, but is O(n) to
299  insert. The primary use case is when data is inserted in order, but
300  accessed randomly. You can also create the SparseVectorMap with a
301  vector already loaded with the data. If the data is not already
302  sorted, it will call std::sort on the data, which likely has an
303  average complexity of O(n log n). This data structure should not
304  be used for large lists where inserts do not happen in sorted order.
305 
306  NOTE: Since the data is stored in the vector, reference returned
307  from the various accessor functions will not be valid longterm. If
308  an insert causes the vector to be resized, all references returned
309  before that reallocation may (likely will) be invalid. References
310  are only guaranteed to be valid until the next write to the data
311  structure.
312  */
313 template <typename keyT, typename classT>
314 class SparseVectorMap<keyT, classT*>
315 {
316 private:
317  friend class SST::Core::Serialization::serialize_impl<SparseVectorMap<keyT, classT*>>;
318 
319  /**
320  Finds the insertion point for new data
321 
322  @param id ID of the data that needs to be inserted.
323 
324  @return Index where new data should be inserted. If key is
325  already in the map, it will return -1.
326  */
327  std::vector<classT*> data;
328  int binary_search_insert(keyT id) const
329  {
330  // For insert, we've found the right place when id < n && id >
331  // n-1. We then insert at n.
332 
333  int size = data.size();
334 
335  // Check to see if it goes top or bottom
336  if ( size == 0 ) return 0;
337  if ( id > data[size - 1]->key() ) return size;
338  if ( id < data[0]->key() ) return 0;
339 
340  int bottom = 0;
341  int top = size - 1;
342  int middle;
343 
344  while ( bottom <= top ) {
345  middle = bottom + (top - bottom) / 2;
346  if ( id == data[middle]->key() ) return -1; // Already in map
347  if ( id < data[middle]->key() ) {
348  // May be the right place, need to see if id is greater
349  // than the one before the current middle. If so, then we
350  // have the right place.
351  if ( id > data[middle - 1]->key() )
352  return middle;
353  else {
354  top = middle - 1;
355  }
356  }
357  else {
358  bottom = middle + 1;
359  }
360  }
361  /* Shouldn't be reached */
362  return -1;
363  }
364 
365  /**
366  Finds the index where the data associated with the given key is
367  found in the vector
368 
369  @param id ID of the data that needs to be found.
370 
371  @return Index where data for the provided ID is found. It
372  returns -1 if the key is not found in the data vector.
373  */
374  int binary_search_find(keyT id) const
375  {
376  int bottom = 0;
377  int top = data.size() - 1;
378  int middle;
379 
380  if ( data.size() == 0 ) return -1;
381  while ( bottom <= top ) {
382  middle = bottom + (top - bottom) / 2;
383  if ( id == data[middle]->key() )
384  return middle;
385  else if ( id < data[middle]->key() )
386  top = middle - 1;
387  else
388  bottom = middle + 1;
389  }
390  return -1;
391  }
392 
393  friend class ConfigGraph;
394 
395 public:
396  /**
397  Default constructor for SparseVectorMap
398  */
400 
401  /**
402  Constructor that allows you to pass an already filled in array
403  with data. The data in the passed in vector will be swapped
404  into the data vector of the sparsevectormap and the passed in
405  vector will be empty.
406 
407  @param new_data Vector of data to swap into the sparsevectormap
408  data
409 
410  @param sorted Specifies whether the vector is already sorted in
411  ascending order. if not, it will be sorted after swapping the
412  data in.
413  */
414  SparseVectorMap(std::vector<classT*>& new_data, bool sorted = false)
415  {
416  data.swap(new_data);
417  if ( !sorted ) {
418  sort();
419  }
420  }
421 
422  /**
423  Force a sort of the data
424  */
425  void sort()
426  {
427  std::sort(data.begin(), data.end(),
428  [](const classT* lhs, const classT* rhs) -> bool { return lhs->key() < rhs->key(); });
429  }
430 
431  using iterator = typename std::vector<classT*>::iterator;
432  using const_iterator = typename std::vector<classT*>::const_iterator;
433 
434  /**
435  Insert new value into SparseVectorMap. The inserted class must
436  have a key() function with return type keyT.
437 
438  @param val value to add to SparseVectorMap
439 
440  @return reference to the inserted item, or to the existing item
441  if it was already present in the map.
442 
443  */
444  classT* insert(classT* val)
445  {
446  int index = binary_search_insert(val->key());
447  if ( index == -1 ) return data[binary_search_find(val->key())]; // already in the map
448  iterator it = data.begin();
449  it += index;
450  data.insert(it, val);
451  return data[index];
452  }
453 
454  /**
455  Returns the begin iterator to the underlying vector.
456 
457  @return begin iterator to data vector
458  */
459  iterator begin() { return data.begin(); }
460 
461  /**
462  Returns the end iterator to the underlying vector.
463 
464  @return end iterator to data vector
465  */
466  iterator end() { return data.end(); }
467 
468  /**
469  Returns the const begin iterator to the underlying vector.
470 
471  @return const begin iterator to data vector
472  */
473  const_iterator begin() const { return data.begin(); }
474 
475  /**
476  Returns the const end iterator to the underlying vector.
477 
478  @return const end iterator to data vector
479  */
480  const_iterator end() const { return data.end(); }
481 
482  /**
483  Checks if the provided id is found in the SparseVectorMap
484 
485  @param id id to check for
486 
487  @return true if id is found, false otherwise
488  */
489  bool contains(keyT id) const
490  {
491  if ( binary_search_find(id) == -1 ) return false;
492  return true;
493  }
494 
495  /**
496  Operator returns a reference to data with the specified id.
497  Value can be modified. This will only return references to
498  existing values, you must use insert() for new values.
499 
500  @param id id of the value to return (value returned by key())
501 
502  @return reference to the requested item.
503 
504  @exception std::out_of_range try to access an element that doesn't exist in the SparseVectorMap
505  */
506  classT* operator[](keyT id)
507  {
508  int index = binary_search_find(id);
509  if ( index == -1 ) {
510  throw std::out_of_range("SparseVectorMap: trying to access element that does not exist");
511  }
512  return data[index];
513  }
514 
515  /**
516  Operator returns a const reference to data with the specified
517  id. Value cannot be modified. This will only return
518  references to existing values, you must use insert() for new
519  values.
520 
521  @param id id of the value to return (value returned by key())
522 
523  @return const reference to the requested item.
524 
525  @exception std::out_of_range try to access an element that doesn't exist in the SparseVectorMap
526  */
527  const classT* operator[](keyT id) const
528  {
529  int index = binary_search_find(id);
530  if ( index == -1 ) {
531  throw std::out_of_range("SparseVectorMap: trying to access element that does not exist");
532  }
533  return data[index];
534  }
535 
536  /**
537  Clears the contents of the SparseVectorMap
538  */
539  void clear() { data.clear(); }
540 
541  /**
542  Returns the number of items in the SparseVectorMap
543 
544  @return number of items
545  */
546  size_t size() { return data.size(); }
547 
548 
549  /**
550  Function to filter the contents of the SparseVectorMap. Takes
551  an object with an overloaded operator() function that takes as
552  argument the current item. The funtion returns the object that
553  should take the place of this object (value returned by key()
554  function must be same for both objects), or returns nullptr if
555  the object should be deleted. When an item is deleted, the
556  size of the map reduces by 1.
557 
558  @param filt Filter object to use for filtering contents of map
559 
560  @exception bad_filtered_key_error filter returned an object that
561  didn't return the same value on a call to key() as the original
562  object in the map.
563  */
564  template <typename filterT>
565  void filter(filterT& filt)
566  {
567  int write_ptr = 0;
568  for ( size_t i = 0; i < data.size(); ++i ) {
569  auto key = data[i]->key();
570  data[write_ptr] = filt(data[i]);
571  if ( data[write_ptr] != nullptr ) {
572  // Make sure the keys match
573  if ( UNLIKELY(data[write_ptr]->key() != key) ) {
574  // No recovering from this, just need to error out
576  "ERROR: Filter object passed to SparseVectorMap::filter returned an object that had a "
577  "different value of key() than what was passed into the filter. The filter object must return "
578  "either an object with the same value of key(), or nullptr if the object should be removed.");
579  }
580  write_ptr++;
581  }
582  }
583  // Need to shorten vector if items were removed. The
584  // write_ptr will be at the index with the first nullptr from
585  // the filter, and tells us where to cut things off. So,
586  // simply call resize() on the vector with write_ptr as the
587  // new size.
588  data.resize(write_ptr);
589  data.shrink_to_fit();
590  }
591 };
592 
593 /**
594  Templated version of SparseVectorMap where the data and key are the
595  same (actually more like a set than a map in this case). The type
596  must implement the less than operator. This is primarily intended
597  for use with native types.
598  */
599 template <typename keyT>
600 class SparseVectorMap<keyT, keyT>
601 {
602 private:
604 
605  /**
606  Finds the insertion point for new data
607 
608  @param id ID of the data that needs to be inserted.
609 
610  @return Index where new data should be inserted. If key is
611  already in the map, it will return -1.
612  */
613  std::vector<keyT> data;
614  int binary_search_insert(keyT id) const
615  {
616  // For insert, we've found the right place when id < n && id >
617  // n-1. We then insert at n.
618 
619  int size = data.size();
620 
621  // Check to see if it goes top or bottom
622  if ( size == 0 ) return 0;
623  if ( id < data[0] ) return 0;
624  if ( id > data[size - 1] ) return size;
625 
626  int bottom = 0;
627  int top = size - 1;
628  int middle;
629 
630  while ( bottom <= top ) {
631  middle = bottom + (top - bottom) / 2;
632  if ( id == data[middle] ) return -1; // Already in map
633  if ( id < data[middle] ) {
634  // May be the right place, need to see if id is greater
635  // than the one before the current middle. If so, then we
636  // have the right place.
637  if ( id > data[middle - 1] )
638  return middle;
639  else {
640  top = middle - 1;
641  }
642  }
643  else {
644  bottom = middle + 1;
645  }
646  }
647  /* Shouldn't be reached */
648  return -1;
649  }
650 
651  /**
652  Finds the index where the data associated with the given key is
653  found in the vector
654 
655  @param id ID of the data that needs to be found.
656 
657  @return Index where data for the provided ID is found. It
658  returns -1 if the key is not found in the data vector.
659  */
660  int binary_search_find(keyT id) const
661  {
662  int bottom = 0;
663  int top = data.size() - 1;
664  int middle;
665 
666  if ( data.size() == 0 ) return -1;
667  while ( bottom <= top ) {
668  middle = bottom + (top - bottom) / 2;
669  if ( id == data[middle] )
670  return middle;
671  else if ( id < data[middle] )
672  top = middle - 1;
673  else
674  bottom = middle + 1;
675  }
676  return -1;
677  }
678 
679  friend class ConfigGraph;
680 
681 public:
682  /**
683  Default constructor for SparseVectorMap
684  */
686 
687  /**
688  Constructor that allows you to pass an already filled in array
689  with data. The data in the passed in vector will be swapped
690  into the data vector of the SparseVectorMap and the passed in
691  vector will be empty.
692 
693  @param new_data Vector of data to swap into the SparseVectorMap
694  data
695 
696  @param sorted Specifies whether the vector is already sorted in
697  ascending order. If not, it will be sorted after swapping the
698  data in.
699  */
700  SparseVectorMap(std::vector<keyT>& new_data, bool sorted = false)
701  {
702  data.swap(new_data);
703  if ( !sorted ) {
704  sort();
705  }
706  }
707 
708  /**
709  Force a sort of the data
710  */
711  void sort()
712  {
713  std::sort(data.begin(), data.end, [](const keyT& lhs, const keyT& rhs) -> bool { return lhs < rhs; });
714  }
715 
716  using iterator = typename std::vector<keyT>::iterator;
717  using const_iterator = typename std::vector<keyT>::const_iterator;
718 
719  /**
720  Insert new value into SparseVectorMap. The inserted class must
721  have a key() function with return type keyT.
722 
723  @param val value to add to SparseVectorMap
724 
725  @return reference to the inserted item, or to the existing item
726  if it was already present in the map.
727 
728  */
729  keyT& insert(const keyT& val)
730  {
731  int index = binary_search_insert(val);
732  if ( index == -1 ) return data[binary_search_find(val)]; // already in the map
733  iterator it = data.begin();
734  it += index;
735  data.insert(it, val);
736  return data[index];
737  }
738 
739  /**
740  Returns the begin iterator to the underlying vector.
741 
742  @return begin iterator to data vector
743  */
744  iterator begin() { return data.begin(); }
745 
746  /**
747  Returns the end iterator to the underlying vector.
748 
749  @return end iterator to data vector
750  */
751  iterator end() { return data.end(); }
752 
753  /**
754  Returns the const begin iterator to the underlying vector.
755 
756  @return const begin iterator to data vector
757  */
758  const_iterator begin() const { return data.begin(); }
759 
760  /**
761  Returns the const end iterator to the underlying vector.
762 
763  @return const end iterator to data vector
764  */
765  const_iterator end() const { return data.end(); }
766 
767  /**
768  Checks if the provided id is found in the SparseVectorMap
769 
770  @param id id to check for
771 
772  @return true if id is found, false otherwise
773  */
774  bool contains(keyT id)
775  {
776  if ( binary_search_find(id) == -1 ) return false;
777  return true;
778  }
779 
780  /**
781  Operator returns a reference to data with the specified id.
782  Value can be modified. This will only return references to
783  existing values, you must use insert() for new values.
784 
785  @param id id of the value to return (value returned by key())
786 
787  @return reference to the requested item.
788 
789  @exception std::out_of_range try to access an element that doesn't exist in the SparseVectorMap
790  */
791  keyT& operator[](keyT id)
792  {
793  int index = binary_search_find(id);
794  if ( index == -1 ) {
795  throw std::out_of_range("SparseVectorMap: trying to access element that does not exist");
796  }
797  return data[index];
798  }
799 
800  /**
801  Operator returns a const reference to data with the specified
802  id. Value cannot be modified. This will only return
803  references to existing values, you must use insert() for new
804  values.
805 
806  @param id id of the value to return (value returned by key())
807 
808  @return const reference to the requested item.
809 
810  @exception std::out_of_range try to access an element that doesn't exist in the SparseVectorMap
811  */
812  const keyT& operator[](keyT id) const
813  {
814  int index = binary_search_find(id);
815  if ( index == -1 ) {
816  throw std::out_of_range("SparseVectorMap: trying to access element that does not exist");
817  }
818  return data[index];
819  }
820 
821  /**
822  Clears the contents of the SparseVectorMap
823  */
824  void clear() { data.clear(); }
825 
826  /**
827  Returns the number of items in the SparseVectorMap
828 
829  @return number of items
830  */
831  size_t size() { return data.size(); }
832 };
833 
834 } // namespace SST
835 
836 namespace SST::Core::Serialization {
837 
838 template <typename keyT, typename classT>
839 class serialize_impl<SST::SparseVectorMap<keyT, classT>>
840 {
841 public:
842  void operator()(SST::SparseVectorMap<keyT, classT>& v, SST::Core::Serialization::serializer& ser, ser_opt_t options)
843  {
844  SST_SER(v.data, options);
845  }
846 };
847 } // namespace SST::Core::Serialization
848 
849 #endif // SST_CORE_SPARSEVECTORMAP_H
void sort()
Force a sort of the data.
Definition: sparseVectorMap.h:157
iterator end()
Returns the end iterator to the underlying vector.
Definition: sparseVectorMap.h:751
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:42
iterator end()
Returns the end iterator to the underlying vector.
Definition: sparseVectorMap.h:466
classT & operator[](keyT id)
Operator returns a reference to data with the specified id.
Definition: sparseVectorMap.h:238
const_iterator begin() const
Returns the const begin iterator to the underlying vector.
Definition: sparseVectorMap.h:473
bool contains(keyT id)
Checks if the provided id is found in the SparseVectorMap.
Definition: sparseVectorMap.h:774
classT & insert(const classT &val)
Insert new value into SparseVectorMap.
Definition: sparseVectorMap.h:176
void sort()
Force a sort of the data.
Definition: sparseVectorMap.h:425
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:414
classT * operator[](keyT id)
Operator returns a reference to data with the specified id.
Definition: sparseVectorMap.h:506
A Configuration Graph A graph representing Components and Links.
Definition: configGraph.h:585
Base serialize class.
Definition: serialize.h:113
Definition: action.cc:18
iterator end()
Returns the end iterator to the underlying vector.
Definition: sparseVectorMap.h:198
iterator begin()
Returns the begin iterator to the underlying vector.
Definition: sparseVectorMap.h:191
const_iterator end() const
Returns the const end iterator to the underlying vector.
Definition: sparseVectorMap.h:212
size_t size()
Returns the number of items in the SparseVectorMap.
Definition: sparseVectorMap.h:546
size_t size()
Returns the number of items in the SparseVectorMap.
Definition: sparseVectorMap.h:278
const classT * operator[](keyT id) const
Operator returns a const reference to data with the specified id.
Definition: sparseVectorMap.h:527
keyT & operator[](keyT id)
Operator returns a reference to data with the specified id.
Definition: sparseVectorMap.h:791
void filter(filterT &filt)
Function to filter the contents of the SparseVectorMap.
Definition: sparseVectorMap.h:565
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:700
iterator begin()
Returns the begin iterator to the underlying vector.
Definition: sparseVectorMap.h:459
const_iterator begin() const
Returns the const begin iterator to the underlying vector.
Definition: sparseVectorMap.h:758
const classT & operator[](keyT id) const
Operator returns a const reference to data with the specified id.
Definition: sparseVectorMap.h:259
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:146
iterator begin()
Returns the begin iterator to the underlying vector.
Definition: sparseVectorMap.h:744
const keyT & operator[](keyT id) const
Operator returns a const reference to data with the specified id.
Definition: sparseVectorMap.h:812
keyT & insert(const keyT &val)
Insert new value into SparseVectorMap.
Definition: sparseVectorMap.h:729
size_t size()
Returns the number of items in the SparseVectorMap.
Definition: sparseVectorMap.h:831
const_iterator end() const
Returns the const end iterator to the underlying vector.
Definition: sparseVectorMap.h:480
SparseVectorMap()
Default constructor for SparseVectorMap.
Definition: sparseVectorMap.h:131
const_iterator begin() const
Returns the const begin iterator to the underlying vector.
Definition: sparseVectorMap.h:205
SparseVectorMap()
Default constructor for SparseVectorMap.
Definition: sparseVectorMap.h:685
bool contains(keyT id) const
Checks if the provided id is found in the SparseVectorMap.
Definition: sparseVectorMap.h:221
Class that stores data in a vector, but can access the data similar to a map.
Definition: sparseVectorMap.h:46
bool contains(keyT id) const
Checks if the provided id is found in the SparseVectorMap.
Definition: sparseVectorMap.h:489
void clear()
Clears the contents of the SparseVectorMap.
Definition: sparseVectorMap.h:824
Exception that is thrown by SparseVectorMap::filter() if the filtering object returns an object that ...
Definition: sparseVectorMap.h:287
SparseVectorMap()
Default constructor for SparseVectorMap.
Definition: sparseVectorMap.h:399
void clear()
Clears the contents of the SparseVectorMap.
Definition: sparseVectorMap.h:271
classT * insert(classT *val)
Insert new value into SparseVectorMap.
Definition: sparseVectorMap.h:444
const_iterator end() const
Returns the const end iterator to the underlying vector.
Definition: sparseVectorMap.h:765
void sort()
Force a sort of the data.
Definition: sparseVectorMap.h:711
void clear()
Clears the contents of the SparseVectorMap.
Definition: sparseVectorMap.h:539