IndexMap::new() is now a const-fn

This commit is contained in:
Emil Fresk 2021-04-19 21:31:47 +02:00
parent 6fdcc4fb99
commit 58cb279aec
4 changed files with 6 additions and 51 deletions

View File

@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- `Pool` and `MPMC` now works on `thumbv6m`
- [breaking-change] `String` has had `utf8` related methods removed as this can be done via `str`
- [breaking-change] No data structures implement `AsSlice` traits any more, now using `AsRef` and `AsMut`
- `IndexMap::new()` is now a `const-fn`
## [v0.6.1] - 2021-03-02

View File

@ -36,7 +36,7 @@ scoped_threadpool = "0.1.8"
atomic-polyfill = "0.1.2"
[dependencies]
hash32 = "0.1.0"
hash32 = "0.2.1"
[dependencies.serde]
version = "1"

View File

@ -360,25 +360,16 @@ where
/// println!("{}: \"{}\"", book, review);
/// }
/// ```
pub struct IndexMap<K, V, S, const N: usize>
where
K: Eq + Hash,
{
pub struct IndexMap<K, V, S, const N: usize> {
core: CoreMap<K, V, N>,
build_hasher: S,
}
impl<K, V, S, const N: usize> IndexMap<K, V, BuildHasherDefault<S>, N>
where
K: Eq + Hash,
S: Default + Hasher,
{
impl<K, V, S, const N: usize> IndexMap<K, V, BuildHasherDefault<S>, N> {
/// Creates an empty `IndexMap`.
///
/// **NOTE** This constructor will become a `const fn` in the future
pub fn new() -> Self {
pub const fn new() -> Self {
IndexMap {
build_hasher: BuildHasherDefault::default(),
build_hasher: BuildHasherDefault::new(),
core: CoreMap::new(),
}
}
@ -737,7 +728,6 @@ where
K: Eq + Hash + Borrow<Q>,
Q: ?Sized + Eq + Hash,
S: BuildHasher,
// N: ArrayLength<Bucket<K, V>> + ArrayLength<Option<Pos>>,
{
type Output = V;
@ -751,7 +741,6 @@ where
K: Eq + Hash + Borrow<Q>,
Q: ?Sized + Eq + Hash,
S: BuildHasher,
// N: ArrayLength<Bucket<K, V>> + ArrayLength<Option<Pos>>,
{
fn index_mut(&mut self, key: &Q) -> &mut V {
self.get_mut(key).expect("key not found")
@ -763,7 +752,6 @@ where
K: Eq + Hash + Clone,
V: Clone,
S: Clone,
// N: ArrayLength<Bucket<K, V>> + ArrayLength<Option<Pos>>,
{
fn clone(&self) -> Self {
Self {
@ -778,7 +766,6 @@ where
K: Eq + Hash + fmt::Debug,
V: fmt::Debug,
S: BuildHasher,
// N: ArrayLength<Bucket<K, V>> + ArrayLength<Option<Pos>>,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_map().entries(self.iter()).finish()
@ -789,7 +776,6 @@ impl<K, V, S, const N: usize> Default for IndexMap<K, V, S, N>
where
K: Eq + Hash,
S: BuildHasher + Default,
// N: ArrayLength<Bucket<K, V>> + ArrayLength<Option<Pos>>,
{
fn default() -> Self {
IndexMap {

View File

@ -389,38 +389,6 @@ impl<const N1: usize, const N2: usize> PartialEq<String<N2>> for String<N1> {
}
}
// macro_rules! impl_eq {
// ($lhs:ty, $rhs:ty) => {
// impl<'a, 'b, N> PartialEq<$rhs> for $lhs
// where
// N: ArrayLength<u8>,
// {
// #[inline]
// fn eq(&self, other: &$rhs) -> bool {
// str::eq(&self[..], &other[..])
// }
// #[inline]
// fn ne(&self, other: &$rhs) -> bool {
// str::ne(&self[..], &other[..])
// }
// }
// impl<'a, 'b, N> PartialEq<$lhs> for $rhs
// where
// N: ArrayLength<u8>,
// {
// #[inline]
// fn eq(&self, other: &$lhs) -> bool {
// str::eq(&self[..], &other[..])
// }
// #[inline]
// fn ne(&self, other: &$lhs) -> bool {
// str::ne(&self[..], &other[..])
// }
// }
// };
// }
// String<N> == str
impl<const N: usize> PartialEq<str> for String<N> {
#[inline]