Skip to content

Commit f3af76d

Browse files
authored
Merge pull request #260 from japaric/fix-index-structs
Fix bounds in IndexMap and IndexSet, IndexSet::new() is now const
2 parents e3c536b + 318da23 commit f3af76d

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

CHANGELOG.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
## [v0.7.9] - 2021-12-16
11+
12+
### Fixed
13+
14+
- Fix `IndexMap` and `IndexSet` bounds
15+
- Make `IndexSet::new()` a `const fn`
16+
1017
## [v0.7.8] - 2021-11-11
1118

1219
### Added
@@ -423,8 +430,9 @@ architecture.
423430

424431
- Initial release
425432

426-
[Unreleased]: https://github.com/japaric/heapless/compare/v0.7.8...HEAD
427-
[v0.7.9]: https://github.com/japaric/heapless/compare/v0.7.7...v0.7.8
433+
[Unreleased]: https://github.com/japaric/heapless/compare/v0.7.9...HEAD
434+
[v0.7.9]: https://github.com/japaric/heapless/compare/v0.7.8...v0.7.9
435+
[v0.7.8]: https://github.com/japaric/heapless/compare/v0.7.7...v0.7.8
428436
[v0.7.7]: https://github.com/japaric/heapless/compare/v0.7.6...v0.7.7
429437
[v0.7.6]: https://github.com/japaric/heapless/compare/v0.7.5...v0.7.6
430438
[v0.7.5]: https://github.com/japaric/heapless/compare/v0.7.4...v0.7.5

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ keywords = ["static", "no-heap"]
1212
license = "MIT OR Apache-2.0"
1313
name = "heapless"
1414
repository = "https://github.com/japaric/heapless"
15-
version = "0.7.8"
15+
version = "0.7.9"
1616

1717
[features]
1818
default = ["cas"]

src/indexmap.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ pub struct IndexMap<K, V, S, const N: usize> {
368368
impl<K, V, S, const N: usize> IndexMap<K, V, BuildHasherDefault<S>, N> {
369369
/// Creates an empty `IndexMap`.
370370
pub const fn new() -> Self {
371+
// Const assert
372+
crate::sealed::greater_than_1::<N>();
373+
crate::sealed::power_of_two::<N>();
374+
371375
IndexMap {
372376
build_hasher: BuildHasherDefault::new(),
373377
core: CoreMap::new(),

src/indexset.rs

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

55
/// A [`heapless::IndexSet`](./struct.IndexSet.html) using the
66
/// default FNV hasher.
@@ -74,22 +74,13 @@ pub type FnvIndexSet<T, const N: usize> = IndexSet<T, BuildHasherDefault<FnvHash
7474
/// println!("{}", book);
7575
/// }
7676
/// ```
77-
pub struct IndexSet<T, S, const N: usize>
78-
where
79-
T: Eq + Hash,
80-
{
77+
pub struct IndexSet<T, S, const N: usize> {
8178
map: IndexMap<T, (), S, N>,
8279
}
8380

84-
impl<T, S, const N: usize> IndexSet<T, BuildHasherDefault<S>, N>
85-
where
86-
T: Eq + Hash,
87-
S: Default + Hasher,
88-
{
81+
impl<T, S, const N: usize> IndexSet<T, BuildHasherDefault<S>, N> {
8982
/// Creates an empty `IndexSet`
90-
pub fn new() -> Self {
91-
assert!(N.is_power_of_two());
92-
83+
pub const fn new() -> Self {
9384
IndexSet {
9485
map: IndexMap::new(),
9586
}

0 commit comments

Comments
 (0)