From ef2ee4f4de9cc7662618beac0536982b6dceb039 Mon Sep 17 00:00:00 2001 From: Dominic Date: Fri, 21 Feb 2025 15:46:04 +0100 Subject: [PATCH] Require `Clone` instead of `Copy` for the key --- src/lib.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index bccc96d..a93294c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,7 +34,7 @@ pub struct RadixHeapMap { initial: Bucket, } -impl RadixHeapMap { +impl RadixHeapMap { /// Create an empty `RadixHeapMap` pub fn new() -> RadixHeapMap { RadixHeapMap { @@ -98,17 +98,18 @@ impl RadixHeapMap { return; }; - let top = *repush + let top = repush .iter() .map(|(k, _)| k) .max() - .expect("Expected non-empty bucket"); - - self.top = Some(top); + .expect("Expected non-empty bucket") + .clone(); repush .drain(..) .for_each(|(key, value)| buckets[key.radix_distance(&top) as usize].push((key, value))); + + self.top = Some(top); } /// Pushes a new key value pair onto the heap. @@ -118,9 +119,9 @@ impl RadixHeapMap { /// Panics if the key is larger than the current top key. #[inline] pub fn push(&mut self, key: K, value: V) { - let bucket = if let Some(top) = self.top { - assert!(key <= top, "Key must be lower or equal to current top key"); - &mut self.buckets[key.radix_distance(&top) as usize] + let bucket = if let Some(top) = &self.top { + assert!(key <= *top, "Key must be lower or equal to current top key"); + &mut self.buckets[key.radix_distance(top) as usize] } else { &mut self.initial }; @@ -165,7 +166,7 @@ impl RadixHeapMap { /// The current top value. All keys pushed onto the heap must be smaller than this value. #[inline] pub fn top(&self) -> Option { - self.top + self.top.clone() } /// Discards as much additional capacity as possible.