Skip to content
Draft
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
10 changes: 5 additions & 5 deletions benches/general_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
//! * Hasher: std default (SipHash) and crate default (foldhash).
//! * Int key distribution: low bit heavy, top bit heavy, and random.
//! * Task: basic functionality: insert, insert_erase, lookup, lookup_fail, iter
use criterion::Criterion;
use hashbrown::DefaultHashBuilder;
use hashbrown::{HashMap, HashSet};
use std::{
collections::hash_map::RandomState,
use core::{
hint::black_box,
sync::atomic::{self, AtomicUsize},
};
use criterion::Criterion;
use hashbrown::DefaultHashBuilder;
use hashbrown::{HashMap, HashSet};
use std::hash::RandomState;

const SIZE: usize = 1000;
const OP_COUNT: usize = 500;
Expand Down
2 changes: 1 addition & 1 deletion benches/insert_unique_unchecked.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Compare `insert` and `insert_unique_unchecked` operations performance.
use core::hint::black_box;
use criterion::Criterion;
use hashbrown::HashMap;
use std::hint::black_box;

pub(crate) fn register_benches(c: &mut Criterion) {
let keys: Vec<String> = (0..1000).map(|i| format!("xxxx{i}yyyy")).collect();
Expand Down
2 changes: 1 addition & 1 deletion benches/with_capacity.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::hint::black_box;
use criterion::Criterion;
use hashbrown::HashMap;
use std::hint::black_box;

type Map<K, V> = HashMap<K, V>;

Expand Down
24 changes: 12 additions & 12 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ pub use crate::raw_entry::*;
/// The easiest way to use `HashMap` with a custom key type is to derive [`Eq`] and [`Hash`].
/// We must also derive [`PartialEq`].
///
/// [`RefCell`]: std::cell::RefCell
/// [`Cell`]: std::cell::Cell
/// [`Cell`]: core::cell::Cell
/// [`RefCell`]: core::cell::RefCell
/// [`default`]: Default::default
/// [`with_hasher`]: HashMap::with_hasher
/// [`with_capacity_and_hasher`]: HashMap::with_capacity_and_hasher
Expand Down Expand Up @@ -2669,13 +2669,13 @@ pub struct ValuesMut<'a, K, V> {
///
/// // Existing key (or_insert)
/// let v = map.entry("b").or_insert(2);
/// assert_eq!(std::mem::replace(v, 2), 20);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly in favour of this change, but I would rather not update the doctests specifically since in general we prefer making those as simple as possible, and using only std allows better import grouping.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import grouping shouldn’t be an issue here. In the doctests, we only use the following std imports, and they are never used in combination with core:

/// use std::hash::RandomState;
/// use std::rc::Rc;

/// assert_eq!(core::mem::replace(v, 2), 20);
/// // Nonexistent key (or_insert)
/// map.entry("e").or_insert(5);
///
/// // Existing key (or_insert_with)
/// let v = map.entry("c").or_insert_with(|| 3);
/// assert_eq!(std::mem::replace(v, 3), 30);
/// assert_eq!(core::mem::replace(v, 3), 30);
/// // Nonexistent key (or_insert_with)
/// map.entry("f").or_insert_with(|| 6);
///
Expand Down Expand Up @@ -2872,13 +2872,13 @@ impl<K: Debug, V, S, A: Allocator> Debug for VacantEntry<'_, K, V, S, A> {
///
/// // Existing key (or_insert)
/// let v = map.entry_ref("b").or_insert(2);
/// assert_eq!(std::mem::replace(v, 2), 20);
/// assert_eq!(core::mem::replace(v, 2), 20);
/// // Nonexistent key (or_insert)
/// map.entry_ref("e").or_insert(5);
///
/// // Existing key (or_insert_with)
/// let v = map.entry_ref("c").or_insert_with(|| 3);
/// assert_eq!(std::mem::replace(v, 3), 30);
/// assert_eq!(core::mem::replace(v, 3), 30);
/// // Nonexistent key (or_insert_with)
/// map.entry_ref("f").or_insert_with(|| 6);
///
Expand Down Expand Up @@ -3809,8 +3809,8 @@ impl<'a, K, V, S, A: Allocator> OccupiedEntry<'a, K, V, S, A> {
/// Entry::Vacant(_) => panic!(),
/// Entry::Occupied(mut entry) => {
/// let replaced = entry.replace_key(new_key);
/// assert!(std::ptr::eq(replaced, old_key));
/// assert!(std::ptr::eq(*entry.key(), new_key));
/// assert!(core::ptr::eq(replaced, old_key));
/// assert!(core::ptr::eq(*entry.key(), new_key));
/// },
/// }
///
Expand Down Expand Up @@ -3864,8 +3864,8 @@ impl<'a, K, V, S, A: Allocator> OccupiedEntry<'a, K, V, S, A> {
/// Entry::Vacant(_) => panic!(),
/// Entry::Occupied(mut entry) => {
/// let replaced = unsafe { entry.replace_key_unchecked(new_key) };
/// assert!(std::ptr::eq(replaced, old_key));
/// assert!(std::ptr::eq(*entry.key(), new_key));
/// assert!(core::ptr::eq(replaced, old_key));
/// assert!(core::ptr::eq(*entry.key(), new_key));
/// },
/// }
///
Expand Down Expand Up @@ -5084,11 +5084,11 @@ mod test_map {
use super::HashMap;
use crate::alloc::{AllocError, Allocator, Global};
use core::alloc::Layout;
use core::cell::RefCell;
use core::ptr::NonNull;
use core::sync::atomic::{AtomicI8, Ordering};
use rand::{Rng, SeedableRng, rngs::SmallRng};
use std::borrow::ToOwned;
use std::cell::RefCell;
use std::vec::Vec;
use stdalloc::string::String;
use stdalloc::sync::Arc;
Expand Down Expand Up @@ -6043,7 +6043,7 @@ mod test_map {

#[test]
fn test_extend_ref_kv_tuple() {
use std::ops::AddAssign;
use core::ops::AddAssign;
let mut a = HashMap::new();
a.insert(0, 0);

Expand Down
4 changes: 2 additions & 2 deletions src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ use crate::raw::RawExtractIf;
/// // use the values stored in the set
/// ```
///
/// [`Cell`]: std::cell::Cell
/// [`RefCell`]: std::cell::RefCell
/// [`Cell`]: core::cell::Cell
/// [`RefCell`]: core::cell::RefCell
pub struct HashSet<T, S = DefaultHashBuilder, A: Allocator = Global> {
pub(crate) map: HashMap<T, (), S, A>,
}
Expand Down
Loading
Loading