feat(ds): implement ‹From› and ‹FromIterator›
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
4c07bd4f2e
commit
3fcbbf4f81
1 changed files with 22 additions and 0 deletions
|
@ -26,3 +26,25 @@ impl<T: Ord> Default for MinHeap<T> {
|
||||||
Self::new()
|
Self::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T, const N: usize> From<[T; N]> for MinHeap<T>
|
||||||
|
where
|
||||||
|
T: Ord,
|
||||||
|
{
|
||||||
|
fn from(value: [T; N]) -> Self {
|
||||||
|
Self {
|
||||||
|
heap: BinaryHeap::from(value.map(|x| Reverse(x))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Ord> FromIterator<T> for MinHeap<T>
|
||||||
|
where
|
||||||
|
T: Ord,
|
||||||
|
{
|
||||||
|
fn from_iter<U: IntoIterator<Item = T>>(iter: U) -> Self {
|
||||||
|
Self {
|
||||||
|
heap: BinaryHeap::from_iter(iter.into_iter().map(|x| Reverse(x))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue