fn replace(self: *Self, old: *Node, new: *Node) void 220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238 fn replace(self: *Self, old: *Node, new: *Node) void {
// copy over the values from the old node
new.key = old.key;
new.priority = old.priority;
new.parent = old.parent;
new.children = old.children;
// point the parent at the new node
const link = if (old.parent) |p| &p.children[@intFromBool(p.children[1] == old)] else &self.root;
assert(link.* == old);
link.* = new;
// point the children's parent at the new node
for (old.children) |child_node| {
const child = child_node orelse continue;
assert(child.parent == old);
child.parent = new;
}
}