I'm implementing a binary heap, and in other languages, it's most convenient to do so by storing an internal array, but set the first element of this array to null
and ignore it. This way, if a node is located at index i
, its children will always be located at i * 2
and i * 2 + 1
.
This no longer works if index 0 is used, because 0 * 2 = 0. However, in Rust, there is no null
, so I would have to use Vec<Option<MyHeapItem>>
instead of Vec<MyHeapItem>
, which makes everything more cumbersome.
So my question is, is there a way to customize Vec<T>
so that index 1 refers to the first element?