26
26
/// let store = MemoryBlockstore::default();
27
27
///
28
28
/// let mut amt = Amt::new(store);
29
- /// let kvs: Vec<usize > = (0..=5).collect();
29
+ /// let kvs: Vec<u64 > = (0..=5).collect();
30
30
/// kvs
31
31
/// .iter()
32
32
/// .map(|k| amt.set(u64::try_from(*k).unwrap(), k.to_string()))
@@ -101,7 +101,7 @@ where
101
101
///
102
102
/// # anyhow::Ok(())
103
103
/// ```
104
- pub fn keys ( & self ) -> impl Iterator < Item = usize > + ' _ {
104
+ pub fn keys ( & self ) -> impl Iterator < Item = u64 > + ' _ {
105
105
self . iter ( ) . map ( |res| {
106
106
res. map ( |( k, _) | k)
107
107
. expect ( "Failed to generate iterator from AMT keys" )
@@ -119,7 +119,7 @@ where
119
119
///
120
120
/// // Create an AMT with 5 keys.
121
121
/// let mut amt = Amt::new(store);
122
- /// let kvs: Vec<usize > = (0..=5).collect();
122
+ /// let kvs: Vec<u64 > = (0..=5).collect();
123
123
///
124
124
/// let _ = kvs
125
125
/// .iter()
@@ -152,14 +152,14 @@ where
152
152
///
153
153
/// # anyhow::Ok(())
154
154
/// ```
155
- pub fn iter_from ( & self , key : usize ) -> Result < Iter < ' _ , V , & BS , Ver > , crate :: Error > {
155
+ pub fn iter_from ( & self , key : u64 ) -> Result < Iter < ' _ , V , & BS , Ver > , crate :: Error > {
156
156
let mut iter = self . iter ( ) ;
157
157
while key > iter. key {
158
158
let stack = iter. stack . last_mut ( ) . expect ( "Stack is empty" ) ;
159
159
match stack. node {
160
160
Some ( Node :: Leaf { vals } ) => {
161
- while stack. idx < vals. len ( ) {
162
- match vals[ stack. idx ] {
161
+ while ( stack. idx as usize ) < vals. len ( ) {
162
+ match vals[ stack. idx as usize ] {
163
163
Some ( _) => {
164
164
stack. idx += 1 ;
165
165
iter. key += 1 ;
@@ -176,8 +176,8 @@ where
176
176
iter. stack . pop ( ) ;
177
177
}
178
178
Some ( Node :: Link { links } ) => {
179
- if stack. idx < links. len ( ) {
180
- let link = & links[ stack. idx ] ;
179
+ if ( stack. idx as usize ) < links. len ( ) {
180
+ let link = & links[ stack. idx as usize ] ;
181
181
match link {
182
182
Some ( Link :: Cid { cid, cache } ) => {
183
183
match cache. get_or_try_init ( || {
@@ -206,7 +206,7 @@ where
206
206
}
207
207
None => {
208
208
stack. idx += 1 ;
209
- iter. key += 2_usize . pow ( iter. bit_width ) ;
209
+ iter. key += 2_u64 . pow ( iter. bit_width ) ;
210
210
}
211
211
} ;
212
212
} else {
@@ -235,7 +235,7 @@ where
235
235
BS : Blockstore ,
236
236
{
237
237
type IntoIter = Iter < ' a , V , & ' a BS , Ver > ;
238
- type Item = Result < ( usize , & ' a V ) , crate :: Error > ;
238
+ type Item = Result < ( u64 , & ' a V ) , crate :: Error > ;
239
239
fn into_iter ( self ) -> Self :: IntoIter {
240
240
self . iter ( )
241
241
}
@@ -246,27 +246,27 @@ pub struct Iter<'a, V, BS, Ver> {
246
246
blockstore : BS ,
247
247
bit_width : u32 ,
248
248
ver : PhantomData < Ver > ,
249
- key : usize ,
249
+ key : u64 ,
250
250
}
251
251
252
252
pub struct IterStack < ' a , V > {
253
253
pub ( crate ) node : Option < & ' a Node < V > > ,
254
- pub ( crate ) idx : usize ,
254
+ pub ( crate ) idx : u64 ,
255
255
}
256
256
257
257
impl < ' a , V , BS , Ver > Iterator for Iter < ' a , V , BS , Ver >
258
258
where
259
259
BS : Blockstore ,
260
260
V : Serialize + DeserializeOwned ,
261
261
{
262
- type Item = Result < ( usize , & ' a V ) , crate :: Error > ;
262
+ type Item = Result < ( u64 , & ' a V ) , crate :: Error > ;
263
263
fn next ( & mut self ) -> Option < Self :: Item > {
264
264
loop {
265
265
let stack = self . stack . last_mut ( ) ?;
266
266
match stack. node {
267
267
Some ( Node :: Leaf { vals } ) => {
268
- while stack. idx < vals. len ( ) {
269
- match vals[ stack. idx ] {
268
+ while ( stack. idx as usize ) < vals. len ( ) {
269
+ match vals[ stack. idx as usize ] {
270
270
Some ( ref v) => {
271
271
stack. idx += 1 ;
272
272
self . key += 1 ;
@@ -281,8 +281,8 @@ where
281
281
self . stack . pop ( ) ;
282
282
}
283
283
Some ( Node :: Link { links } ) => {
284
- if stack. idx < links. len ( ) {
285
- let link = & links[ stack. idx ] ;
284
+ if ( stack. idx as usize ) < links. len ( ) {
285
+ let link = & links[ stack. idx as usize ] ;
286
286
match link {
287
287
Some ( Link :: Cid { cid, cache } ) => {
288
288
match cache. get_or_try_init ( || {
@@ -311,7 +311,7 @@ where
311
311
}
312
312
None => {
313
313
stack. idx += 1 ;
314
- self . key += 2_usize . pow ( self . bit_width ) ;
314
+ self . key += 2_u64 . pow ( self . bit_width ) ;
315
315
}
316
316
} ;
317
317
} else {
@@ -393,14 +393,8 @@ mod tests {
393
393
amt. set ( 8 , "foo" . to_owned ( ) ) . unwrap ( ) ;
394
394
amt. set ( 64 , "bar" . to_owned ( ) ) . unwrap ( ) ;
395
395
let mut amt_iter = amt. iter ( ) ;
396
- assert_eq ! (
397
- amt_iter. next( ) . unwrap( ) . unwrap( ) ,
398
- ( 8_usize , & "foo" . to_owned( ) )
399
- ) ;
400
- assert_eq ! (
401
- amt_iter. next( ) . unwrap( ) . unwrap( ) ,
402
- ( 64_usize , & "bar" . to_owned( ) )
403
- ) ;
396
+ assert_eq ! ( amt_iter. next( ) . unwrap( ) . unwrap( ) , ( 8 , & "foo" . to_owned( ) ) ) ;
397
+ assert_eq ! ( amt_iter. next( ) . unwrap( ) . unwrap( ) , ( 64 , & "bar" . to_owned( ) ) ) ;
404
398
}
405
399
406
400
#[ test]
@@ -412,7 +406,7 @@ mod tests {
412
406
let mut restored = Vec :: new ( ) ;
413
407
#[ allow( deprecated) ]
414
408
a. for_each ( |k, v| {
415
- restored. push ( ( * k , v. clone ( ) ) ) ;
409
+ restored. push ( ( k as usize , v. clone ( ) ) ) ;
416
410
Ok ( ( ) )
417
411
} )
418
412
. unwrap ( ) ;
@@ -451,7 +445,7 @@ mod tests {
451
445
#[ allow( deprecated) ]
452
446
new_amt
453
447
. for_each ( |k, _: & BytesDe | {
454
- if * k as u64 != indexes[ x] {
448
+ if k as u64 != indexes[ x] {
455
449
panic ! (
456
450
"for each found wrong index: expected {} got {}" ,
457
451
indexes[ x] , k
@@ -494,7 +488,7 @@ mod tests {
494
488
amt. set ( idx, "foo" . to_owned ( ) ) . unwrap ( ) ;
495
489
assert_eq ! (
496
490
amt. iter( ) . next( ) . unwrap( ) . unwrap( ) ,
497
- ( idx as usize , & "foo" . to_owned( ) )
491
+ ( idx, & "foo" . to_owned( ) )
498
492
) ;
499
493
}
500
494
@@ -533,7 +527,7 @@ mod tests {
533
527
534
528
// Create an AMT with 5 keys.
535
529
let mut amt = Amt :: new ( store) ;
536
- let kvs: Vec < usize > = ( 0 ..=5 ) . collect ( ) ;
530
+ let kvs: Vec < u64 > = ( 0 ..=5 ) . collect ( ) ;
537
531
let _ = kvs
538
532
. iter ( )
539
533
. map ( |k| amt. set ( u64:: try_from ( * k) . unwrap ( ) , k. to_string ( ) ) )
0 commit comments