apple / swift-collections

Commonly used data structures for Swift
Apache License 2.0
3.55k stars 270 forks source link

Bugfix Incorrect Assert in BTree.removeFirst/removeLast #349

Closed LeoNavel closed 3 months ago

LeoNavel commented 4 months ago

_BTree.removeFirst(_:) and _BTree.removeLast(_:) contains following incorrect assert:

assert(0 <= k && k < self.count, "Can't remove more items from a collection than it contains")

This assertion will cause a crash (in debug mode) when we call one of these functions with the same number of items as the collection contains.

This PR solves this issue by replacing k < self.count with k <= self.count in the assert.

Checklist

lorentey commented 4 months ago

@swift-ci test