Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions gtsam/inference/VariableIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ namespace gtsam {

using namespace std;

const FactorIndices& VariableIndex::operator[](Key variable) const {
return index_.find(variable)->second;
}

const FactorIndices& VariableIndex::at(Key variable) const {
KeyMap::const_iterator item = index_.find(variable);
if(item == index_.end())
throw std::invalid_argument("Requested non-existent variable '" +
DefaultKeyFormatter(variable) +
"' from VariableIndex");
else
return item->second;
}

bool VariableIndex::empty(Key variable) const {
return (*this)[variable].empty();
}

/* ************************************************************************* */
bool VariableIndex::equals(const VariableIndex& other, double tol) const {
return this->nEntries_ == other.nEntries_ && this->nFactors_ == other.nFactors_
Expand Down
16 changes: 4 additions & 12 deletions gtsam/inference/VariableIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,13 @@ class GTSAM_EXPORT VariableIndex {
/// The number of nonzero blocks, i.e. the number of variable-factor entries
size_t nEntries() const { return nEntries_; }

/// Access a list of factors by variable without checking for existence
const FactorIndices& operator[](Key variable) const;
/// Access a list of factors by variable
const FactorIndices& operator[](Key variable) const {
KeyMap::const_iterator item = index_.find(variable);
if(item == index_.end())
throw std::invalid_argument("Requested non-existent variable '" +
DefaultKeyFormatter(variable) +
"' from VariableIndex");
else
return item->second;
}
const FactorIndices& at(Key variable) const;

/// Return true if no factors associated with a variable
bool empty(Key variable) const {
return (*this)[variable].empty();
}
bool empty(Key variable) const;

/// @}
/// @name Testable
Expand Down
Loading
Loading