@@ -45,8 +45,14 @@ impl<'a, T, const N: usize> SlotBkVec<'a, T, N> {
4545 // N <= 4: last tow bits mask: 0b11 , buckets: (0,1,2,3)
4646 // N <= 8: last three bits mask: 0b111 , buckets: (0,1,2,3,4,5,6,7)
4747 // N <= 16: last four bits mask: 0b1111 , buckets: (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
48- let buckets = N ;
49- ( buckets as f64 ) . log2 ( ) . ceil ( ) as usize
48+ // this calculation method only works in std: `(N as f64).log2().ceil() as usize`
49+ match N {
50+ 1 ..=2 => 1 ,
51+ 3 ..=4 => 2 ,
52+ 5 ..=8 => 3 ,
53+ 9 ..=16 => 4 ,
54+ _ => unreachable ! ( ) ,
55+ }
5056 }
5157
5258 /// Returns the bucket mask from bucket bit numbers.
@@ -86,7 +92,7 @@ impl<'a, T, const N: usize> SlotBkVec<'a, T, N> {
8692 ( index << bucket_bits) | ( buket & bucket_mask)
8793 }
8894
89- /// Iterates every element in all of bucket slices in this buckets, as mutable.
95+ /// Iterates every element of all slices of the buckets, as mutable.
9096 #[ auto_enums:: auto_enum( DoubleEndedIterator ) ]
9197 fn iter_mut_impl < ' s > ( & ' s mut self ) -> impl DoubleEndedIterator < Item = & ' s mut T > {
9298 // This implementation does not affect performance, because N is determined
@@ -194,17 +200,17 @@ impl<'a, T, const N: usize> SlotBkVec<'a, T, N> {
194200 self . buckets [ buket] . remove ( index)
195201 }
196202
197- /// Returns the number of valid elements in all of bucket slices in this buckets.
203+ /// Returns the number of valid elements of all slices of the buckets.
198204 pub fn len ( & self ) -> usize {
199205 self . iter ( ) . count ( )
200206 }
201207
202- /// Returns true if all of bucket slices in this buckets contains no valid elements.
208+ /// Returns true if all slices of the buckets contains no valid elements.
203209 pub fn is_empty ( & self ) -> bool {
204210 self . len ( ) == 0
205211 }
206212
207- /// Iterates every element in the bucket slice of this buckets , as immutable.
213+ /// Iterates every element of the bucket slice, as immutable.
208214 ///
209215 /// # Panics
210216 /// This function panics if the bucket number is overflow (>N).
@@ -218,7 +224,7 @@ impl<'a, T, const N: usize> SlotBkVec<'a, T, N> {
218224 . flatten ( )
219225 }
220226
221- /// Iterates every element in the bucket slice of this buckets , as mutable.
227+ /// Iterates every element of the bucket slice, as mutable.
222228 ///
223229 /// # Panics
224230 /// This function panics if the bucket number is overflow (>N).
@@ -235,12 +241,12 @@ impl<'a, T, const N: usize> SlotBkVec<'a, T, N> {
235241 . flatten ( )
236242 }
237243
238- /// Iterates every element in all of bucket slices in this buckets, as immutable.
244+ /// Iterates every element of all slices of the buckets, as immutable.
239245 pub fn iter < ' s > ( & ' s self ) -> impl DoubleEndedIterator < Item = & ' s T > {
240246 self . buckets . iter ( ) . flat_map ( |slice| slice. iter ( ) )
241247 }
242248
243- /// Iterates every element in all of bucket slices in this buckets, as mutable.
249+ /// Iterates every element of all slices of the buckets, as mutable.
244250 pub fn iter_mut < ' s > ( & ' s mut self ) -> impl DoubleEndedIterator < Item = & ' s mut T > {
245251 // NB: In the future we may use a more concise Rust API like this.
246252 // Although it is possible to use the Captures trick here,
0 commit comments