@@ -1306,8 +1306,37 @@ impl<A: Allocator + Clone> RawTableInner<A> {
1306
1306
self . set_ctrl ( index, h2 ( hash) ) ;
1307
1307
}
1308
1308
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
1309
1337
#[ inline]
1310
1338
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`]
1311
1340
let prev_ctrl = * self . ctrl ( index) ;
1312
1341
self . set_ctrl_h2 ( index, hash) ;
1313
1342
prev_ctrl
0 commit comments