Skip to content

[Heap] Express heap operations on UnsafeMutableBufferPointer #75

@lorentey

Description

@lorentey

Heap currently uses regular array subscripting to access the contents of its storage. Array access is pretty fast, but it includes index validation that is (hopefully) unnecessary in Heap's case. I expect the optimizer is able to get rid of these index validations in some (but not all) cases; but it probably makes sense to not have them in the first place.

Rework the low-level heap implementation to operate on UnsafeMutableBuffer storage instead, turning index checks into debug-mode assertions rather than unconditional preconditions.

To do this, it would make sense to introduce a Heap._UnsafeHandle or _UnsafeHeap struct that consists of an UnsafeMutableBufferPointer value, and move most heap operation to that. We'll need to have closure-based read and update helpers that expose a read-only (or read-write) view of the Array storage. (Similar to how Deque and OrderedSet's hash tables work.)

Metadata

Metadata

Assignees

Labels

HeapMin-max heap moduleenhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions