Relative Content

Tag Archive for linuxdata-structuresred-black-tree

Question About Node Replacement Strategy in Linux Red-Black Tree: Why Not Simply Swap Data Instead of Nodes?

I’m looking at the node replacement method in the Linux Red-Black tree implementation (rb_replace_node). To replace the victim node with newnode, all pointers that were pointing to victim are redirected to newnode, and then newnode‘s color, parent, left child, and right child pointers are replaced with those of victim. This has me puzzled: why can’t we simply replace the key and data fields of victim with those of newnode? This approach would seemingly achieve the same effect without actually swapping the two node variables, and it might be more efficient.