27 #include <boost/mpl/has_xxx.hpp>
28 #include <boost/utility/enable_if.hpp>
29 #include <boost/serialization/nvp.hpp>
30 #include <boost/serialization/set.hpp>
32 BOOST_MPL_HAS_XXX_TRAIT_DEF(
print)
38 template<
typename VALUE,
class ENABLE =
void>
48 template<
typename VALUE,
class ENABLE =
void>
49 class FastSet:
public std::set<VALUE, std::less<VALUE>, typename internal::FastDefaultAllocator<VALUE>::type> {
53 typedef std::set<VALUE, std::less<VALUE>,
typename internal::FastDefaultAllocator<VALUE>::type> Base;
60 template<
typename INPUTITERATOR>
61 explicit FastSet(INPUTITERATOR first, INPUTITERATOR last) :
66 template<
typename INPUTCONTAINER>
67 explicit FastSet(
const INPUTCONTAINER& container) :
68 Base(container.begin(), container.end()) {
81 #ifdef GTSAM_ALLOCATOR_BOOSTPOOL
83 FastSet(
const std::set<VALUE>& x) {
88 Base::insert(x.begin(), x.end());
93 operator std::set<VALUE>()
const {
94 return std::set<VALUE>(this->begin(), this->end());
98 bool exists(
const VALUE& e)
const {
return this->find(e) != this->end(); }
108 Base::insert(other.begin(),other.end());
113 friend class boost::serialization::access;
114 template<
class ARCHIVE>
115 void serialize(ARCHIVE & ar,
const unsigned int version) {
116 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
122 template<
typename VALUE,
class ENABLE>
123 struct FastSetTestableHelper {
125 typedef FastSet<VALUE> Set;
127 static void print(
const Set& set,
const std::string& str) {
128 std::cout << str <<
"\n";
129 for (
typename Set::const_iterator it = set.begin(); it != set.end(); ++it)
130 std::cout <<
" " << *it <<
"\n";
134 static bool equals(
const Set& set1,
const Set& set2,
double tol) {
135 typename Set::const_iterator it1 = set1.begin();
136 typename Set::const_iterator it2 = set2.begin();
137 while (it1 != set1.end()) {
138 if (it2 == set2.end() ||
139 fabs((
double)(*it1) - (
double)(*it2)) > tol)
149 template<
typename VALUE>
154 static void print(
const Set& set,
const std::string& str) {
155 std::cout << str <<
"\n";
156 for (
typename Set::const_iterator it = set.begin(); it != set.end(); ++it)
161 static bool equals(
const Set& set1,
const Set& set2,
double tol) {
162 typename Set::const_iterator it1 = set1.begin();
163 typename Set::const_iterator it2 = set2.begin();
164 while (it1 != set1.end()) {
165 if (it2 == set2.end() ||
FastSet(INPUTITERATOR first, INPUTITERATOR last)
Constructor from a range, passes through to base class.
Definition: FastSet.h:61
bool equals(const FastSet< VALUE > &other, double tol=1e-9) const
Check for equality within tolerance to implement Testable.
Definition: FastSet.h:104
void print(const std::string &str="") const
Print to implement Testable.
Definition: FastSet.h:101
FastSet()
Default constructor.
Definition: FastSet.h:56
bool exists(const VALUE &e) const
Handy 'exists' function.
Definition: FastSet.h:98
void print(const Matrix &A, const string &s, ostream &stream)
print a matrix
Definition: Matrix.cpp:183
An easy way to control which allocator is used for Fast* collections.
Template to create a binary predicate.
Definition: Testable.h:102
FastSet(const Base &x)
Copy constructor from the base set class.
Definition: FastSet.h:77
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
void merge(const FastSet &other)
insert another set: handy for MATLAB access
Definition: FastSet.h:107