[SortedCollections] Fix _BTree default node capacity capping at 16

The defaultInternalCapacity and defaultLeafCapacity computations used
Swift.min(16, capacityInBytes / MemoryLayout<Key>.stride), which capped
the node capacity at 16 regardless of element size. This defeated the
byte-budget intent: small elements should yield larger nodes, not be
clamped to 16. Use Swift.max instead so 16 acts as a floor and the
byte budget governs the upper bound, as confirmed by the maintainer
in issue #257.

Fixes #257
This commit is contained in:
Aditya Singh committed 2026-05-29 00:52:15 -07:00
1 parent cef9727051
commit ce67d512d5
1 file changed
+2 -2
+2 -2
View File
@@ -31,7 +31,7 @@ internal struct _BTree<Key: Comparable, Value> {
return 4
#else
let capacityInBytes = 128
return Swift.min(16, capacityInBytes / MemoryLayout<Key>.stride)
return Swift.max(16, capacityInBytes / MemoryLayout<Key>.stride)
#endif
}
@@ -43,7 +43,7 @@ internal struct _BTree<Key: Comparable, Value> {
return 5
#else
let capacityInBytes = 2000
return Swift.min(16, capacityInBytes / MemoryLayout<Key>.stride)
return Swift.max(16, capacityInBytes / MemoryLayout<Key>.stride)
#endif
}