diff --git a/nonlinear/TupleConfig.h b/nonlinear/TupleConfig.h index e683739f1..cf7f6d5a4 100644 --- a/nonlinear/TupleConfig.h +++ b/nonlinear/TupleConfig.h @@ -128,6 +128,9 @@ namespace gtsam { void erase(const Key& j) { second_.erase(j); } void erase(const Key1& j) { first_.erase(j); } + /** clears the config */ + void clear() { first_.clear(); second_.clear(); } + /** determine whether an element exists */ template bool exists(const Key& j) const { return second_.exists(j); } @@ -162,6 +165,9 @@ namespace gtsam { /** @return number of key/value pairs stored */ size_t size() const { return first_.size() + second_.size(); } + /** @return true if config is empty */ + bool empty() const { return first_.empty() && second_.empty(); } + /** @return The dimensionality of the tangent space */ size_t dim() const { return first_.dim() + second_.dim(); } @@ -241,6 +247,10 @@ namespace gtsam { void erase(const Key1& j) { first_.erase(j); } + void clear() { first_.clear(); } + + bool empty() const { return first_.empty(); } + bool exists(const Key1& j) const { return first_.exists(j); } boost::optional exists_(const Key1& j) const { return first_.exists_(j); } diff --git a/tests/testTupleConfig.cpp b/tests/testTupleConfig.cpp index dd682b36e..4dc146a68 100644 --- a/tests/testTupleConfig.cpp +++ b/tests/testTupleConfig.cpp @@ -95,7 +95,7 @@ TEST( TupleConfig, insert_equals2 ) CHECK(!config1.equals(config2)); } -///* ************************************************************************* */ +/* ************************************************************************* */ TEST( TupleConfig, insert_duplicate ) { Pose2 x1(1,2,3), x2(6,7,8); @@ -271,6 +271,16 @@ TEST(TupleConfig, basic_functions) { configB.erase(L1); CHECK(!configB.exists(L1)); CHECK(configB.size() == 2); + + // clear + configA.clear(); + CHECK(configA.size() == 0); + configB.clear(); + CHECK(configB.size() == 0); + + // empty + CHECK(configA.empty()); + CHECK(configB.empty()); } /* ************************************************************************* */