Loading...
Searching...
No Matches
FastSet.h
Go to the documentation of this file.
/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
#pragma once
#include <boost/version.hpp>
#if BOOST_VERSION >= 107400
#include <boost/serialization/library_version_type.hpp>
#endif
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/set.hpp>
#include <gtsam/base/FastDefaultAllocator.h>
#include <gtsam/base/Testable.h>
#include <functional>
#include <set>
namespace boost {
namespace serialization {
class access;
} /* namespace serialization */
} /* namespace boost */
namespace gtsam {
template<typename VALUE>
class FastSet: public std::set<VALUE, std::less<VALUE>,
typename internal::FastDefaultAllocator<VALUE>::type> {
BOOST_CONCEPT_ASSERT ((IsTestable<VALUE> ));
public:
typedef std::set<VALUE, std::less<VALUE>,
typename internal::FastDefaultAllocator<VALUE>::type> Base;
using Base::Base; // Inherit the set constructors
FastSet() = default;
template<typename INPUTCONTAINER>
explicit FastSet(const INPUTCONTAINER& container) :
Base(container.begin(), container.end()) {
}
FastSet(const FastSet<VALUE>& x) :
Base(x) {
}
FastSet(const Base& x) :
Base(x) {
}
#ifdef GTSAM_ALLOCATOR_BOOSTPOOL
FastSet(const std::set<VALUE>& x) {
// This if statement works around a bug in boost pool allocator and/or
// STL vector where if the size is zero, the pool allocator will allocate
// huge amounts of memory.
if(x.size() > 0)
Base::insert(x.begin(), x.end());
}
#endif
operator std::set<VALUE>() const {
return std::set<VALUE>(this->begin(), this->end());
}
bool exists(const VALUE& e) const {
return this->find(e) != this->end();
}
void print(const std::string& str = "") const {
for (typename Base::const_iterator it = this->begin(); it != this->end(); ++it)
traits<VALUE>::Print(*it, str);
}
bool equals(const FastSet<VALUE>& other, double tol = 1e-9) const {
typename Base::const_iterator it1 = this->begin(), it2 = other.begin();
while (it1 != this->end()) {
if (it2 == other.end() || !traits<VALUE>::Equals(*it2, *it2, tol))
return false;
++it1;
++it2;
}
return true;
}
void merge(const FastSet& other) {
Base::insert(other.begin(), other.end());
}
private:
friend class boost::serialization::access;
template<class ARCHIVE>
void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
}
};
}
Testable.h
Concept check for values that can be used in unit tests.
FastDefaultAllocator.h
An easy way to control which allocator is used for Fast* collections.
gtsam
Global functions in a separate testing namespace.
Definition chartTesting.h:28
gtsam::traits
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition concepts.h:30
gtsam::FastSet::merge
void merge(const FastSet &other)
insert another set: handy for MATLAB access
Definition FastSet.h:119
gtsam::FastSet::print
void print(const std::string &str="") const
Print to implement Testable: pretty basic.
Definition FastSet.h:101
gtsam::FastSet::FastSet
FastSet(const INPUTCONTAINER &container)
Constructor from a iterable container, passes through to base class.
Definition FastSet.h:65
gtsam::FastSet::FastSet
FastSet(const FastSet< VALUE > &x)
Copy constructor from another FastSet.
Definition FastSet.h:70
gtsam::FastSet::exists
bool exists(const VALUE &e) const
Handy 'exists' function.
Definition FastSet.h:96
gtsam::FastSet::equals
bool equals(const FastSet< VALUE > &other, double tol=1e-9) const
Check for equality within tolerance to implement Testable.
Definition FastSet.h:107
gtsam::FastSet::FastSet
FastSet(const Base &x)
Copy constructor from the base set class.
Definition FastSet.h:75
gtsam::FastSet::FastSet
FastSet()=default
Default constructor.
gtsam::IsTestable
A testable concept check that should be placed in applicable unit tests and in generic algorithms.
Definition Testable.h:58