39 const int n =
static_cast<int>(rows.size());
41 for (
const Row& row : rows)
42 maxDepth = std::max(maxDepth,
static_cast<int>(row.depth));
45 std::vector<uint8_t> later(
static_cast<size_t>(maxDepth) + 1, 0);
49 std::vector<int> open;
50 for (
int i = n - 1; i >= 0; --i)
52 const int D = std::max(0,
static_cast<int>(rows[i].depth));
53 while (!open.empty() && rows[open.back()].depth > D)
55 rows[i].skipCount = (open.empty() ? n : open.back()) - i - 1;
59 for (
int d = 0; d <= D - 2 && d < 32; d++)
60 if (d + 1 <= highest && later[
size_t(d + 1)])
62 rows[i].ancestorLineMask = mask;
63 rows[i].isLastSibling = !(D <= highest && later[size_t(D)]);
66 for (
int t = D + 1; t <= highest; t++)
82 const int n =
static_cast<int>(rows.size());
83 if (srcDs < 0 || srcDs >= n)
return -1;
84 if (dstDs < 0 || dstDs >= n)
return -1;
85 if (srcDs == dstDs)
return -1;
87 const int srcStart = srcDs;
88 const int srcSliceCount = 1 + rows[srcStart].skipCount;
89 const int srcEnd = srcStart + srcSliceCount;
92 if (dstDs >= srcStart && dstDs < srcEnd)
return -1;
94 int targetBaseDepth = rows[dstDs].depth;
96 auto openTarget = [&] {
97 if constexpr (
requires { rows[dstDs].isOpen =
true; })
98 rows[dstDs].isOpen =
true;
104 targetBaseDepth = rows[dstDs].depth;
108 insertAt = dstDs + 1;
109 targetBaseDepth = rows[dstDs].depth + 1;
114 insertAt = dstDs + 1 + rows[dstDs].skipCount;
115 targetBaseDepth = rows[dstDs].depth + 1;
119 insertAt = dstDs + 1 + rows[dstDs].skipCount;
120 targetBaseDepth = rows[dstDs].depth;
126 const int srcBaseDepth = rows[srcStart].depth;
127 const int deltaDepth = targetBaseDepth - srcBaseDepth;
128 std::vector<Row> lifted;
129 lifted.reserve(srcSliceCount);
130 lifted.insert(lifted.end(),
131 std::make_move_iterator(rows.begin() + srcStart),
132 std::make_move_iterator(rows.begin() + srcEnd));
134 for (
auto& r : lifted) r.depth += deltaDepth;
136 rows.erase(rows.begin() + srcStart, rows.begin() + srcEnd);
137 if (insertAt > srcStart) insertAt -= srcSliceCount;
138 rows.insert(rows.begin() + insertAt,
139 std::make_move_iterator(lifted.begin()),
140 std::make_move_iterator(lifted.end()));