Skip to content

make with_hasher_in const (consistent with with_hasher) #355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 8, 2022
Merged
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: 4 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ jobs:
thumbv6m-none-eabi,
x86_64-pc-windows-gnu,
]
channel: [1.58.1, nightly]
channel: [1.61.0, nightly]
include:
- os: macos-latest
target: x86_64-apple-darwin
@@ -60,13 +60,13 @@ jobs:
channel: nightly
- os: macos-latest
target: x86_64-apple-darwin
channel: 1.58.1
channel: 1.61.0
- os: windows-latest
target: x86_64-pc-windows-msvc
channel: 1.58.1
channel: 1.61.0
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
channel: 1.56.1
channel: 1.61.0
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
channel: beta
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ hashbrown
[![Build Status](https://github.com/rust-lang/hashbrown/actions/workflows/rust.yml/badge.svg)](https://github.com/rust-lang/hashbrown/actions)
[![Crates.io](https://img.shields.io/crates/v/hashbrown.svg)](https://crates.io/crates/hashbrown)
[![Documentation](https://docs.rs/hashbrown/badge.svg)](https://docs.rs/hashbrown)
[![Rust](https://img.shields.io/badge/rust-1.56.1%2B-blue.svg?maxAge=3600)](https://github.com/rust-lang/hashbrown)
[![Rust](https://img.shields.io/badge/rust-1.61.0%2B-blue.svg?maxAge=3600)](https://github.com/rust-lang/hashbrown)

This crate is a Rust port of Google's high-performance [SwissTable] hash
map, adapted to make it a drop-in replacement for Rust's standard `HashMap`
5 changes: 3 additions & 2 deletions src/map.rs
Original file line number Diff line number Diff line change
@@ -429,7 +429,8 @@ impl<K, V, S, A: Allocator + Clone> HashMap<K, V, S, A> {
/// Creates an empty `HashMap` which will use the given hash builder to hash
/// keys. It will be allocated with the given allocator.
///
/// The created map has the default initial capacity.
/// The hash map is initially created with a capacity of 0, so it will not
/// allocate until it is first inserted into.
///
/// Warning: `hash_builder` is normally randomly generated, and
/// is designed to allow HashMaps to be resistant to attacks that
@@ -447,7 +448,7 @@ impl<K, V, S, A: Allocator + Clone> HashMap<K, V, S, A> {
/// map.insert(1, 2);
/// ```
#[cfg_attr(feature = "inline-more", inline)]
pub fn with_hasher_in(hash_builder: S, alloc: A) -> Self {
pub const fn with_hasher_in(hash_builder: S, alloc: A) -> Self {
Self {
hash_builder,
table: RawTable::new_in(alloc),
2 changes: 1 addition & 1 deletion src/raw/mod.rs
Original file line number Diff line number Diff line change
@@ -426,7 +426,7 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
/// leave the data pointer dangling since that bucket is never written to
/// due to our load factor forcing us to always have at least 1 free bucket.
#[inline]
pub fn new_in(alloc: A) -> Self {
pub const fn new_in(alloc: A) -> Self {
Self {
table: RawTableInner::new_in(alloc),
marker: PhantomData,
8 changes: 5 additions & 3 deletions src/set.rs
Original file line number Diff line number Diff line change
@@ -387,7 +387,8 @@ impl<T, S> HashSet<T, S, Global> {
/// Creates a new empty hash set which will use the given hasher to hash
/// keys.
///
/// The hash set is also created with the default initial capacity.
/// The hash set is initially created with a capacity of 0, so it will not
/// allocate until it is first inserted into.
///
/// Warning: `hasher` is normally randomly generated, and
/// is designed to allow `HashSet`s to be resistant to attacks that
@@ -464,7 +465,8 @@ where
/// Creates a new empty hash set which will use the given hasher to hash
/// keys.
///
/// The hash set is also created with the default initial capacity.
/// The hash set is initially created with a capacity of 0, so it will not
/// allocate until it is first inserted into.
///
/// Warning: `hasher` is normally randomly generated, and
/// is designed to allow `HashSet`s to be resistant to attacks that
@@ -482,7 +484,7 @@ where
/// set.insert(2);
/// ```
#[cfg_attr(feature = "inline-more", inline)]
pub fn with_hasher_in(hasher: S, alloc: A) -> Self {
pub const fn with_hasher_in(hasher: S, alloc: A) -> Self {
Self {
map: HashMap::with_hasher_in(hasher, alloc),
}