Skip to content

Commit f238820

Browse files
committed
Auto merge of #398 - JustForFun88:set_ctrl_h2, r=Amanieu
Doc `RawTableInner::set_ctrl_h2`
2 parents 574a1a9 + be202e7 commit f238820

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
@@ -1736,8 +1736,34 @@ impl<A: Allocator + Clone> RawTableInner<A> {
17361736

17371737
/// Sets a control byte to the hash, and possibly also the replicated control byte at
17381738
/// the end of the array.
1739+
///
1740+
/// This function does not make any changes to the `data` parts of the table,
1741+
/// or any changes to the the `items` or `growth_left` field of the table.
1742+
///
1743+
/// # Safety
1744+
///
1745+
/// The safety rules are directly derived from the safety rules for [`RawTableInner::set_ctrl`]
1746+
/// method. Thus, in order to uphold the safety contracts for the method, you must observe the
1747+
/// following rules when calling this function:
1748+
///
1749+
/// * The [`RawTableInner`] has already been allocated;
1750+
///
1751+
/// * The `index` must not be greater than the `RawTableInner.bucket_mask`, i.e.
1752+
/// `index <= RawTableInner.bucket_mask` or, in other words, `(index + 1)` must
1753+
/// be no greater than the number returned by the function [`RawTableInner::buckets`].
1754+
///
1755+
/// Calling this function on a table that has not been allocated results in [`undefined behavior`].
1756+
///
1757+
/// See also [`Bucket::as_ptr`] method, for more information about of properly removing
1758+
/// or saving `data element` from / into the [`RawTable`] / [`RawTableInner`].
1759+
///
1760+
/// [`RawTableInner::set_ctrl`]: RawTableInner::set_ctrl
1761+
/// [`RawTableInner::buckets`]: RawTableInner::buckets
1762+
/// [`Bucket::as_ptr`]: Bucket::as_ptr
1763+
/// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
17391764
#[inline]
17401765
unsafe fn set_ctrl_h2(&self, index: usize, hash: u64) {
1766+
// SAFETY: The caller must uphold the safety rules for the [`RawTableInner::set_ctrl_h2`]
17411767
self.set_ctrl(index, h2(hash));
17421768
}
17431769

0 commit comments

Comments
 (0)