Skip to content

Commit 574a1a9

Browse files
committed
Auto merge of #397 - JustForFun88:replace_ctrl_h2, r=Amanieu
Doc `replace_ctrl_h2`
2 parents e01dcd3 + 7a2e471 commit 574a1a9

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
@@ -1741,8 +1741,37 @@ impl<A: Allocator + Clone> RawTableInner<A> {
17411741
self.set_ctrl(index, h2(hash));
17421742
}
17431743

1744+
/// Replaces the hash in the control byte at the given index with the provided one,
1745+
/// and possibly also replicates the new control byte at the end of the array of control
1746+
/// bytes, returning the old control byte.
1747+
///
1748+
/// This function does not make any changes to the `data` parts of the table,
1749+
/// or any changes to the the `items` or `growth_left` field of the table.
1750+
///
1751+
/// # Safety
1752+
///
1753+
/// The safety rules are directly derived from the safety rules for [`RawTableInner::set_ctrl_h2`]
1754+
/// and [`RawTableInner::ctrl`] methods. Thus, in order to uphold the safety contracts for both
1755+
/// methods, you must observe the following rules when calling this function:
1756+
///
1757+
/// * The [`RawTableInner`] has already been allocated;
1758+
///
1759+
/// * The `index` must not be greater than the `RawTableInner.bucket_mask`, i.e.
1760+
/// `index <= RawTableInner.bucket_mask` or, in other words, `(index + 1)` must
1761+
/// be no greater than the number returned by the function [`RawTableInner::buckets`].
1762+
///
1763+
/// Calling this function on a table that has not been allocated results in [`undefined behavior`].
1764+
///
1765+
/// See also [`Bucket::as_ptr`] method, for more information about of properly removing
1766+
/// or saving `data element` from / into the [`RawTable`] / [`RawTableInner`].
1767+
///
1768+
/// [`RawTableInner::set_ctrl_h2`]: RawTableInner::set_ctrl_h2
1769+
/// [`RawTableInner::buckets`]: RawTableInner::buckets
1770+
/// [`Bucket::as_ptr`]: Bucket::as_ptr
1771+
/// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
17441772
#[inline]
17451773
unsafe fn replace_ctrl_h2(&self, index: usize, hash: u64) -> u8 {
1774+
// SAFETY: The caller must uphold the safety rules for the [`RawTableInner::replace_ctrl_h2`]
17461775
let prev_ctrl = *self.ctrl(index);
17471776
self.set_ctrl_h2(index, hash);
17481777
prev_ctrl

0 commit comments

Comments
 (0)