mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 16:21:33 +11:00
Implement clone for hashmap
This commit is contained in:
parent
1cdf23683a
commit
5decb42cf0
|
@ -136,6 +136,7 @@ type HashType = u32;
|
|||
/// println!("{game}: \"{review}\"");
|
||||
/// }
|
||||
/// ```
|
||||
#[derive(Clone)]
|
||||
pub struct HashMap<K, V, ALLOCATOR: Allocator = Global> {
|
||||
nodes: NodeStorage<K, V, ALLOCATOR>,
|
||||
|
||||
|
|
|
@ -144,3 +144,28 @@ impl<K, V> Default for Node<K, V> {
|
|||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V> Clone for Node<K, V>
|
||||
where
|
||||
K: Clone,
|
||||
V: Clone,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
if self.has_value() {
|
||||
Self {
|
||||
hash: self.hash,
|
||||
distance_to_initial_bucket: self.distance_to_initial_bucket,
|
||||
key: MaybeUninit::new(unsafe { self.key.assume_init_ref() }.clone()),
|
||||
value: MaybeUninit::new(unsafe { self.value.assume_init_ref() }.clone()),
|
||||
}
|
||||
} else {
|
||||
Self {
|
||||
hash: self.hash,
|
||||
|
||||
distance_to_initial_bucket: self.distance_to_initial_bucket,
|
||||
key: MaybeUninit::uninit(),
|
||||
value: MaybeUninit::uninit(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ use alloc::{alloc::Global, vec::Vec};
|
|||
|
||||
use crate::{node::Node, number_before_resize, ClonableAllocator, HashType};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct NodeStorage<K, V, ALLOCATOR: Allocator = Global> {
|
||||
nodes: Vec<Node<K, V>, ALLOCATOR>,
|
||||
max_distance_to_initial_bucket: i32,
|
||||
|
|
Loading…
Reference in a new issue