28 boost::optional<const FactorIndices&> newFactorIndices) {
29 gttic(VariableIndex_augment);
32 for (
size_t i = 0; i < factors.size(); ++i) {
34 const size_t globalI =
35 newFactorIndices ? (*newFactorIndices)[i] : nFactors_;
36 for(
const Key key: *factors[i]) {
37 index_[key].push_back(globalI);
43 if (newFactorIndices) {
44 if ((*newFactorIndices)[i] >= nFactors_)
45 nFactors_ = (*newFactorIndices)[i] + 1;
53template<
typename ITERATOR,
class FG>
56 gttic(VariableIndex_remove);
62 ITERATOR factorIndex = firstFactor;
64 for (; factorIndex != lastFactor; ++factorIndex, ++i) {
65 if (i >= factors.size())
66 throw std::invalid_argument(
67 "Internal error, requested inconsistent number of factor indices and factors in VariableIndex::remove");
69 for(
Key j: *factors[i]) {
71 auto entry = std::find(factorEntries.begin(),
72 factorEntries.end(), *factorIndex);
73 if (entry == factorEntries.end())
74 throw std::invalid_argument(
75 "Internal error, indices and factors passed into VariableIndex::remove are not consistent with the existing variable index");
76 factorEntries.erase(entry);
84template<
typename ITERATOR>
86 for (ITERATOR key = firstKey; key != lastKey; ++key) {
87 KeyMap::iterator entry = index_.find(*key);
88 if (!entry->second.empty())
89 throw std::invalid_argument(
90 "Asking to remove variables from the variable index that are not unused");
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
FastVector< FactorIndex > FactorIndices
Define collection types:
Definition: Factor.h:33
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:69
const FactorIndices & internalAt(Key variable) const
Internal version of 'at' that asserts existence.
Definition: VariableIndex.h:172
void remove(ITERATOR firstFactor, ITERATOR lastFactor, const FG &factors)
Remove entries corresponding to the specified factors.
Definition: VariableIndex-inl.h:54
void removeUnusedVariables(ITERATOR firstKey, ITERATOR lastKey)
Remove unused empty variables (in debug mode verifies they are empty).
Definition: VariableIndex-inl.h:85
void augment(const FG &factors, boost::optional< const FactorIndices & > newFactorIndices=boost::none)
Augment the variable index with new factors.
Definition: VariableIndex-inl.h:27