gtsam 4.1.1
gtsam
FastSet.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
19#pragma once
20
21#include <boost/serialization/nvp.hpp>
22#include <boost/serialization/set.hpp>
24#include <gtsam/base/Testable.h>
25
26#include <functional>
27#include <set>
28
29namespace boost {
30namespace serialization {
31class access;
32} /* namespace serialization */
33} /* namespace boost */
34
35namespace gtsam {
36
44template<typename VALUE>
45class FastSet: public std::set<VALUE, std::less<VALUE>,
46 typename internal::FastDefaultAllocator<VALUE>::type> {
47
48 BOOST_CONCEPT_ASSERT ((IsTestable<VALUE> ));
49
50public:
51
52 typedef std::set<VALUE, std::less<VALUE>,
53 typename internal::FastDefaultAllocator<VALUE>::type> Base;
54
57 }
58
60 template<typename INPUTITERATOR>
61 explicit FastSet(INPUTITERATOR first, INPUTITERATOR last) :
62 Base(first, last) {
63 }
64
66 template<typename INPUTCONTAINER>
67 explicit FastSet(const INPUTCONTAINER& container) :
68 Base(container.begin(), container.end()) {
69 }
70
73 Base(x) {
74 }
75
77 FastSet(const Base& x) :
78 Base(x) {
79 }
80
81#ifdef GTSAM_ALLOCATOR_BOOSTPOOL
83 FastSet(const std::set<VALUE>& x) {
84 // This if statement works around a bug in boost pool allocator and/or
85 // STL vector where if the size is zero, the pool allocator will allocate
86 // huge amounts of memory.
87 if(x.size() > 0)
88 Base::insert(x.begin(), x.end());
89 }
90#endif
91
93 operator std::set<VALUE>() const {
94 return std::set<VALUE>(this->begin(), this->end());
95 }
96
98 bool exists(const VALUE& e) const {
99 return this->find(e) != this->end();
100 }
101
103 void print(const std::string& str = "") const {
104 for (typename Base::const_iterator it = this->begin(); it != this->end(); ++it)
105 traits<VALUE>::Print(*it, str);
106 }
107
109 bool equals(const FastSet<VALUE>& other, double tol = 1e-9) const {
110 typename Base::const_iterator it1 = this->begin(), it2 = other.begin();
111 while (it1 != this->end()) {
112 if (it2 == other.end() || !traits<VALUE>::Equals(*it2, *it2, tol))
113 return false;
114 ++it1;
115 ++it2;
116 }
117 return true;
118 }
119
121 void merge(const FastSet& other) {
122 Base::insert(other.begin(), other.end());
123 }
124
125private:
128 template<class ARCHIVE>
129 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
130 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
131 }
132};
133
134}
An easy way to control which allocator is used for Fast* collections.
Concept check for values that can be used in unit tests.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
Definition: FastSet.h:46
void merge(const FastSet &other)
insert another set: handy for MATLAB access
Definition: FastSet.h:121
FastSet()
Default constructor.
Definition: FastSet.h:56
void print(const std::string &str="") const
Print to implement Testable: pretty basic.
Definition: FastSet.h:103
FastSet(const INPUTCONTAINER &container)
Constructor from a iterable container, passes through to base class.
Definition: FastSet.h:67
FastSet(const FastSet< VALUE > &x)
Copy constructor from another FastSet.
Definition: FastSet.h:72
FastSet(INPUTITERATOR first, INPUTITERATOR last)
Constructor from a range, passes through to base class.
Definition: FastSet.h:61
bool exists(const VALUE &e) const
Handy 'exists' function.
Definition: FastSet.h:98
bool equals(const FastSet< VALUE > &other, double tol=1e-9) const
Check for equality within tolerance to implement Testable.
Definition: FastSet.h:109
friend class boost::serialization::access
Serialization function.
Definition: FastSet.h:127
FastSet(const Base &x)
Copy constructor from the base set class.
Definition: FastSet.h:77
Definition: Testable.h:58