14#ifndef OR_TOOLS_ALGORITHMS_DYNAMIC_PERMUTATION_H_
15#define OR_TOOLS_ALGORITHMS_DYNAMIC_PERMUTATION_H_
22#include "absl/types/span.h"
27class SparsePermutation;
40 int Size()
const {
return image_.size(); }
49 void AddMappings(absl::Span<const int> src, absl::Span<const int> dst);
69 const std::vector<int>&
AllMappingsSrc()
const {
return mapping_src_stack_; }
85 const std::set<int>&
LooseEnds()
const {
return loose_ends_; }
96 std::vector<int> image_;
99 std::vector<int> ancestor_;
104 std::vector<int> mapping_src_stack_;
105 std::vector<int> mapping_src_size_stack_;
108 std::set<int> loose_ends_;
112 mutable std::vector<bool> tmp_mask_;
118 DCHECK_LT(i,
Size());
125 DCHECK_LT(i,
Size());
127 const int j = ancestor_[i];
128 if (j == i)
return i;
int RootOf(int i) const
Forced-inline for the speed.
const std::vector< int > & AllMappingsSrc() const
Returns the union of all "src" ever given to AddMappings().
int ImageOf(int i) const
Forced-inline for the speed.
const std::set< int > & LooseEnds() const
void UndoLastMappings(std::vector< int > *undone_mapping_src)
DynamicPermutation(int n)
Upon construction, every element i in [0..n-1] maps to itself.
void AddMappings(absl::Span< const int > src, absl::Span< const int > dst)
std::string DebugString() const
std::unique_ptr< SparsePermutation > CreateSparsePermutation() const
In SWIG mode, we don't want anything besides these top-level includes.