Skip to main content

collections/
heap.rs

1// SPDX-License-Identifier: Apache-2.0
2//
3// Written in 2022-2026 by Dr. Maxim Orlovsky <orlovsky@ubideco.org>
4//
5// Copyright 2022-2026 Laboratories for Ubiquitous and Deterministic Computing,
6// Institute for Distributed and Cognitive Computing (InDCS), Switzerland.
7// All rights reserved.
8//
9// Copyright (C) 2022-2026 Dr Maxim Orlovsky.
10// All rights reserved.
11//
12// Licensed under the Apache License, Version 2.0 (the "License"); you may not
13// use this file except in compliance with the License. You may obtain a copy of
14// the License at <http://www.apache.org/licenses/LICENSE-2.0>
15//
16// Unless required by applicable law or agreed to in writing, software
17// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
19// License for the specific language governing permissions and limitations under
20// the License.
21
22use alloc::collections::BinaryHeap;
23
24use super::{Collection, CollectionBase, CollectionCapacity};
25
26impl<T: Ord> CollectionBase for BinaryHeap<T> {
27    type Item = T;
28
29    fn item_count(&self) -> usize {
30        BinaryHeap::len(self)
31    }
32
33    fn push(&mut self, elem: Self::Item) {
34        BinaryHeap::push(self, elem)
35    }
36
37    fn clear(&mut self) {
38        BinaryHeap::clear(self)
39    }
40}
41
42impl<T: Ord> Collection for BinaryHeap<T> {
43    fn with_capacity(capacity: usize) -> Self {
44        BinaryHeap::with_capacity(capacity)
45    }
46}
47
48impl<T: Ord> CollectionCapacity for BinaryHeap<T> {
49    type ReserveError = alloc::collections::TryReserveError;
50
51    fn capacity(&self) -> usize {
52        BinaryHeap::capacity(self)
53    }
54
55    fn reserve(&mut self, additional: usize) {
56        BinaryHeap::reserve(self, additional)
57    }
58
59    fn try_reserve(&mut self, additional: usize) -> Result<(), Self::ReserveError> {
60        BinaryHeap::try_reserve(self, additional)
61    }
62}