Skip to content

Commit 7a2e471

Browse files
committed
Doc replace_ctrl_h2
1 parent 5e4a982 commit 7a2e471

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/raw/mod.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,8 +1306,37 @@ impl<A: Allocator + Clone> RawTableInner<A> {
13061306
self.set_ctrl(index, h2(hash));
13071307
}
13081308

1309+
/// Replaces the hash in the control byte at the given index with the provided one,
1310+
/// and possibly also replicates the new control byte at the end of the array of control
1311+
/// bytes, returning the old control byte.
1312+
///
1313+
/// This function does not make any changes to the `data` parts of the table,
1314+
/// or any changes to the the `items` or `growth_left` field of the table.
1315+
///
1316+
/// # Safety
1317+
///
1318+
/// The safety rules are directly derived from the safety rules for [`RawTableInner::set_ctrl_h2`]
1319+
/// and [`RawTableInner::ctrl`] methods. Thus, in order to uphold the safety contracts for both
1320+
/// methods, you must observe the following rules when calling this function:
1321+
///
1322+
/// * The [`RawTableInner`] has already been allocated;
1323+
///
1324+
/// * The `index` must not be greater than the `RawTableInner.bucket_mask`, i.e.
1325+
/// `index <= RawTableInner.bucket_mask` or, in other words, `(index + 1)` must
1326+
/// be no greater than the number returned by the function [`RawTableInner::buckets`].
1327+
///
1328+
/// Calling this function on a table that has not been allocated results in [`undefined behavior`].
1329+
///
1330+
/// See also [`Bucket::as_ptr`] method, for more information about of properly removing
1331+
/// or saving `data element` from / into the [`RawTable`] / [`RawTableInner`].
1332+
///
1333+
/// [`RawTableInner::set_ctrl_h2`]: RawTableInner::set_ctrl_h2
1334+
/// [`RawTableInner::buckets`]: RawTableInner::buckets
1335+
/// [`Bucket::as_ptr`]: Bucket::as_ptr
1336+
/// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
13091337
#[inline]
13101338
unsafe fn replace_ctrl_h2(&self, index: usize, hash: u64) -> u8 {
1339+
// SAFETY: The caller must uphold the safety rules for the [`RawTableInner::replace_ctrl_h2`]
13111340
let prev_ctrl = *self.ctrl(index);
13121341
self.set_ctrl_h2(index, hash);
13131342
prev_ctrl

0 commit comments

Comments
 (0)