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
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hashlink"
version = "0.9.1"
version = "0.10.0"
authors = ["kyren <kerriganw@gmail.com>"]
edition = "2018"
description = "HashMap-like containers that hold their key-value pairs in a user controllable order"
Expand All @@ -9,6 +9,7 @@ documentation = "https://docs.rs/hashlink"
readme = "README.md"
keywords = ["data-structures", "no_std"]
license = "MIT OR Apache-2.0"
rust-version = "1.65"

[badges]
circle-ci = { repository = "kyren/hashlink", branch = "master" }
Expand All @@ -17,9 +18,10 @@ circle-ci = { repository = "kyren/hashlink", branch = "master" }
serde_impl = ["serde"]

[dependencies]
hashbrown = { version = "0.14.3", default-features = false, features = ["ahash", "inline-more"] }
foldhash = { version = "0.1.3", default-features = false }
hashbrown = { version = "0.15", default-features = false, features = ["default-hasher", "inline-more"] }
serde = { version = "1.0", default-features = false, optional = true }

[dev-dependencies]
serde_test = "1.0"
rustc-hash = "1.1"
rustc-hash = "2"
95 changes: 95 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,101 @@ pub mod lru_cache;
#[cfg(feature = "serde_impl")]
pub mod serde;

use core::hash::{BuildHasher, Hasher};

pub use linked_hash_map::LinkedHashMap;
pub use linked_hash_set::LinkedHashSet;
pub use lru_cache::LruCache;

/// Default hash builder, matches hashbrown's default hasher.
///
/// See [`DefaultHasher`] for more details.
#[derive(Clone, Copy, Default, Debug)]
pub struct DefaultHashBuilder(hashbrown::DefaultHashBuilder);

impl BuildHasher for DefaultHashBuilder {
type Hasher = DefaultHasher;

#[inline]
fn build_hasher(&self) -> Self::Hasher {
DefaultHasher(self.0.build_hasher())
}
}

/// Default hasher, as selected by hashbrown.
///
/// Currently this is [`foldhash::fast::FoldHasher`].
#[derive(Clone)]
pub struct DefaultHasher(foldhash::fast::FoldHasher);

impl Hasher for DefaultHasher {
#[inline]
fn write(&mut self, bytes: &[u8]) {
self.0.write(bytes)
}

#[inline]
fn write_u8(&mut self, i: u8) {
self.0.write_u8(i)
}

#[inline]
fn write_u16(&mut self, i: u16) {
self.0.write_u16(i)
}

#[inline]
fn write_u32(&mut self, i: u32) {
self.0.write_u32(i)
}

#[inline]
fn write_u64(&mut self, i: u64) {
self.0.write_u64(i)
}

#[inline]
fn write_u128(&mut self, i: u128) {
self.0.write_u128(i)
}

#[inline]
fn write_usize(&mut self, i: usize) {
self.0.write_usize(i)
}

#[inline]
fn finish(&self) -> u64 {
self.0.finish()
}

#[inline]
fn write_i8(&mut self, i: i8) {
self.0.write_i8(i)
}

#[inline]
fn write_i16(&mut self, i: i16) {
self.0.write_i16(i)
}

#[inline]
fn write_i32(&mut self, i: i32) {
self.0.write_i32(i)
}

#[inline]
fn write_i64(&mut self, i: i64) {
self.0.write_i64(i)
}

#[inline]
fn write_i128(&mut self, i: i128) {
self.0.write_i128(i)
}

#[inline]
fn write_isize(&mut self, i: isize) {
self.0.write_isize(i)
}
}
56 changes: 29 additions & 27 deletions src/linked_hash_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ use core::{
};

use alloc::boxed::Box;
use hashbrown::hash_map::DefaultHashBuilder;
use hashbrown::hash_table::{self, HashTable};

use crate::DefaultHashBuilder;

pub enum TryReserveError {
CapacityOverflow,
AllocError { layout: Layout },
Expand Down Expand Up @@ -972,15 +973,15 @@ where
}
}

