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 <gtsam/config.h>
22 
23 #if GTSAM_ENABLE_BOOST_SERIALIZATION
24 #include <boost/version.hpp>
25 #if BOOST_VERSION >= 107400
26 #include <boost/serialization/library_version_type.hpp>
27 #endif
28 #include <boost/serialization/nvp.hpp>
29 #include <boost/serialization/set.hpp>
30 #endif
32 #include <gtsam/base/Testable.h>
33 
34 #include <functional>
35 #include <set>
36 
37 namespace boost {
38 namespace serialization {
39 class access;
40 } /* namespace serialization */
41 } /* namespace boost */
42 
43 namespace gtsam {
44 
52 template<typename VALUE>
53 class FastSet: public std::set<VALUE, std::less<VALUE>,
54  typename internal::FastDefaultAllocator<VALUE>::type> {
55 
57 
58 public:
59 
60  typedef std::set<VALUE, std::less<VALUE>,
62 
63  using Base::Base; // Inherit the set constructors
64 
65  FastSet() = default;
66 
68  template<typename INPUTCONTAINER>
69  explicit FastSet(const INPUTCONTAINER& container) :
70  Base(container.begin(), container.end()) {
71  }
72 
75  Base(x) {
76  }
77 
79  FastSet(const Base& x) :
80  Base(x) {
81  }
82 
83  FastSet& operator=(const FastSet& other) = default;
84 
85 #ifdef GTSAM_ALLOCATOR_BOOSTPOOL
86 
87  FastSet(const std::set<VALUE>& x) {
88  // This if statement works around a bug in boost pool allocator and/or
89  // STL vector where if the size is zero, the pool allocator will allocate
90  // huge amounts of memory.
91  if(x.size() > 0)
92  Base::insert(x.begin(), x.end());
93  }
94 #endif
95 
97  operator std::set<VALUE>() const {
98  return std::set<VALUE>(this->begin(), this->end());
99  }
100 
102  bool exists(const VALUE& e) const {
103  return this->find(e) != this->end();
104  }
105 
107  void print(const std::string& str = "") const {
108  for (typename Base::const_iterator it = this->begin(); it != this->end(); ++it)
110  }
111 
113  bool equals(const FastSet<VALUE>& other, double tol = 1e-9) const {
114  typename Base::const_iterator it1 = this->begin(), it2 = other.begin();
115  while (it1 != this->end()) {
116  if (it2 == other.end() || !traits<VALUE>::Equals(*it2, *it2, tol))
117  return false;
118  ++it1;
119  ++it2;
120  }
121  return true;
122  }
123 
125  void merge(const FastSet& other) {
126  Base::insert(other.begin(), other.end());
127  }
128 
129 private:
130 #if GTSAM_ENABLE_BOOST_SERIALIZATION
131 
132  friend class boost::serialization::access;
133  template<class ARCHIVE>
134  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
135  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
136  }
137 #endif
138 };
139 
140 }
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:102
gtsam::FastSet::FastSet
FastSet(const FastSet< VALUE > &x)
Definition: FastSet.h:74
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:125
gtsam::FastSet
Definition: FastSet.h:53
boost
Definition: boostmultiprec.cpp:109
gtsam::FastSet::FastSet
FastSet(const Base &x)
Definition: FastSet.h:79
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
gtsam::FastSet::operator=
FastSet & operator=(const FastSet &other)=default
anyset::size
size_t size() const
Definition: pytypes.h:2220
gtsam::FastSet::print
void print(const std::string &str="") const
Definition: FastSet.h:107
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:69
gtsam::FastSet::Base
std::set< VALUE, std::less< VALUE >, typename internal::FastDefaultAllocator< VALUE >::type > Base
Definition: FastSet.h:61
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:113


gtsam
Author(s):
autogenerated on Tue Jan 7 2025 04:02:15