Closed xingzhicn closed 5 years ago
Hi,
BinaryHeap::with_capacity_by()
does not limit the actual length of the heap.
It behaves exactly like Vec::with_capacity()
which allocate the capacity beforehand to avoid later reallocation.
For more explanation, please read the docs below:
This preallocates enough memory for capacity elements, so that the BinaryHeap does not have to be reallocated until it contains at least that many values.
If you want to limit the actual length of any BinaryHeap
or Vec
, you need to check .len()
before push
ing element onto it. I believe you can write a thin wrapper that perform this operation automatically.
I want to create a Binary Heap of fixed length,but the length is not expected.