14#ifndef OR_TOOLS_MATH_OPT_ELEMENTAL_DIFF_H_
15#define OR_TOOLS_MATH_OPT_ELEMENTAL_DIFF_H_
20#include "absl/container/flat_hash_set.h"
21#include "absl/types/span.h"
58 void Advance(
const std::array<int64_t, kNumElements>& checkpoints);
69 return element_diff(e).checkpoint();
76 return element_diff(e).deleted();
84 mutable_element_diff(e).
Delete(
id);
93 template <
typename AttrType>
95 const AttrType a)
const {
96 return attr_diffs_[a].modified_keys();
100 template <
typename AttrType>
102 if (IsBeforeCheckpoint(a, attr_key)) {
103 attr_diffs_[a].SetModified(attr_key);
112 template <
typename AttrType>
115 if (!attr_diffs_[a].has_modified_keys()) {
118 for (
const auto& attr_key : keys) {
119 if (IsBeforeCheckpoint(a, attr_key)) {
120 attr_diffs_[a].Erase(attr_key);
126 const ElementDiff& element_diff(
const ElementType e)
const {
128 return element_diffs_[
static_cast<int>(e)];
131 ElementDiff& mutable_element_diff(
const ElementType e) {
132 return element_diffs_[
static_cast<int>(e)];
137 template <
typename AttrType>
139 for (
int i = 0; i < GetAttrKeySize<AttrType>(); ++
i) {
147 std::array<ElementDiff, kNumElements> element_diffs_;
150 using DiffForAttr = AttrDiff<AllAttrs::TypeDescriptor<i>::kNumKeyElements,
151 typename AllAttrs::TypeDescriptor<i>::Symmetry>;
152 AttrMap<DiffForAttr> attr_diffs_;
void EraseKeysForAttr(const AttrType a, absl::Span< const AttrKeyFor< AttrType > > keys)
const absl::flat_hash_set< int64_t > & deleted_elements(const ElementType e) const
void Advance(const std::array< int64_t, kNumElements > &checkpoints)
void DeleteElement(const ElementType e, int64_t id)
int64_t checkpoint(const ElementType e) const
void SetModified(const AttrType a, const AttrKeyFor< AttrType > attr_key)
Marks that the attribute a has been modified for attr_key.
const AttrKeyHashSet< AttrKeyFor< AttrType > > & modified_keys(const AttrType a) const
void Delete(int64_t id)
Tracks the element id as deleted if it is less than the checkpoint.
An object oriented wrapper for quadratic constraints in ModelStorage.
AttrKey< AttrTypeDescriptorT< AttrType >::kNumKeyElements, typename AttrTypeDescriptorT< AttrType >::Symmetry > AttrKeyFor
The type of the AttrKey for attribute type AttrType.
std::conditional_t<(AttrKeyT::size() > 0), absl::flat_hash_set< AttrKeyT >, detail::AttrKey0RawSet< typename AttrKeyT::SymmetryT, AttrKeyT > > AttrKeyHashSet
A hash set of AttrKeyT, where AttrKeyT is an AttrKey<n, Symmetry>.
constexpr std::array< ElementType, GetAttrKeySize< attr >()> GetElementTypes()