From 3de878b09eb45a6736142da6a48d2ca42394643b Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Thu, 25 Mar 2021 19:42:21 +0100 Subject: [PATCH] Cleanup --- src/indexmap.rs | 16 +++++++++------- src/indexset.rs | 3 ++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/indexmap.rs b/src/indexmap.rs index 6f77d306d0..c2e5d459b6 100644 --- a/src/indexmap.rs +++ b/src/indexmap.rs @@ -127,25 +127,27 @@ macro_rules! probe_loop { } struct CoreMap -where - K: Eq + Hash, { entries: Vec, N>, indices: [Option; N], } impl CoreMap -where - K: Eq + Hash, { - // TODO turn into a `const fn`; needs `mem::zeroed` to be a `const fn` - fn new() -> Self { + const fn new() -> Self { + const INIT: Option = None; + CoreMap { entries: Vec::new(), - indices: unsafe { MaybeUninit::zeroed().assume_init() }, + indices: [INIT; N], } } +} +impl CoreMap +where + K: Eq + Hash, +{ fn capacity() -> usize { N } diff --git a/src/indexset.rs b/src/indexset.rs index bd36df4161..232564717a 100644 --- a/src/indexset.rs +++ b/src/indexset.rs @@ -2,7 +2,6 @@ use crate::indexmap::{self, IndexMap}; use core::{borrow::Borrow, fmt, iter::FromIterator}; use hash32::{BuildHasher, BuildHasherDefault, FnvHasher, Hash, Hasher}; -// TODO: We don't enforce the power of 2 currently (part of generic array bounds) /// A [`heapless::IndexSet`](./struct.IndexSet.html) using the /// default FNV hasher. /// A list of all Methods and Traits available for `FnvIndexSet` can be found in @@ -89,6 +88,8 @@ where { /// Creates an empty `IndexSet` pub fn new() -> Self { + assert!(N.is_power_of_two()); + IndexSet { map: IndexMap::new(), }