@@ -45,8 +45,14 @@ impl<'a, T, const N: usize> SlotBkVec<'a, T, N> {
45
45
// N <= 4: last tow bits mask: 0b11 , buckets: (0,1,2,3)
46
46
// N <= 8: last three bits mask: 0b111 , buckets: (0,1,2,3,4,5,6,7)
47
47
// 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
+ }
50
56
}
51
57
52
58
/// Returns the bucket mask from bucket bit numbers.
@@ -86,7 +92,7 @@ impl<'a, T, const N: usize> SlotBkVec<'a, T, N> {
86
92
( index << bucket_bits) | ( buket & bucket_mask)
87
93
}
88
94
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.
90
96
#[ auto_enums:: auto_enum( DoubleEndedIterator ) ]
91
97
fn iter_mut_impl < ' s > ( & ' s mut self ) -> impl DoubleEndedIterator < Item = & ' s mut T > {
92
98
// This implementation does not affect performance, because N is determined
@@ -194,17 +200,17 @@ impl<'a, T, const N: usize> SlotBkVec<'a, T, N> {
194
200
self . buckets [ buket] . remove ( index)
195
201
}
196
202
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.
198
204
pub fn len ( & self ) -> usize {
199
205
self . iter ( ) . count ( )
200
206
}
201
207
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.
203
209
pub fn is_empty ( & self ) -> bool {
204
210
self . len ( ) == 0
205
211
}
206
212
207
- /// Iterates every element in the bucket slice of this buckets , as immutable.
213
+ /// Iterates every element of the bucket slice, as immutable.
208
214
///
209
215
/// # Panics
210
216
/// This function panics if the bucket number is overflow (>N).
@@ -218,7 +224,7 @@ impl<'a, T, const N: usize> SlotBkVec<'a, T, N> {
218
224
. flatten ( )
219
225
}
220
226
221
- /// Iterates every element in the bucket slice of this buckets , as mutable.
227
+ /// Iterates every element of the bucket slice, as mutable.
222
228
///
223
229
/// # Panics
224
230
/// This function panics if the bucket number is overflow (>N).
@@ -235,12 +241,12 @@ impl<'a, T, const N: usize> SlotBkVec<'a, T, N> {
235
241
. flatten ( )
236
242
}
237
243
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.
239
245
pub fn iter < ' s > ( & ' s self ) -> impl DoubleEndedIterator < Item = & ' s T > {
240
246
self . buckets . iter ( ) . flat_map ( |slice| slice. iter ( ) )
241
247
}
242
248
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.
244
250
pub fn iter_mut < ' s > ( & ' s mut self ) -> impl DoubleEndedIterator < Item = & ' s mut T > {
245
251
// NB: In the future we may use a more concise Rust API like this.
246
252
// Although it is possible to use the Captures trick here,
0 commit comments