Skip to content

Commit ed9a3d5

Browse files
committed
Add HashSet#raw_table
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`.
1 parent 22c7dbc commit ed9a3d5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/set.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#[cfg(feature = "raw")]
2+
use crate::raw::RawTable;
13
use crate::{Equivalent, TryReserveError};
24
use alloc::borrow::ToOwned;
35
use core::fmt;
@@ -1135,6 +1137,26 @@ where
11351137
None => None,
11361138
}
11371139
}
1140+
1141+
/// Returns a mutable reference to the [`RawTable`] used underneath [`HashSet`].
1142+
/// This function is only available if the `raw` feature of the crate is enabled.
1143+
///
1144+
/// # Note
1145+
///
1146+
/// Calling the function safe, but using raw hash table API's may require
1147+
/// unsafe functions or blocks.
1148+
///
1149+
/// `RawTable` API gives the lowest level of control under the set that can be useful
1150+
/// for extending the HashSet's API, but may lead to *[undefined behavior]*.
1151+
///
1152+
/// [`HashSet`]: struct.HashSet.html
1153+
/// [`RawTable`]: raw/struct.RawTable.html
1154+
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
1155+
#[cfg(feature = "raw")]
1156+
#[cfg_attr(feature = "inline-more", inline)]
1157+
pub fn raw_table(&mut self) -> &mut RawTable<(T, ()), A> {
1158+
self.map.raw_table()
1159+
}
11381160
}
11391161

11401162
impl<T, S, A> PartialEq for HashSet<T, S, A>

0 commit comments

Comments
 (0)