mirror of
https://github.com/apple/swift-collections
synced 2026-11-26 04:47:48 +00:00
The Index type now represents a path into the tree, consisting of a series of child offsets from the root node, as well as the item offset within the final node. (This all fits in a couple of words, as the depth of the tree is fixed, and the offset path can always be compressed into a single `UInt` value.) To speed up basic operations, we also cache the final node as an unsafe-unowned reference. Dereferencing this is extremely unsafe, so the Index type carries an unsafe reference to the root node along with a mutation counter, to allow reliable(*) index validation. If index’s stored root is identical to the root of the collection, and they have the same version value, then we can assume that the index is still valid.