Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ipfs/kubo
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1673b9cc3c3a
Choose a base ref
...
head repository: ipfs/kubo
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: bd7c74df982f
Choose a head ref
  • 3 commits
  • 1 file changed
  • 1 contributor

Commits on May 13, 2015

  1. Copy-pasto

    tv42 committed May 13, 2015
    Copy the full SHA
    e28153c View commit details
  2. Copy the full SHA
    bd19fdf View commit details
  3. pin: Simplify code

    tv42 committed May 13, 2015
    Copy the full SHA
    bd7c74d View commit details
Showing with 14 additions and 4 deletions.
  1. +14 −4 pin/set.go
18 changes: 14 additions & 4 deletions pin/set.go
Original file line number Diff line number Diff line change
@@ -210,7 +210,7 @@ func walkItems(ctx context.Context, dag merkledag.DAGService, n *merkledag.Node,
return err
}
// readHdr guarantees fanout is a safe value
fanout := int(hdr.GetFanout())
fanout := hdr.GetFanout()
for i, l := range n.Links[fanout:] {
if err := fn(buf, i, l); err != nil {
return err
@@ -251,9 +251,6 @@ func loadSet(ctx context.Context, dag merkledag.DAGService, root *merkledag.Node
if err := walkItems(ctx, dag, n, walk, internalKeys); err != nil {
return nil, err
}
if err != nil {
return nil, err
}
return res, nil
}

@@ -302,12 +299,25 @@ func storeSet(ctx context.Context, dag merkledag.DAGService, keys []util.Key, in

func storeMultiset(ctx context.Context, dag merkledag.DAGService, refcounts map[util.Key]uint64, internalKeys keyObserver) (*merkledag.Node, error) {
iter := func() (k util.Key, data []byte, ok bool) {
// Every call of this function returns the next refcount item.
//
// This function splits out the uint64 reference counts as
// smaller increments, as fits in type refcount. Most of the
// time the refcount will fit inside just one, so this saves
// space.
//
// We use range here to pick an arbitrary item in the map, but
// not really iterate the map.
for k, refs := range refcounts {
num := ^refcount(0)
if refs <= uint64(num) {
// Remaining count fits in a single item; remove the
// key from the map.
num = refcount(refs)
delete(refcounts, k)
} else {
// Count is too large to fit in one item, the key will
// repeat in some later call.
refcounts[k] -= uint64(num)
}
return k, num.Bytes(), true