@@ -493,7 +493,7 @@ func (txn *Txn[T]) delete(root *header[T], key []byte) (oldValue T, hadOld bool,
493493 return
494494}
495495
496- func (txn * Txn [T ]) removeChild (parent * header [T ], index int ) * header [T ] {
496+ func (txn * Txn [T ]) removeChild (parent * header [T ], index int ) ( newParent * header [T ]) {
497497 size := parent .size ()
498498 switch {
499499 case size == 2 && parent .getLeaf () == nil :
@@ -512,11 +512,13 @@ func (txn *Txn[T]) removeChild(parent *header[T], index int) *header[T] {
512512 childClone := child .clone (false )
513513 childClone .watch = child .watch
514514 childClone .setPrefix (slices .Concat (parent .prefix (), childClone .prefix ()))
515- nodeMutatedSet (txn .mutated , childClone )
516- return childClone
515+ newParent = childClone
517516
518517 case parent .kind () == nodeKind256 && size <= 49 :
519518 demoted := (& node48 [T ]{header : * parent }).self ()
519+ if parent .watch != nil {
520+ demoted .watch = make (chan struct {})
521+ }
520522 demoted .setKind (nodeKind48 )
521523 demoted .setSize (size - 1 )
522524 n48 := demoted .node48 ()
@@ -528,10 +530,12 @@ func (txn *Txn[T]) removeChild(parent *header[T], index int) *header[T] {
528530 children = append (children , n )
529531 }
530532 }
531- nodeMutatedSet (txn .mutated , demoted )
532- return demoted
533+ newParent = demoted
533534 case parent .kind () == nodeKind48 && size <= 17 :
534535 demoted := (& node16 [T ]{header : * parent }).self ()
536+ if parent .watch != nil {
537+ demoted .watch = make (chan struct {})
538+ }
535539 demoted .setKind (nodeKind16 )
536540 demoted .setSize (size - 1 )
537541 n16 := demoted .node16 ()
@@ -544,10 +548,12 @@ func (txn *Txn[T]) removeChild(parent *header[T], index int) *header[T] {
544548 idx ++
545549 }
546550 }
547- nodeMutatedSet (txn .mutated , demoted )
548- return demoted
551+ newParent = demoted
549552 case parent .kind () == nodeKind16 && size <= 5 :
550553 demoted := (& node4 [T ]{header : * parent }).self ()
554+ if parent .watch != nil {
555+ demoted .watch = make (chan struct {})
556+ }
551557 demoted .setKind (nodeKind4 )
552558 demoted .setSize (size - 1 )
553559 n16 := parent .node16 ()
@@ -561,13 +567,17 @@ func (txn *Txn[T]) removeChild(parent *header[T], index int) *header[T] {
561567 idx ++
562568 }
563569 }
564- nodeMutatedSet (txn .mutated , demoted )
565- return demoted
570+ newParent = demoted
566571 default :
567- parent = txn .cloneNode (parent )
568- parent .remove (index )
569- return parent
572+ newParent = txn .cloneNode (parent )
573+ newParent .remove (index )
574+ return newParent
575+ }
576+ if parent .watch != nil {
577+ txn .watches [parent .watch ] = struct {}{}
570578 }
579+ nodeMutatedSet (txn .mutated , newParent )
580+ return newParent
571581}
572582
573583var runValidation = os .Getenv ("PART_VALIDATE" ) != ""
0 commit comments