Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
authors = ["Heinz N. Gies <[email protected]>"]
description = "Multi backend HashMap for higher performance on different key space sizes"
edition = "2018"
edition = "2024"
license = "Apache-2.0/MIT"
name = "halfbrown"
repository = "https://github.com/Licenser/halfbrown"
version = "0.3.0"
version = "0.4.0"

[dependencies]
hashbrown = "0.16"
Expand Down
29 changes: 14 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
//! Note: Most of the documentation is taken from
//! rusts hashmap.rs and should be considered under
//! their copyright.

#![warn(unused_extern_crates)]
#![deny(
clippy::all,
Expand All @@ -26,7 +25,7 @@
clippy::pedantic
)]
// We might want to revisit inline_always
#![allow(clippy::module_name_repetitions, clippy::inline_always)]
#![allow(clippy::module_name_repetitions)]
#![deny(missing_docs)]

mod entry;
Expand Down Expand Up @@ -436,7 +435,7 @@ impl<K, V, S, const VEC_LIMIT_UPPER: usize> SizedHashMap<K, V, S, VEC_LIMIT_UPPE
/// assert!(a.is_empty());
/// ```
#[inline]
pub fn drain(&mut self) -> Drain<K, V, VEC_LIMIT_UPPER> {
pub fn drain(&'_ mut self) -> Drain<'_, K, V, VEC_LIMIT_UPPER> {
match &mut self.0 {
HashMapInt::Map(m) => Drain(DrainInt::Map(m.drain())),
HashMapInt::Vec(m) => Drain(DrainInt::Vec(m.drain())),
Expand Down Expand Up @@ -562,14 +561,14 @@ where
/// assert_eq!(letters[&'u'], 1);
/// assert_eq!(letters.get(&'y'), None);
/// ```
pub fn entry(&mut self, key: K) -> Entry<K, V, VEC_LIMIT_UPPER, S>
pub fn entry(&'_ mut self, key: K) -> Entry<'_, K, V, VEC_LIMIT_UPPER, S>
where
S: Default,
{
if let HashMapInt::Vec(m) = &self.0 {
if m.len() >= VEC_LIMIT_UPPER {
self.swap_backend_to_map();
}
if let HashMapInt::Vec(m) = &self.0
&& m.len() >= VEC_LIMIT_UPPER
{
self.swap_backend_to_map();
}
match &mut self.0 {
HashMapInt::Map(m) => m.entry(key).into(),
Expand Down Expand Up @@ -838,12 +837,12 @@ where
{
match &mut self.0 {
HashMapInt::Map(m) => {
m.insert_unique_unchecked(k, v);
unsafe { m.insert_unique_unchecked(k, v) };
}
HashMapInt::Vec(m) => {
if m.len() >= VEC_LIMIT_UPPER {
let map = self.swap_backend_to_map();
map.insert_unique_unchecked(k, v);
unsafe { map.insert_unique_unchecked(k, v) };
} else {
m.insert_nocheck(k, v);
}
Expand Down Expand Up @@ -930,10 +929,10 @@ where
where
S: Default,
{
if let HashMapInt::Vec(m) = &self.0 {
if m.len() >= VEC_LIMIT_UPPER {
self.swap_backend_to_map();
}
if let HashMapInt::Vec(m) = &self.0
&& m.len() >= VEC_LIMIT_UPPER
{
self.swap_backend_to_map();
}
match &mut self.0 {
HashMapInt::Vec(m) => RawEntryBuilderMut::from(m.raw_entry_mut()),
Expand Down Expand Up @@ -978,7 +977,7 @@ where
}

self.iter()
.all(|(key, value)| other.get(key).map_or(false, |v| *value == *v))
.all(|(key, value)| other.get(key).is_some_and(|v| *value == *v))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod se {
S: Serializer,
{
let mut map = serializer.serialize_map(Some(self.len()))?;
for (k, v) in self.iter() {
for (k, v) in self {
map.serialize_entry(k, v)?;
}
map.end()
Expand Down
12 changes: 6 additions & 6 deletions src/vecmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ mod raw_entry;

pub(crate) use self::entry::*;
pub(crate) use self::raw_entry::*;
use crate::vectypes::VecDrain;
use crate::DefaultHashBuilder;
use crate::vectypes::VecDrain;
use std::borrow::Borrow;

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -43,7 +43,7 @@ where
}

self.iter()
.all(|(key, value)| other.get(key).map_or(false, |v| value == v.borrow()))
.all(|(key, value)| other.get(key).is_some_and(|v| value == v.borrow()))
}
}

Expand Down Expand Up @@ -83,7 +83,7 @@ impl<K, V, const N: usize, S> VecMap<K, V, N, S> {

#[cfg(feature = "arraybackend")]
#[inline]
pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self {
pub fn with_capacity_and_hasher(_capacity: usize, hash_builder: S) -> Self {
let v = arrayvec::ArrayVec::new();
Self { v, hash_builder }
}
Expand Down Expand Up @@ -132,7 +132,7 @@ impl<K, V, const N: usize, S> VecMap<K, V, N, S> {
}

#[inline]
pub(crate) fn drain(&mut self) -> VecDrain<(K, V), N> {
pub(crate) fn drain(&'_ mut self) -> VecDrain<'_, (K, V), N> {
self.v.drain(..)
}

Expand Down Expand Up @@ -214,7 +214,7 @@ impl<K, V, const N: usize, S> VecMap<K, V, N, S> {
self.v.push((k, v));
}

pub(crate) fn entry(&mut self, key: K) -> Entry<K, V, N, S>
pub(crate) fn entry(&'_ mut self, key: K) -> Entry<'_, K, V, N, S>
where
K: Eq,
{
Expand Down Expand Up @@ -339,7 +339,7 @@ impl<K, V, const N: usize, S> VecMap<K, V, N, S> {
/// inserts a non existing element and returns it's position
#[inline]
unsafe fn get_mut_idx(&mut self, idx: usize) -> (&mut K, &mut V) {
let r = self.v.get_unchecked_mut(idx);
let r = unsafe { self.v.get_unchecked_mut(idx) };
(&mut r.0, &mut r.1)
}
#[cfg(feature = "arraybackend")]
Expand Down
4 changes: 2 additions & 2 deletions src/vecmap/raw_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl<'a, K, V, const N: usize, S> RawEntryBuilderMut<'a, K, V, N, S> {
where
for<'b> F: FnMut(&'b K) -> bool,
{
for (idx, (ref key, _v)) in self.map.v.iter().enumerate() {
for (idx, (key, _v)) in self.map.v.iter().enumerate() {
if is_match(key) {
return RawEntryMut::Occupied(RawOccupiedEntryMut { idx, map: self.map });
}
Expand Down Expand Up @@ -332,7 +332,7 @@ impl<'a, K, V, const N: usize, S> RawOccupiedEntryMut<'a, K, V, N, S> {
#[inline]
pub fn get_key_value(&mut self) -> (&K, &V) {
unsafe {
let (ref key, ref value) = &self.map.v.get_unchecked(self.idx);
let (key, value) = &self.map.v.get_unchecked(self.idx);
(key, value)
}
}
Expand Down
Loading