From ce67d512d5ee9e1f9ee7ef304968c824e799aede Mon Sep 17 00:00:00 2001 From: Aditya Singh Date: Fri, 29 May 2026 00:52:15 -0700 Subject: [PATCH] [SortedCollections] Fix _BTree default node capacity capping at 16 The defaultInternalCapacity and defaultLeafCapacity computations used Swift.min(16, capacityInBytes / MemoryLayout.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 --- Sources/SortedCollections/BTree/_BTree.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/SortedCollections/BTree/_BTree.swift b/Sources/SortedCollections/BTree/_BTree.swift index dcaa6749..d8b12a42 100644 --- a/Sources/SortedCollections/BTree/_BTree.swift +++ b/Sources/SortedCollections/BTree/_BTree.swift @@ -31,7 +31,7 @@ internal struct _BTree { return 4 #else let capacityInBytes = 128 - return Swift.min(16, capacityInBytes / MemoryLayout.stride) + return Swift.max(16, capacityInBytes / MemoryLayout.stride) #endif } @@ -43,7 +43,7 @@ internal struct _BTree { return 5 #else let capacityInBytes = 2000 - return Swift.min(16, capacityInBytes / MemoryLayout.stride) + return Swift.max(16, capacityInBytes / MemoryLayout.stride) #endif }