Skip to content

Commit

Permalink
Add HashSet#raw_table
Browse files Browse the repository at this point in the history
Just like rust-lang#335 did for `HashMap`, I'd like to add access to the
underlying `RawTable` for `HashSet`. I intend to use it in conjunction
with rust-lang#354 to pull random elements from a `HashSet`.
  • Loading branch information
braddunbar committed Sep 3, 2022
1 parent 22c7dbc commit 76dddaa
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/set.rs
@@ -1,4 +1,5 @@
use crate::{Equivalent, TryReserveError};
use crate::raw::RawTable;
use alloc::borrow::ToOwned;
use core::fmt;
use core::hash::{BuildHasher, Hash};
Expand Down Expand Up @@ -1135,6 +1136,26 @@ where
None => None,
}
}

/// Returns a mutable reference to the [`RawTable`] used underneath [`HashSet`].
/// This function is only available if the `raw` feature of the crate is enabled.
///
/// # Note
///
/// Calling the function safe, but using raw hash table API's may require
/// unsafe functions or blocks.
///
/// `RawTable` API gives the lowest level of control under the set that can be useful
/// for extending the HashSet's API, but may lead to *[undefined behavior]*.
///
/// [`HashSet`]: struct.HashSet.html
/// [`RawTable`]: raw/struct.RawTable.html
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
#[cfg(feature = "raw")]
#[cfg_attr(feature = "inline-more", inline)]
pub fn raw_table(&mut self) -> &mut RawTable<(T, ()), A> {
self.map.raw_table()
}
}

impl<T, S, A> PartialEq for HashSet<T, S, A>
Expand Down

0 comments on commit 76dddaa

Please sign in to comment.