From 53a03a002176e1dde19384b72eab9e34c2feb580 Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Thu, 14 Jan 2010 16:05:04 +0000 Subject: [PATCH] Changed signature of tree insert --- cpp/FactorGraph-inl.h | 2 +- cpp/graph.h | 10 ++++++++-- cpp/testGraph.cpp | 12 ++++++------ cpp/testOrdering.cpp | 12 ++++++------ 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/cpp/FactorGraph-inl.h b/cpp/FactorGraph-inl.h index f23696cde..338e35b15 100644 --- a/cpp/FactorGraph-inl.h +++ b/cpp/FactorGraph-inl.h @@ -288,7 +288,7 @@ PredecessorMap FactorGraph::findMinimumSpanningTree() const { string key = boost::get(boost::vertex_name, g, *itVertex); string parent = boost::get(boost::vertex_name, g, *vi); // printf("%s parent: %s\n", key.c_str(), parent.c_str()); - tree.insert(make_pair(key, parent)); + tree.insert(key, parent); } return tree; diff --git a/cpp/graph.h b/cpp/graph.h index 946a8372d..2d8a66923 100644 --- a/cpp/graph.h +++ b/cpp/graph.h @@ -40,8 +40,14 @@ namespace gtsam { /** * Map from variable key to parent key */ - template - class PredecessorMap : public std::map {}; + template + class PredecessorMap: public std::map { + public: + /** convenience insert so we can pass ints for Symbol keys */ + inline void insert(const Key& key, const Key& parent) { + std::map::insert(std::make_pair(key, parent)); + } + }; /** * Convert the factor graph to an SDGraph diff --git a/cpp/testGraph.cpp b/cpp/testGraph.cpp index c3a82fe9b..1f7c5e6a0 100644 --- a/cpp/testGraph.cpp +++ b/cpp/testGraph.cpp @@ -29,9 +29,9 @@ TEST( Graph, predecessorMap2Graph ) map key2vertex; PredecessorMap p_map; - p_map.insert(make_pair("x1", "x2")); - p_map.insert(make_pair("x2", "x2")); - p_map.insert(make_pair("x3", "x2")); + p_map.insert("x1", "x2"); + p_map.insert("x2", "x2"); + p_map.insert("x3", "x2"); tie(graph, root, key2vertex) = predecessorMap2Graph, SVertex, string>(p_map); LONGS_EQUAL(3, boost::num_vertices(graph)); @@ -47,9 +47,9 @@ TEST( Graph, composePoses ) graph.push_back(boost::shared_ptr(new Pose2Factor(2,3, Pose2(3.0, 0.0, 0.0), cov))); PredecessorMap tree; - tree.insert(make_pair(1,2)); - tree.insert(make_pair(2,2)); - tree.insert(make_pair(3,2)); + tree.insert(1,2); + tree.insert(2,2); + tree.insert(3,2); Pose2 rootPose(3.0, 0.0, 0.0); diff --git a/cpp/testOrdering.cpp b/cpp/testOrdering.cpp index 2d70b275c..23beed59f 100644 --- a/cpp/testOrdering.cpp +++ b/cpp/testOrdering.cpp @@ -20,14 +20,14 @@ using namespace boost::assign; TEST ( Ordering, predecessorMap2Keys ) { typedef Symbol Key; PredecessorMap p_map; - p_map.insert(make_pair(Key(1), Key(1))); - p_map.insert(make_pair(Key(2), Key(1))); - p_map.insert(make_pair(Key(3), Key(1))); - p_map.insert(make_pair(Key(4), Key(3))); - p_map.insert(make_pair(Key(5), Key(1))); + p_map.insert(1,1); + p_map.insert(2,1); + p_map.insert(3,1); + p_map.insert(4,3); + p_map.insert(5,1); list expected; - expected += Key(4), Key(5), Key(3), Key(2), Key(1); + expected += 4,5,3,2,1;//Key(4), Key(5), Key(3), Key(2), Key(1); list actual = predecessorMap2Keys(p_map); LONGS_EQUAL(expected.size(), actual.size());