Skip to content

Commit

Permalink
Auto merge of #358 - braddunbar:set-raw-table, r=Amanieu
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
bors committed Sep 8, 2022
2 parents 2784682 + 6041b5a commit f89bcf8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/map.rs
Expand Up @@ -1996,7 +1996,7 @@ impl<K, V, S, A: Allocator + Clone> HashMap<K, V, S, A> {
///
/// # Note
///
/// Calling the function safe, but using raw hash table API's may require
/// Calling this function is safe, but using the raw hash table API may require
/// unsafe functions or blocks.
///
/// `RawTable` API gives the lowest level of control under the map that can be useful
Expand Down
22 changes: 22 additions & 0 deletions src/set.rs
@@ -1,3 +1,5 @@
#[cfg(feature = "raw")]
use crate::raw::RawTable;
use crate::{Equivalent, TryReserveError};
use alloc::borrow::ToOwned;
use core::fmt;
Expand Down Expand Up @@ -1135,6 +1137,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 this function is safe, but using the raw hash table API 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 f89bcf8

Please sign in to comment.