Removed useless typedef, add empty()

release/4.3a0
Frank Dellaert 2019-05-31 13:42:32 -04:00
parent bf904f9ff8
commit 0a95ac292f
5 changed files with 29 additions and 24 deletions

View File

@ -98,7 +98,7 @@ namespace gtsam {
for (size_t j = 0; j < n; j++)
{
// Retrieve the factors involving this variable and create the current node
const VariableIndex::Factors& factors = structure[order[j]];
const FactorIndices& factors = structure[order[j]];
const sharedNode node = boost::make_shared<Node>();
node->key = order[j];

View File

@ -79,7 +79,7 @@ Ordering Ordering::ColamdConstrained(const VariableIndex& variableIndex,
size_t index = 0;
for (auto key_factors: variableIndex) {
// Arrange factor indices into COLAMD format
const VariableIndex::Factors& column = key_factors.second;
const FactorIndices& column = key_factors.second;
for(size_t factorIndex: column) {
A[count++] = (int) factorIndex; // copy sparse column
}

View File

@ -67,8 +67,8 @@ void VariableIndex::remove(ITERATOR firstFactor, ITERATOR lastFactor,
"Internal error, requested inconsistent number of factor indices and factors in VariableIndex::remove");
if (factors[i]) {
for(Key j: *factors[i]) {
Factors& factorEntries = internalAt(j);
Factors::iterator entry = std::find(factorEntries.begin(),
FactorIndices& factorEntries = internalAt(j);
auto entry = std::find(factorEntries.begin(),
factorEntries.end(), *factorIndex);
if (entry == factorEntries.end())
throw std::invalid_argument(

View File

@ -41,26 +41,22 @@ namespace gtsam {
* \nosubgrouping
*/
class GTSAM_EXPORT VariableIndex {
public:
public:
typedef boost::shared_ptr<VariableIndex> shared_ptr;
typedef FactorIndices Factors;
typedef Factors::iterator Factor_iterator;
typedef Factors::const_iterator Factor_const_iterator;
typedef FactorIndices::iterator Factor_iterator;
typedef FactorIndices::const_iterator Factor_const_iterator;
protected:
typedef FastMap<Key,Factors> KeyMap;
protected:
typedef FastMap<Key, FactorIndices> KeyMap;
KeyMap index_;
size_t nFactors_; // Number of factors in the original factor graph.
size_t nEntries_; // Sum of involved variable counts of each factor.
size_t nFactors_; // Number of factors in the original factor graph.
size_t nEntries_; // Sum of involved variable counts of each factor.
public:
public:
typedef KeyMap::const_iterator const_iterator;
typedef KeyMap::const_iterator iterator;
typedef KeyMap::value_type value_type;
public:
/// @name Standard Constructors
/// @{
@ -71,8 +67,10 @@ public:
* Create a VariableIndex that computes and stores the block column structure
* of a factor graph.
*/
template<class FG>
VariableIndex(const FG& factorGraph) : nFactors_(0), nEntries_(0) { augment(factorGraph); }
template <class FG>
explicit VariableIndex(const FG& factorGraph) : nFactors_(0), nEntries_(0) {
augment(factorGraph);
}
/// @}
/// @name Standard Interface
@ -88,7 +86,7 @@ public:
size_t nEntries() const { return nEntries_; }
/// Access a list of factors by variable
const Factors& operator[](Key variable) const {
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 from VariableIndex");
@ -96,6 +94,11 @@ public:
return item->second;
}
/// Return true if no factors associated with a variable
const bool empty(Key variable) const {
return (*this)[variable].empty();
}
/// @}
/// @name Testable
/// @{
@ -166,16 +169,18 @@ protected:
Factor_const_iterator factorsEnd(Key variable) const { return internalAt(variable).end(); }
/// Internal version of 'at' that asserts existence
const Factors& internalAt(Key variable) const {
const FactorIndices& internalAt(Key variable) const {
const KeyMap::const_iterator item = index_.find(variable);
assert(item != index_.end());
return item->second; }
return item->second;
}
/// Internal version of 'at' that asserts existence
Factors& internalAt(Key variable) {
FactorIndices& internalAt(Key variable) {
const KeyMap::iterator item = index_.find(variable);
assert(item != index_.end());
return item->second; }
return item->second;
}
/// @}
};

View File

@ -43,7 +43,7 @@ namespace gtsam {
// keep track of which domains changed
changed[v] = false;
// loop over all factors/constraints for variable v
const VariableIndex::Factors& factors = index[v];
const FactorIndices& factors = index[v];
for(size_t f: factors) {
// if not already a singleton
if (!domains[v].isSingleton()) {