23 #include <boost/make_shared.hpp> 24 #include <boost/assign/std/list.hpp> 25 #include <boost/assign/std/set.hpp> 26 #include <boost/assign/std/vector.hpp> 32 using namespace gtsam;
66 typedef pair<size_t,size_t> Match;
68 matches += Match(1,2), Match(2,3), Match(4,5), Match(4,6);
72 for(
const Match&
m: matches)
76 size_t rep1 = 1, rep2 = 4;
87 boost::shared_ptr<DSFBase::V>
v = boost::make_shared<DSFBase::V>(5);
88 std::vector<size_t>
keys; keys += 1, 3;
98 map<size_t, set<size_t> > sets = dsf.
sets();
101 set<size_t>
expected; expected += 0, 1;
109 map<size_t, vector<size_t> > arrays = dsf.
arrays();
112 vector<size_t>
expected; expected += 0, 1;
121 map<size_t, set<size_t> > sets = dsf.
sets();
124 set<size_t>
expected; expected += 0, 1, 2;
133 map<size_t, vector<size_t> > arrays = dsf.
arrays();
136 vector<size_t>
expected; expected += 0, 1, 2;
144 map<size_t, set<size_t> > sets = dsf.
sets();
147 set<size_t>
expected; expected += 0, 1;
155 map<size_t, vector<size_t> > arrays = dsf.
arrays();
158 vector<size_t>
expected; expected += 0, 1;
166 set<size_t>
set = dsf.
set(0);
169 std::set<size_t>
expected; expected += 0, 1;
178 set<size_t>
set = dsf.
set(0);
181 std::set<size_t>
expected; expected += 0, 1, 2;
202 typedef pair<size_t,size_t> Match;
204 matches += Match(1,2), Match(2,3), Match(4,5), Match(4,6);
208 for(
const Match&
m: matches)
212 map<size_t, set<size_t> > sets = dsf.
sets();
214 set<size_t> expected1; expected1 += 1,2,3;
215 set<size_t> actual1 = sets[dsf.
find(2)];
216 EXPECT(expected1 == actual1);
217 set<size_t> expected2; expected2 += 4,5,6;
218 set<size_t> actual2 = sets[dsf.
find(5)];
219 EXPECT(expected2 == actual2);
static int runAllTests(TestResult &result)
bool isSingleton(const size_t &label) const
Find whether there is one and only one occurrence for the given {label}.
A faster implementation for DSF, which uses vector rather than btree.
size_t find(size_t key) const
Find the label of the set in which {key} lives.
std::map< size_t, std::vector< size_t > > arrays() const
Return all sets, i.e. a partition of all elements.
#define EXPECT(condition)
#define LONGS_EQUAL(expected, actual)
std::set< size_t > set(const size_t &label) const
Get the nodes in the tree with the given label.
#define EXPECT_LONGS_EQUAL(expected, actual)
std::map< size_t, std::set< size_t > > sets() const
Return all sets, i.e. a partition of all elements.
void merge(const size_t &i1, const size_t &i2)
Merge the sets containing i1 and i2. Does nothing if i1 and i2 are already in the same set...