Skip to content

Commit f89bcf8

Browse files
committed
Auto merge of #358 - braddunbar:set-raw-table, r=Amanieu
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`. Let me know if I've missed something here or you'd like things implemented differently. I'll be happy to change it up!
2 parents 2784682 + 6041b5a commit f89bcf8

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1996,7 +1996,7 @@ impl<K, V, S, A: Allocator + Clone> HashMap<K, V, S, A> {
19961996
///
19971997
/// # Note
19981998
///
1999-
/// Calling the function safe, but using raw hash table API's may require
1999+
/// Calling this function is safe, but using the raw hash table API may require
20002000
/// unsafe functions or blocks.
20012001
///
20022002
/// `RawTable` API gives the lowest level of control under the map that can be useful

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 this function is safe, but using the raw hash table API 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)