unsafe impl<'a, K, V, S> Send for RawEntryBuilder<'a, K, V, S>
unsafe impl<K, V, S> Send for RawEntryBuilder<'_, K, V, S>
where
K: Send,
V: Send,
S: Send,
{
}

unsafe impl<'a, K, V, S> Sync for RawEntryBuilder<'a, K, V, S>
unsafe impl<K, V, S> Sync for RawEntryBuilder<'_, K, V, S>
where
K: Sync,
V: Sync,
Expand Down Expand Up @@ -1043,15 +1044,15 @@ where
}
}

unsafe impl<'a, K, V, S> Send for RawEntryBuilderMut<'a, K, V, S>
unsafe impl<K, V, S> Send for RawEntryBuilderMut<'_, K, V, S>
where
K: Send,
V: Send,
S: Send,
{
}

unsafe impl<'a, K, V, S> Sync for RawEntryBuilderMut<'a, K, V, S>
unsafe impl<K, V, S> Sync for RawEntryBuilderMut<'_, K, V, S>
where
K: Sync,
V: Sync,
Expand Down Expand Up @@ -1346,31 +1347,31 @@ impl<K, V, S> fmt::Debug for RawEntryBuilder<'_, K, V, S> {
}
}

unsafe impl<'a, K, V, S> Send for RawOccupiedEntryMut<'a, K, V, S>
unsafe impl<K, V, S> Send for RawOccupiedEntryMut<'_, K, V, S>
where
K: Send,
V: Send,
S: Send,
{
}

unsafe impl<'a, K, V, S> Sync for RawOccupiedEntryMut<'a, K, V, S>
unsafe impl<K, V, S> Sync for RawOccupiedEntryMut<'_, K, V, S>
where
K: Sync,
V: Sync,
S: Sync,
{
}

unsafe impl<'a, K, V, S> Send for RawVacantEntryMut<'a, K, V, S>
unsafe impl<K, V, S> Send for RawVacantEntryMut<'_, K, V, S>
where
K: Send,
V: Send,
S: Send,
{
}

unsafe impl<'a, K, V, S> Sync for RawVacantEntryMut<'a, K, V, S>
unsafe impl<K, V, S> Sync for RawVacantEntryMut<'_, K, V, S>
where
K: Sync,
V: Sync,
Expand Down Expand Up @@ -1444,14 +1445,14 @@ impl<K, V> Drain<'_, K, V> {
}
}

unsafe impl<'a, K, V> Send for Iter<'a, K, V>
unsafe impl<K, V> Send for Iter<'_, K, V>
where
K: Send,
V: Send,
{
}

unsafe impl<'a, K, V> Send for IterMut<'a, K, V>
unsafe impl<K, V> Send for IterMut<'_, K, V>
where
K: Send,
V: Send,
Expand All @@ -1465,21 +1466,21 @@ where
{
}

unsafe impl<'a, K, V> Send for Drain<'a, K, V>
unsafe impl<K, V> Send for Drain<'_, K, V>
where
K: Send,
V: Send,
{
}

unsafe impl<'a, K, V> Sync for Iter<'a, K, V>
unsafe impl<K, V> Sync for Iter<'_, K, V>
where
K: Sync,
V: Sync,
{
}

unsafe impl<'a, K, V> Sync for IterMut<'a, K, V>
unsafe impl<K, V> Sync for IterMut<'_, K, V>
where
K: Sync,
V: Sync,
Expand All @@ -1493,14 +1494,14 @@ where
{
}

unsafe impl<'a, K, V> Sync for Drain<'a, K, V>
unsafe impl<K, V> Sync for Drain<'_, K, V>
where
K: Sync,
V: Sync,
{
}

