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 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
22 #include <boost/version.hpp>
23 #if BOOST_VERSION >= 107400
24 #include <boost/serialization/library_version_type.hpp>
25 #endif
26 #include <boost/serialization/nvp.hpp>
27 #include <boost/serialization/set.hpp>
28 #endif
30 #include <gtsam/base/Testable.h>
31 
32 #include <functional>
33 #include <set>
34 
35 namespace boost {
36 namespace serialization {
37 class access;
38 } /* namespace serialization */
39 } /* namespace boost */
40 
41 namespace gtsam {
42 
50 template<typename VALUE>
51 class FastSet: public std::set<VALUE, std::less<VALUE>,
52  typename internal::FastDefaultAllocator<VALUE>::type> {
53 
55 
56 public:
57 
58  typedef std::set<VALUE, std::less<VALUE>,
60 
61  using Base::Base; // Inherit the set constructors
62 
63  FastSet() = default;
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
82 
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)
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 
125 private:
126 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
127 
128  friend class boost::serialization::access;
129  template<class ARCHIVE>
130  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
131  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
132  }
133 #endif
134 };
135 
136 }
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Testable.h
Concept check for values that can be used in unit tests.
gtsam::FastSet::exists
bool exists(const VALUE &e) const
Definition: FastSet.h:98
gtsam::FastSet::FastSet
FastSet(const FastSet< VALUE > &x)
Definition: FastSet.h:72
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
gtsam::FastSet::merge
void merge(const FastSet &other)
Definition: FastSet.h:121
gtsam::FastSet
Definition: FastSet.h:51
boost
Definition: boostmultiprec.cpp:109
gtsam::FastSet::FastSet
FastSet(const Base &x)
Definition: FastSet.h:77
Eigen::internal::VALUE
@ VALUE
Definition: SpecialFunctionsImpl.h:729
gtsam::FastSet::FastSet
FastSet()=default
Default constructor.
gtsam::internal::FastDefaultAllocator::type
boost::fast_pool_allocator< T > type
Definition: FastDefaultAllocator.h:52
anyset::size
size_t size() const
Definition: pytypes.h:2220
gtsam::FastSet::print
void print(const std::string &str="") const
Definition: FastSet.h:103
str
Definition: pytypes.h:1558
set
void set(Container &c, Position position, const Value &value)
Definition: stdlist_overload.cpp:37
gtsam
traits
Definition: SFMdata.h:40
gtsam::traits
Definition: Group.h:36
Base::Base
Base()=default
gtsam::FastSet::GTSAM_CONCEPT_ASSERT
GTSAM_CONCEPT_ASSERT(IsTestable< VALUE >)
gtsam::FastSet::FastSet
FastSet(const INPUTCONTAINER &container)
Definition: FastSet.h:67
gtsam::FastSet::Base
std::set< VALUE, std::less< VALUE >, typename internal::FastDefaultAllocator< VALUE >::type > Base
Definition: FastSet.h:59
gtsam::tol
const G double tol
Definition: Group.h:79
FastDefaultAllocator.h
An easy way to control which allocator is used for Fast* collections.
Eigen::placeholders::end
static const EIGEN_DEPRECATED end_t end
Definition: IndexedViewHelper.h:181
gtsam::IsTestable
Definition: Testable.h:59
Base
Definition: test_virtual_functions.cpp:156
insert
A insert(1, 2)=0
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
gtsam::FastSet::equals
bool equals(const FastSet< VALUE > &other, double tol=1e-9) const
Definition: FastSet.h:109


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:17