Fix bounds in IndexMap and IndexSet, IndexSet::new() is now const

This commit is contained in:
Emil Fresk 2021-12-16 10:37:23 +01:00
parent e3c536b3c2
commit 318da23c43
4 changed files with 19 additions and 16 deletions

View File

@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
## [v0.7.9] - 2021-12-16
### Fixed
- Fix `IndexMap` and `IndexSet` bounds
- Make `IndexSet::new()` a `const fn`
## [v0.7.8] - 2021-11-11
### Added
@ -423,8 +430,9 @@ architecture.
- Initial release
[Unreleased]: https://github.com/japaric/heapless/compare/v0.7.8...HEAD
[v0.7.9]: https://github.com/japaric/heapless/compare/v0.7.7...v0.7.8
[Unreleased]: https://github.com/japaric/heapless/compare/v0.7.9...HEAD
[v0.7.9]: https://github.com/japaric/heapless/compare/v0.7.8...v0.7.9
[v0.7.8]: https://github.com/japaric/heapless/compare/v0.7.7...v0.7.8
[v0.7.7]: https://github.com/japaric/heapless/compare/v0.7.6...v0.7.7
[v0.7.6]: https://github.com/japaric/heapless/compare/v0.7.5...v0.7.6
[v0.7.5]: https://github.com/japaric/heapless/compare/v0.7.4...v0.7.5

View File

@ -12,7 +12,7 @@ keywords = ["static", "no-heap"]
license = "MIT OR Apache-2.0"
name = "heapless"
repository = "https://github.com/japaric/heapless"
version = "0.7.8"
version = "0.7.9"
[features]
default = ["cas"]

View File

@ -368,6 +368,10 @@ pub struct IndexMap<K, V, S, const N: usize> {
impl<K, V, S, const N: usize> IndexMap<K, V, BuildHasherDefault<S>, N> {
/// Creates an empty `IndexMap`.
pub const fn new() -> Self {
// Const assert
crate::sealed::greater_than_1::<N>();
crate::sealed::power_of_two::<N>();
IndexMap {
build_hasher: BuildHasherDefault::new(),
core: CoreMap::new(),

View File

@ -1,6 +1,6 @@
use crate::indexmap::{self, IndexMap};
use core::{borrow::Borrow, fmt, iter::FromIterator};
use hash32::{BuildHasher, BuildHasherDefault, FnvHasher, Hash, Hasher};
use hash32::{BuildHasher, BuildHasherDefault, FnvHasher, Hash};
/// A [`heapless::IndexSet`](./struct.IndexSet.html) using the
/// default FNV hasher.
@ -74,22 +74,13 @@ pub type FnvIndexSet<T, const N: usize> = IndexSet<T, BuildHasherDefault<FnvHash
/// println!("{}", book);
/// }
/// ```
pub struct IndexSet<T, S, const N: usize>
where
T: Eq + Hash,
{
pub struct IndexSet<T, S, const N: usize> {
map: IndexMap<T, (), S, N>,
}
impl<T, S, const N: usize> IndexSet<T, BuildHasherDefault<S>, N>
where
T: Eq + Hash,
S: Default + Hasher,
{
impl<T, S, const N: usize> IndexSet<T, BuildHasherDefault<S>, N> {
/// Creates an empty `IndexSet`
pub fn new() -> Self {
assert!(N.is_power_of_two());
pub const fn new() -> Self {
IndexSet {
map: IndexMap::new(),
}