From 76dddaa4773d4aee219faaaa17d32bd9396614c5 Mon Sep 17 00:00:00 2001 From: Brad Dunbar Date: Sat, 3 Sep 2022 09:23:54 -0400 Subject: [PATCH] Add HashSet#raw_table Just like #335 did for `HashMap`, I'd like to add access to the underlying `RawTable` for `HashSet`. I intend to use it in conjunction with #354 to pull random elements from a `HashSet`. --- src/set.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/set.rs b/src/set.rs index c3e14affe1..96345aa484 100644 --- a/src/set.rs +++ b/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}; @@ -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 PartialEq for HashSet