Skip to content

Commit 3de878b

Browse files
committed
Cleanup
1 parent 305de71 commit 3de878b

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/indexmap.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,25 +127,27 @@ macro_rules! probe_loop {
127127
}
128128

129129
struct CoreMap<K, V, const N: usize>
130-
where
131-
K: Eq + Hash,
132130
{
133131
entries: Vec<Bucket<K, V>, N>,
134132
indices: [Option<Pos>; N],
135133
}
136134

137135
impl<K, V, const N: usize> CoreMap<K, V, N>
138-
where
139-
K: Eq + Hash,
140136
{
141-
// TODO turn into a `const fn`; needs `mem::zeroed` to be a `const fn`
142-
fn new() -> Self {
137+
const fn new() -> Self {
138+
const INIT: Option<Pos> = None;
139+
143140
CoreMap {
144141
entries: Vec::new(),
145-
indices: unsafe { MaybeUninit::zeroed().assume_init() },
142+
indices: [INIT; N],
146143
}
147144
}
145+
}
148146

147+
impl<K, V, const N: usize> CoreMap<K, V, N>
148+
where
149+
K: Eq + Hash,
150+
{
149151
fn capacity() -> usize {
150152
N
151153
}

src/indexset.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::indexmap::{self, IndexMap};
22
use core::{borrow::Borrow, fmt, iter::FromIterator};
33
use hash32::{BuildHasher, BuildHasherDefault, FnvHasher, Hash, Hasher};
44

5-
// TODO: We don't enforce the power of 2 currently (part of generic array bounds)
65
/// A [`heapless::IndexSet`](./struct.IndexSet.html) using the
76
/// default FNV hasher.
87
/// A list of all Methods and Traits available for `FnvIndexSet` can be found in
@@ -89,6 +88,8 @@ where
8988
{
9089
/// Creates an empty `IndexSet`
9190
pub fn new() -> Self {
91+
assert!(N.is_power_of_two());
92+
9293
IndexSet {
9394
map: IndexMap::new(),
9495
}

0 commit comments

Comments
 (0)