31 std::vector<bool> should_be_deleted(
NumCycles(),
false);
32 for (
int i : cycle_indices) {
35 DCHECK(!should_be_deleted[i])
36 <<
"Duplicate index given to RemoveCycles(): " << i;
37 should_be_deleted[i] =
true;
39 int new_cycles_size = 0;
40 int new_cycle_ends_size = 0;
43 const int end = cycle_ends_[i];
44 if (!should_be_deleted[i]) {
46 cycles_[new_cycles_size++] = cycles_[j];
48 cycle_ends_[new_cycle_ends_size++] = new_cycles_size;
52 cycles_.resize(new_cycles_size);
53 cycle_ends_.resize(new_cycle_ends_size);
57 DCHECK_EQ(cycles_.empty(), cycle_ends_.empty());
58 if (!cycles_.empty()) DCHECK_EQ(cycles_.size(), cycle_ends_.back());
59 std::vector<std::vector<int>> cycles;
61 for (
const int end : cycle_ends_) {
64 for (
int i =
start + 1; i <
end; ++i) {
65 if (cycles_[i] < cycles_[min_pos]) min_pos = i;
67 std::vector<int> cycle;
68 for (
int i = min_pos; i <
end; ++i) cycle.push_back(cycles_[i]);
69 for (
int i =
start; i < min_pos; ++i) cycle.push_back(cycles_[i]);
70 cycles.push_back(std::move(cycle));
73 std::sort(cycles.begin(), cycles.end());
75 for (
const std::vector<int>& cycle : cycles) {
76 if (!out.empty()) out +=
" ";
78 out += absl::StrJoin(cycle,
" ");