28 gttic(VariableIndex_augment);
31 for (
size_t i = 0; i < factors.size(); ++i) {
33 const size_t globalI =
34 newFactorIndices ? (*newFactorIndices)[i] : nFactors_;
35 BOOST_FOREACH(
const Key key, *factors[i]) {
36 index_[key].push_back(globalI);
42 if (newFactorIndices) {
43 if ((*newFactorIndices)[i] >= nFactors_)
44 nFactors_ = (*newFactorIndices)[i] + 1;
52 template<
typename ITERATOR,
class FG>
55 gttic(VariableIndex_remove);
61 ITERATOR factorIndex = firstFactor;
63 for (; factorIndex != lastFactor; ++factorIndex, ++i) {
64 if (i >= factors.size())
65 throw std::invalid_argument(
66 "Internal error, requested inconsistent number of factor indices and factors in VariableIndex::remove");
68 BOOST_FOREACH(
Key j, *factors[i]) {
70 Factors::iterator entry = std::find(factorEntries.begin(),
71 factorEntries.end(), *factorIndex);
72 if (entry == factorEntries.end())
73 throw std::invalid_argument(
74 "Internal error, indices and factors passed into VariableIndex::remove are not consistent with the existing variable index");
75 factorEntries.erase(entry);
83 template<
typename ITERATOR>
85 for (ITERATOR key = firstKey; key != lastKey; ++key) {
86 KeyMap::iterator entry = index_.find(*key);
87 if (!entry->second.empty())
88 throw std::invalid_argument(
89 "Asking to remove variables from the variable index that are not unused");
void remove(ITERATOR firstFactor, ITERATOR lastFactor, const FG &factors)
Remove entries corresponding to the specified factors.
Definition: VariableIndex-inl.h:53
void removeUnusedVariables(ITERATOR firstKey, ITERATOR lastKey)
Remove unused empty variables (in debug mode verifies they are empty).
Definition: VariableIndex-inl.h:84
const Factors & internalAt(Key variable) const
Internal version of 'at' that asserts existence.
Definition: VariableIndex.h:164
size_t Key
Integer nonlinear key type.
Definition: types.h:59
Definition: FastList.h:38
void augment(const FG &factors, boost::optional< const FastVector< size_t > & > newFactorIndices=boost::none)
Augment the variable index with new factors.
Definition: VariableIndex-inl.h:26