32 absl::Span<const int> dst) {
33 DCHECK_EQ(src.size(), dst.size());
34 mapping_src_size_stack_.push_back(mapping_src_stack_.size());
35 mapping_src_stack_.reserve(mapping_src_stack_.size() + src.size());
36 for (
int i = 0; i < src.size(); ++i) {
40 DCHECK_EQ(d, ancestor_[d]);
45 if (image_[d] == d) loose_ends_.insert(d);
49 mapping_src_stack_.push_back(s);
54 std::vector<int>* undone_mapping_src) {
55 DCHECK(undone_mapping_src !=
nullptr);
56 undone_mapping_src->clear();
57 if (mapping_src_size_stack_.empty())
return;
58 const int num_mappings_before = mapping_src_size_stack_.back();
59 mapping_src_size_stack_.pop_back();
60 const int num_mappings_now = mapping_src_stack_.size();
61 DCHECK_GE(num_mappings_now, num_mappings_before);
63 undone_mapping_src->reserve(num_mappings_now - num_mappings_before);
64 undone_mapping_src->insert(undone_mapping_src->begin(),
65 mapping_src_stack_.begin() + num_mappings_before,
66 mapping_src_stack_.end());
69 for (
int i = num_mappings_now - 1; i >= num_mappings_before; --i) {
70 const int s = mapping_src_stack_[i];
73 if (ancestor_[s] != s) loose_ends_.insert(s);
79 mapping_src_stack_.resize(num_mappings_before);
96 int num_identity_singletons = 0;
97 for (
const int x : mapping_src_stack_) {
98 if (tmp_mask_[
x])
continue;
103 ++num_identity_singletons;
109 sparse_perm->AddToCurrentCycle(
next);
110 tmp_mask_[
next] =
true;
113 if (
next == root)
break;
115 sparse_perm->CloseCurrentCycle();
117 for (
const int x : mapping_src_stack_) tmp_mask_[
x] =
false;
118 DCHECK_EQ(mapping_src_stack_.size(),
119 sparse_perm->Support().size() + num_identity_singletons);