Skip to content

Commit e233127

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 e233127

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/set.rs

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

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

0 commit comments

Comments
 (0)