@@ -460,10 +460,10 @@ func (ds *Shard) walkTrie(ctx context.Context, cb func(*Shard) error) error {
460
460
461
461
// setValue sets the link `value` in the given key, either creating the entry
462
462
// if it didn't exist or overwriting the old one. It returns the old entry (if any).
463
- func (ds * Shard ) setValue (ctx context.Context , hv * hashBits , key string , value * ipld.Link ) (oldValue * ipld.Link , err error ) {
463
+ func (ds * Shard ) setValue (ctx context.Context , hv * hashBits , key string , value * ipld.Link ) (* ipld.Link , error ) {
464
464
idx , err := hv .Next (ds .tableSizeLg2 )
465
465
if err != nil {
466
- return
466
+ return nil , err
467
467
}
468
468
469
469
if ! ds .childer .has (idx ) {
@@ -474,22 +474,22 @@ func (ds *Shard) setValue(ctx context.Context, hv *hashBits, key string, value *
474
474
i := ds .childer .sliceIndex (idx )
475
475
child , err := ds .childer .get (ctx , i )
476
476
if err != nil {
477
- return
477
+ return nil , err
478
478
}
479
479
480
480
if child .isValueNode () {
481
481
// Leaf node. This is the base case of this recursive function.
482
482
if child .key == key {
483
483
// We are in the correct shard (tree level) so we modify this child
484
484
// and return.
485
- oldValue = child .val
485
+ oldValue : = child .val
486
486
487
487
if value == nil { // Remove old entry.
488
488
return oldValue , ds .childer .rm (idx )
489
489
}
490
490
491
491
child .val = value // Overwrite entry.
492
- return
492
+ return oldValue , nil
493
493
}
494
494
495
495
if value == nil {
@@ -519,11 +519,11 @@ func (ds *Shard) setValue(ctx context.Context, hv *hashBits, key string, value *
519
519
// will create new ones until we find different slots for both.)
520
520
_ , err = child .setValue (ctx , hv , key , value )
521
521
if err != nil {
522
- return
522
+ return nil , err
523
523
}
524
524
_ , err = child .setValue (ctx , chhv , grandChild .key , grandChild .val )
525
525
if err != nil {
526
- return
526
+ return nil , err
527
527
}
528
528
529
529
// Replace this leaf node with the new Shard node.
@@ -532,9 +532,9 @@ func (ds *Shard) setValue(ctx context.Context, hv *hashBits, key string, value *
532
532
} else {
533
533
// We are in a Shard (internal node). We will recursively call this
534
534
// function until finding the leaf (the logic of the `if` case above).
535
- oldValue , err = child .setValue (ctx , hv , key , value )
535
+ oldValue , err : = child .setValue (ctx , hv , key , value )
536
536
if err != nil {
537
- return
537
+ return nil , err
538
538
}
539
539
540
540
if value == nil {
@@ -558,25 +558,25 @@ func (ds *Shard) setValue(ctx context.Context, hv *hashBits, key string, value *
558
558
if schild .isValueNode () {
559
559
ds .childer .set (schild , i )
560
560
}
561
- return
561
+ return oldValue , nil
562
562
}
563
563
564
564
// Otherwise, work with the link.
565
565
slnk := child .childer .link (0 )
566
566
var lnkType linkType
567
567
lnkType , err = child .childer .sd .childLinkType (slnk )
568
568
if err != nil {
569
- return
569
+ return nil , err
570
570
}
571
571
if lnkType == shardValueLink {
572
572
// sub-shard with a single value element, collapse it
573
573
ds .childer .setLink (slnk , i )
574
574
}
575
- return
575
+ return oldValue , nil
576
576
}
577
577
}
578
578
579
- return
579
+ return oldValue , nil
580
580
}
581
581
}
582
582
0 commit comments