memusage/builtin/
heap.rs

1//! Implementation of `MemoryReport` for `BinaryHeap`.
2
3
4
5use crate::MemoryReport;
6use alloc::collections::BinaryHeap;
7
8
9
10impl<T: MemoryReport> MemoryReport for BinaryHeap<T> {
11    const ALLOC: bool = true;
12    const CHILD: bool = true;
13
14    fn indirect(&self) -> usize {
15        self.capacity() * T::direct()
16    }
17
18    fn children(&self) -> usize {
19        if T::ALLOC || T::CHILD {
20            self.iter().map(|x| x.indirect() + x.children()).sum()
21        } else {
22            0
23        }
24    }
25}