[HashTreeCollections] Fix invariant violation in some operations

The two-child variant of _HashNode._regularNode did not check bucket ordering before placing children, leading to inaccessible nodes half of the time.
This commit is contained in:
Karoy Lorentey committed 2026-04-30 17:42:27 -07:00
1 parent 0fa494d3a8
commit 0ede027242
3 files changed
+40 -2

No files matched your search

@@ -166,8 +166,10 @@ extension _HashNode {
count: child1.count &+ child2.count
) { children, items in
assert(items.count == 0 && children.count == 2)
children.initializeElement(at: 0, to: child1)
children.initializeElement(at: 1, to: child2)
let i1 = child1Bucket < child2Bucket ? 0 : 1
let i2 = 1 &- i1
children.initializeElement(at: i1, to: child1)
children.initializeElement(at: i2, to: child2)
}
r.node._invariantCheck()
return r.node