DiscreteValues::insert for single key-value pair

release/4.3a0
Varun Agrawal 2025-01-21 00:33:16 -05:00
parent 8460452990
commit dc79f492b2
2 changed files with 19 additions and 7 deletions

View File

@ -46,16 +46,22 @@ bool DiscreteValues::equals(const DiscreteValues& x, double tol) const {
return true;
}
/* ************************************************************************ */
DiscreteValues& DiscreteValues::insert(
const std::pair<Key, size_t>& assignment) {
if (count(assignment.first)) {
throw std::out_of_range(
"Requested to insert a DiscreteValues into another DiscreteValues "
"that already contains one or more of its keys.");
} else {
this->emplace(assignment);
}
return *this;
}
/* ************************************************************************ */
DiscreteValues& DiscreteValues::insert(const DiscreteValues& values) {
for (const auto& kv : values) {
if (count(kv.first)) {
throw std::out_of_range(
"Requested to insert a DiscreteValues into another DiscreteValues "
"that already contains one or more of its keys.");
} else {
this->emplace(kv);
}
this->insert(kv);
}
return *this;
}

View File

@ -69,6 +69,12 @@ class GTSAM_EXPORT DiscreteValues : public Assignment<Key> {
return Base::insert(value);
}
/**
* Insert key-assignment pair.
* Throws an invalid_argument exception if
* any keys to be inserted are already used. */
DiscreteValues& insert(const std::pair<Key, size_t>& assignment);
/** Insert all values from \c values. Throws an invalid_argument exception if
* any keys to be inserted are already used. */
DiscreteValues& insert(const DiscreteValues& values);