gtsam
Loading...
Searching...
No Matches
FastMap.h
Go to the documentation of this file.
1/* ----------------------------------------------------------------------------
2
3 * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4 * Atlanta, Georgia 30332-0415
5 * All Rights Reserved
6 * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7
8 * See LICENSE for the license information
9
10 * -------------------------------------------------------------------------- */
11
18
19#pragma once
20
22#if GTSAM_ENABLE_BOOST_SERIALIZATION
23#include <boost/serialization/nvp.hpp>
24#include <boost/serialization/map.hpp>
25#endif
26#include <map>
27
28namespace gtsam {
29
38template<typename KEY, typename VALUE>
39class FastMap : public std::map<KEY, VALUE, std::less<KEY>,
40 typename internal::FastDefaultAllocator<std::pair<const KEY, VALUE> >::type> {
41
42public:
43
44 typedef std::map<KEY, VALUE, std::less<KEY>,
46
49
51 template<typename INPUTITERATOR>
52 explicit FastMap(INPUTITERATOR first, INPUTITERATOR last) : Base(first, last) {}
53
55 FastMap(const FastMap<KEY,VALUE>& x) : Base(x) {}
56
57 FastMap& operator=(const FastMap<KEY,VALUE>& x) = default;
58
60 FastMap(const Base& x) : Base(x) {}
61
63 operator std::map<KEY,VALUE>() const {
64 return std::map<KEY,VALUE>(this->begin(), this->end());
65 }
66
68 bool insert2(const KEY& key, const VALUE& val) { return Base::insert({key, val}).second; }
69
71 bool exists(const KEY& e) const { return this->find(e) != this->end(); }
72
73private:
74#if GTSAM_ENABLE_BOOST_SERIALIZATION
76 friend class boost::serialization::access;
77 template<class ARCHIVE>
78 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
79 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
80 }
81#endif
82};
83
84}
An easy way to control which allocator is used for Fast* collections.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
Default allocator for list, map, and set types.
Definition FastDefaultAllocator.h:50
FastMap is a thin wrapper around std::map that uses the boost fast_pool_allocator instead of the defa...
Definition FastMap.h:40
FastMap(const Base &x)
Copy constructor from the base map class.
Definition FastMap.h:60
FastMap(INPUTITERATOR first, INPUTITERATOR last)
Constructor from a range, passes through to base class.
Definition FastMap.h:52
bool insert2(const KEY &key, const VALUE &val)
Handy 'insert' function for Matlab wrapper.
Definition FastMap.h:68
FastMap(const FastMap< KEY, VALUE > &x)
Copy constructor from another FastMap.
Definition FastMap.h:55
FastMap()
Default constructor.
Definition FastMap.h:48
bool exists(const KEY &e) const
Handy 'exists' function.
Definition FastMap.h:71