This commit is contained in:
Emil Fresk 2021-03-25 19:42:21 +01:00
parent 305de719f6
commit 3de878b09e
2 changed files with 14 additions and 11 deletions

View File

@ -127,25 +127,27 @@ macro_rules! probe_loop {
}
struct CoreMap<K, V, const N: usize>
where
K: Eq + Hash,
{
entries: Vec<Bucket<K, V>, N>,
indices: [Option<Pos>; N],
}
impl<K, V, const N: usize> CoreMap<K, V, N>
{
const fn new() -> Self {
const INIT: Option<Pos> = None;
CoreMap {
entries: Vec::new(),
indices: [INIT; N],
}
}
}
impl<K, V, const N: usize> CoreMap<K, V, N>
where
K: Eq + Hash,
{
// TODO turn into a `const fn`; needs `mem::zeroed` to be a `const fn`
fn new() -> Self {
CoreMap {
entries: Vec::new(),
indices: unsafe { MaybeUninit::zeroed().assume_init() },
}
}
fn capacity() -> usize {
N
}

View File

@ -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(),
}