mirror of
https://github.com/rust-embedded/heapless.git
synced 2025-10-02 06:50:32 +00:00
Cleanup
This commit is contained in:
parent
305de719f6
commit
3de878b09e
@ -127,25 +127,27 @@ macro_rules! probe_loop {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct CoreMap<K, V, const N: usize>
|
struct CoreMap<K, V, const N: usize>
|
||||||
where
|
|
||||||
K: Eq + Hash,
|
|
||||||
{
|
{
|
||||||
entries: Vec<Bucket<K, V>, N>,
|
entries: Vec<Bucket<K, V>, N>,
|
||||||
indices: [Option<Pos>; 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>
|
impl<K, V, const N: usize> CoreMap<K, V, N>
|
||||||
where
|
where
|
||||||
K: Eq + Hash,
|
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 {
|
fn capacity() -> usize {
|
||||||
N
|
N
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ use crate::indexmap::{self, IndexMap};
|
|||||||
use core::{borrow::Borrow, fmt, iter::FromIterator};
|
use core::{borrow::Borrow, fmt, iter::FromIterator};
|
||||||
use hash32::{BuildHasher, BuildHasherDefault, FnvHasher, Hash, Hasher};
|
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
|
/// A [`heapless::IndexSet`](./struct.IndexSet.html) using the
|
||||||
/// default FNV hasher.
|
/// default FNV hasher.
|
||||||
/// A list of all Methods and Traits available for `FnvIndexSet` can be found in
|
/// A list of all Methods and Traits available for `FnvIndexSet` can be found in
|
||||||
@ -89,6 +88,8 @@ where
|
|||||||
{
|
{
|
||||||
/// Creates an empty `IndexSet`
|
/// Creates an empty `IndexSet`
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
|
assert!(N.is_power_of_two());
|
||||||
|
|
||||||
IndexSet {
|
IndexSet {
|
||||||
map: IndexMap::new(),
|
map: IndexMap::new(),
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user