Skip to content

Commit

Permalink
Faster multihash sort (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
gammazero authored Mar 8, 2024
1 parent 765897b commit fdc2d77
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/gammazero/radixtree v0.3.1
github.com/ipfs/go-cid v0.4.1
github.com/ipfs/go-log/v2 v2.5.1
github.com/ipni/go-libipni v0.5.13
github.com/ipni/go-libipni v0.5.14
github.com/libp2p/go-libp2p v0.33.0
github.com/mr-tron/base58 v1.2.0
github.com/multiformats/go-multihash v0.2.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ github.com/ipfs/go-log/v2 v2.5.1 h1:1XdUzF7048prq4aBjDQQ4SL5RxftpRGdXhNRwKSAlcY=
github.com/ipfs/go-log/v2 v2.5.1/go.mod h1:prSpmC1Gpllc9UYWxDiZDreBYw7zp4Iqp1kOLU9U5UI=
github.com/ipld/go-ipld-prime v0.21.0 h1:n4JmcpOlPDIxBcY037SVfpd1G+Sj1nKZah0m6QH9C2E=
github.com/ipld/go-ipld-prime v0.21.0/go.mod h1:3RLqy//ERg/y5oShXXdx5YIp50cFGOanyMctpPjsvxQ=
github.com/ipni/go-libipni v0.5.13 h1:4aE7c/DnTwEJNWQY33hYQqAZHkXCazdjUg8buNxM8as=
github.com/ipni/go-libipni v0.5.13/go.mod h1:dL/2YiaL7pVUmtwoa017M9i4bFqYTvehsZNASU22UXE=
github.com/ipni/go-libipni v0.5.14 h1:crJK8WRWajCv5K2kS7jXAhL5KnC4rYqdA8KFI2JCHCY=
github.com/ipni/go-libipni v0.5.14/go.mod h1:dL/2YiaL7pVUmtwoa017M9i4bFqYTvehsZNASU22UXE=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.17.6 h1:60eq2E/jlfwQXtvZEeBUYADs+BwKBWURIY+Gj2eRGjI=
Expand Down
10 changes: 3 additions & 7 deletions store/pebble/pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"errors"
"io"
"sort"
"slices"
"time"

"github.com/cockroachdb/pebble"
Expand Down Expand Up @@ -150,9 +150,7 @@ func (s *store) Put(v indexer.Value, mhs ...multihash.Multihash) error {
// multihashes means their resulting keys will also be sorted.
if len(mhs) > 1 {
// Make a copy to reorder.
sort.Slice(mhs, func(i, j int) bool {
return bytes.Compare(mhs[i], mhs[j]) == -1
})
slices.SortFunc(mhs, func(a, b multihash.Multihash) int { return bytes.Compare(a, b) })
}

keygen := s.p.leaseBlake3Keyer()
Expand Down Expand Up @@ -203,9 +201,7 @@ func (s *store) Remove(v indexer.Value, mhs ...multihash.Multihash) error {
// multihash key is a prefix plus the multihash itself, sorting the
// multihashes means their resulting keys will also be sorted.
if len(mhs) > 1 {
sort.Slice(mhs, func(i, j int) bool {
return bytes.Compare(mhs[i], mhs[j]) == -1
})
slices.SortFunc(mhs, func(a, b multihash.Multihash) int { return bytes.Compare(a, b) })
}

keygen := s.p.leaseBlake3Keyer()
Expand Down

0 comments on commit fdc2d77

Please sign in to comment.