add n_siblings member, and when splits are created / removed update the number of siblings for the remaining nodes

This commit is contained in:
rhodes-b
2025-09-20 22:45:17 -05:00
parent 42fc42de2d
commit 3d3551d1ed
4 changed files with 47 additions and 40 deletions

View File

@@ -507,12 +507,16 @@ pub fn SplitTree(comptime V: type) type {
// We need to increase the reference count of all the nodes.
try refNodes(gpa, nodes);
return .{
const result: Self = .{
.arena = arena,
.nodes = nodes,
// Splitting always resets zoom state.
.zoomed = null,
};
result.updateNodesNumberSiblings();
return result;
}
/// Remove a node from the tree.
@@ -556,6 +560,8 @@ pub fn SplitTree(comptime V: type) type {
// Increase the reference count of all the nodes.
try refNodes(gpa, nodes);
result.updateNodesNumberSiblings();
return result;
}
@@ -865,6 +871,14 @@ pub fn SplitTree(comptime V: type) type {
};
}
/// Set the number of siblings for each split in the tree
fn updateNodesNumberSiblings(self: *const Self) void {
var it = self.iterator();
while (it.next()) |entry| {
entry.view.setNSiblings(self.nodes.len - 1);
}
}
/// Spatial representation of the split tree. See spatial.
pub const Spatial = struct {
/// The slots of the spatial representation in the same order