diff --git a/agb-hashmap/src/lib.rs b/agb-hashmap/src/lib.rs index ac767493..e99f6194 100644 --- a/agb-hashmap/src/lib.rs +++ b/agb-hashmap/src/lib.rs @@ -136,6 +136,7 @@ type HashType = u32; /// println!("{game}: \"{review}\""); /// } /// ``` +#[derive(Clone)] pub struct HashMap { nodes: NodeStorage, diff --git a/agb-hashmap/src/node.rs b/agb-hashmap/src/node.rs index e6b0305e..3331aa94 100644 --- a/agb-hashmap/src/node.rs +++ b/agb-hashmap/src/node.rs @@ -144,3 +144,28 @@ impl Default for Node { Self::new() } } + +impl Clone for Node +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(), + } + } + } +} diff --git a/agb-hashmap/src/node_storage.rs b/agb-hashmap/src/node_storage.rs index 295848f5..3b073446 100644 --- a/agb-hashmap/src/node_storage.rs +++ b/agb-hashmap/src/node_storage.rs @@ -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 { nodes: Vec, ALLOCATOR>, max_distance_to_initial_bucket: i32,