Skip to content

Commit be202e7

Browse files
committed
Doc set_ctrl_h2
1 parent 5e4a982 commit be202e7

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/raw/mod.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,8 +1301,34 @@ impl<A: Allocator + Clone> RawTableInner<A> {
13011301

13021302
/// Sets a control byte to the hash, and possibly also the replicated control byte at
13031303
/// the end of the array.
1304+
///
1305+
/// This function does not make any changes to the `data` parts of the table,
1306+
/// or any changes to the the `items` or `growth_left` field of the table.
1307+
///
1308+
/// # Safety
1309+
///
1310+
/// The safety rules are directly derived from the safety rules for [`RawTableInner::set_ctrl`]
1311+
/// method. Thus, in order to uphold the safety contracts for the method, you must observe the
1312+
/// following rules when calling this function:
1313+
///
1314+
/// * The [`RawTableInner`] has already been allocated;
1315+
///
1316+
/// * The `index` must not be greater than the `RawTableInner.bucket_mask`, i.e.
1317+
/// `index <= RawTableInner.bucket_mask` or, in other words, `(index + 1)` must
1318+
/// be no greater than the number returned by the function [`RawTableInner::buckets`].
1319+
///
1320+
/// Calling this function on a table that has not been allocated results in [`undefined behavior`].
1321+
///
1322+
/// See also [`Bucket::as_ptr`] method, for more information about of properly removing
1323+
/// or saving `data element` from / into the [`RawTable`] / [`RawTableInner`].
1324+
///
1325+
/// [`RawTableInner::set_ctrl`]: RawTableInner::set_ctrl
1326+
/// [`RawTableInner::buckets`]: RawTableInner::buckets
1327+
/// [`Bucket::as_ptr`]: Bucket::as_ptr
1328+
/// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
13041329
#[inline]
13051330
unsafe fn set_ctrl_h2(&self, index: usize, hash: u64) {
1331+
// SAFETY: The caller must uphold the safety rules for the [`RawTableInner::set_ctrl_h2`]
13061332
self.set_ctrl(index, h2(hash));
13071333
}
13081334

0 commit comments

Comments
 (0)