File tree 3 files changed +9
-32
lines changed
3 files changed +9
-32
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ mod allocator;
28
28
mod iter;
29
29
mod node;
30
30
use crate :: {
31
- storable:: { max_size , Bound as StorableBound } ,
31
+ storable:: Bound as StorableBound ,
32
32
types:: { Address , NULL } ,
33
33
Memory , Storable ,
34
34
} ;
@@ -197,8 +197,8 @@ where
197
197
/// This is only exposed for testing and benchmarking.
198
198
#[ cfg( any( feature = "profiler" , test) ) ]
199
199
pub fn new_v1 ( memory : M ) -> Self {
200
- let max_key_size = max_size :: < K > ( ) ;
201
- let max_value_size = max_size :: < V > ( ) ;
200
+ let max_key_size = K :: BOUND . max_size ( ) ;
201
+ let max_value_size = V :: BOUND . max_size ( ) ;
202
202
203
203
let btree = Self {
204
204
root_addr : NULL ,
@@ -235,12 +235,12 @@ where
235
235
max_value_size : expected_value_size,
236
236
} ) => {
237
237
assert ! (
238
- max_size :: < K > ( ) <= expected_key_size,
238
+ K :: BOUND . max_size ( ) <= expected_key_size,
239
239
"max_key_size must be <= {expected_key_size}"
240
240
) ;
241
241
242
242
assert ! (
243
- max_size :: < V > ( ) <= expected_value_size,
243
+ V :: BOUND . max_size ( ) <= expected_value_size,
244
244
"max_value_size must be <= {expected_value_size}"
245
245
) ;
246
246
}
Original file line number Diff line number Diff line change 73
73
74
74
use super :: * ;
75
75
use crate :: btreemap:: Allocator ;
76
- use crate :: {
77
- btreemap:: node:: io:: NodeWriter ,
78
- storable:: { is_fixed_size, max_size} ,
79
- types:: NULL ,
80
- } ;
76
+ use crate :: { btreemap:: node:: io:: NodeWriter , types:: NULL } ;
81
77
82
78
// Initial page
83
79
pub ( super ) const OVERFLOW_ADDRESS_OFFSET : Bytes = Bytes :: new ( 7 ) ;
@@ -159,9 +155,9 @@ impl<K: Storable + Ord + Clone> Node<K> {
159
155
let mut buf = vec ! [ ] ;
160
156
for _ in 0 ..num_entries {
161
157
// Load the key's size.
162
- let key_size = if is_fixed_size :: < K > ( ) {
158
+ let key_size = if K :: BOUND . is_fixed_size ( ) {
163
159
// Key is fixed in size. The size of the key is always its max size.
164
- max_size :: < K > ( )
160
+ K :: BOUND . max_size ( )
165
161
} else {
166
162
// Key is not fixed in size. Read the size from memory.
167
163
let value = read_u32 ( & reader, offset) ;
@@ -251,7 +247,7 @@ impl<K: Storable + Ord + Clone> Node<K> {
251
247
let key_bytes = key. to_bytes_checked ( ) ;
252
248
253
249
// Write the size of the key if it isn't fixed in size.
254
- if !is_fixed_size :: < K > ( ) {
250
+ if !K :: BOUND . is_fixed_size ( ) {
255
251
writer. write_u32 ( offset, key_bytes. len ( ) as u32 ) ;
256
252
offset += U32_SIZE ;
257
253
}
Original file line number Diff line number Diff line change @@ -531,25 +531,6 @@ pub(crate) const fn bounds<A: Storable>() -> Bounds {
531
531
}
532
532
}
533
533
534
- /// Returns the max size of the given type if bounded, panics if unbounded.
535
- pub const fn max_size < A : Storable > ( ) -> u32 {
536
- if let Bound :: Bounded { max_size, .. } = A :: BOUND {
537
- max_size
538
- } else {
539
- panic ! ( "Cannot get max size of unbounded type." ) ;
540
- }
541
- }
542
-
543
- /// Returns true if the type is fixed in size, false otherwise.
544
- pub const fn is_fixed_size < A : Storable > ( ) -> bool {
545
- if let Bound :: Bounded { is_fixed_size, .. } = A :: BOUND {
546
- is_fixed_size
547
- } else {
548
- // Unbounded types do not have a fixed size.
549
- false
550
- }
551
- }
552
-
553
534
fn decode_size ( src : & [ u8 ] , bounds : & Bounds ) -> usize {
554
535
if bounds. is_fixed_size {
555
536
bounds. max_size as usize
You can’t perform that action at this time.
0 commit comments