impl<'a, K, V> Clone for Iter<'a, K, V> {
impl<K, V> Clone for Iter<'_, K, V> {
#[inline]
fn clone(&self) -> Self {
Iter { ..*self }
Expand Down Expand Up @@ -1617,7 +1618,7 @@ impl<K, V> Iterator for IntoIter<K, V> {
}
}

impl<'a, K, V> Iterator for Drain<'a, K, V> {
impl<K, V> Iterator for Drain<'_, K, V> {
type Item = (K, V);

#[inline]
Expand Down Expand Up @@ -1690,7 +1691,7 @@ impl<K, V> DoubleEndedIterator for IntoIter<K, V> {
}
}

impl<'a, K, V> DoubleEndedIterator for Drain<'a, K, V> {
impl<K, V> DoubleEndedIterator for Drain<'_, K, V> {
#[inline]
fn next_back(&mut self) -> Option<(K, V)> {
if self.remaining == 0 {
Expand All @@ -1707,9 +1708,9 @@ impl<'a, K, V> DoubleEndedIterator for Drain<'a, K, V> {
}
}

impl<'a, K, V> ExactSizeIterator for Iter<'a, K, V> {}
impl<K, V> ExactSizeIterator for Iter<'_, K, V> {}

impl<'a, K, V> ExactSizeIterator for IterMut<'a, K, V> {}
impl<K, V> ExactSizeIterator for IterMut<'_, K, V> {}

impl<K, V> ExactSizeIterator for IntoIter<K, V> {}

Expand All @@ -1727,7 +1728,7 @@ impl<K, V> Drop for IntoIter<K, V> {
}
}

impl<'a, K, V> Drop for Drain<'a, K, V> {
impl<K, V> Drop for Drain<'_, K, V> {
#[inline]
fn drop(&mut self) {
for _ in 0..self.remaining {
Expand Down Expand Up @@ -1762,7 +1763,7 @@ pub struct CursorMut<'a, K, V, S> {
table: &'a mut hashbrown::HashTable<NonNull<Node<K, V>>>,
}

impl<'a, K, V, S> CursorMut<'a, K, V, S> {
impl<K, V, S> CursorMut<'_, K, V, S> {
/// Returns an `Option` of the current element in the list, provided it is not the
/// _guard_ node, and `None` overwise.
#[inline]
Expand Down Expand Up @@ -1944,7 +1945,7 @@ impl<'a, K, V> DoubleEndedIterator for Keys<'a, K, V> {
}
}

impl<'a, K, V> ExactSizeIterator for Keys<'a, K, V> {
impl<K, V> ExactSizeIterator for Keys<'_, K, V> {
#[inline]
fn len(&self) -> usize {
self.inner.len()
Expand Down Expand Up @@ -1992,7 +1993,7 @@ impl<'a, K, V> DoubleEndedIterator for Values<'a, K, V> {
}
}

impl<'a, K, V> ExactSizeIterator for Values<'a, K, V> {
impl<K, V> ExactSizeIterator for Values<'_, K, V> {
#[inline]
fn len(&self) -> usize {
self.inner.len()
Expand Down Expand Up @@ -2035,7 +2036,7 @@ impl<'a, K, V> DoubleEndedIterator for ValuesMut<'a, K, V> {
}
}

impl<'a, K, V> ExactSizeIterator for ValuesMut<'a, K, V> {
impl<K, V> ExactSizeIterator for ValuesMut<'_, K, V> {
#[inline]
fn len(&self) -> usize {
self.inner.len()
Expand Down Expand Up @@ -2163,6 +2164,7 @@ impl<K, V> Node<K, V> {
}

trait OptNonNullExt<T> {
#[allow(clippy::wrong_self_convention)]
fn as_ptr(self) -> *mut T;
}

Expand Down Expand Up @@ -2321,7 +2323,7 @@ struct DropFilteredValues<'a, K, V> {
cur_free: Option<NonNull<Node<K, V>>>,
}

impl<'a, K, V> DropFilteredValues<'a, K, V> {
impl<K, V> DropFilteredValues<'_, K, V> {
#[inline]
fn drop_later(&mut self, node: NonNull<Node<K, V>>) {
unsafe {
Expand All @@ -2331,7 +2333,7 @@ impl<'a, K, V> DropFilteredValues<'a, K, V> {
}
}

impl<'a, K, V> Drop for DropFilteredValues<'a, K, V> {
impl<K, V> Drop for DropFilteredValues<'_, K, V> {
fn drop(&mut self) {
unsafe {
let end_free = self.cur_free;
Expand Down
Loading