import Foundation enum Buckets { static let lengths: [Int] = [256, 1024, 8192] static let batches: [Int] = [1] /// Round up `length` to nearest bucket, capped at `maxLen`. static func length(for length: Int, maxLen: Int) -> Int { let cap = min(maxLen, lengths.last ?? length) for bucket in lengths where bucket >= length { return min(bucket, cap) } return cap } /// Round up `batch` to nearest bucket, capped at `maxBatch`. static func batch(for batch: Int, maxBatch: Int) -> Int { let cap = min(maxBatch, batches.last ?? batch) for bucket in batches where bucket >= batch { return min(bucket, cap) } return cap } }