Compare commits
5 Commits
gx/v0.7.24
...
gx/v0.7.25
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
73e5246a65 | ||
|
|
83a7594d41 | ||
|
|
3655c1cdd4 | ||
|
|
1543f4a136 | ||
|
|
d6e0b4e5a7 |
@@ -1 +1 @@
|
||||
0.7.24: Qmdu2AYUV7yMoVBQPxXNfe7FJcdx16kYtsx6jAPKWQYF1y
|
||||
0.7.25: QmYjnkEL7i731PirfVH1sis89evN7jt4otSHw5D2xXXwUV
|
||||
|
||||
14
cid_test.go
14
cid_test.go
@@ -414,3 +414,17 @@ func TestJsonRoundTrip(t *testing.T) {
|
||||
t.Fatal("cids not equal for Cid")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkStringV1(b *testing.B) {
|
||||
data := []byte("this is some test content")
|
||||
hash, _ := mh.Sum(data, mh.SHA2_256, -1)
|
||||
cid := NewCidV1(Raw, hash)
|
||||
b.ResetTimer()
|
||||
count := 0
|
||||
for i := 0; i < b.N; i++ {
|
||||
count += len(cid.String())
|
||||
}
|
||||
if count != 49*b.N {
|
||||
b.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,6 @@
|
||||
"license": "MIT",
|
||||
"name": "go-cid",
|
||||
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
|
||||
"version": "0.7.24"
|
||||
"version": "0.7.25"
|
||||
}
|
||||
|
||||
|
||||
35
set.go
35
set.go
@@ -1,5 +1,9 @@
|
||||
package cid
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
// Set is a implementation of a set of Cids, that is, a structure
|
||||
// to which holds a single copy of every Cids that is added to it.
|
||||
type Set struct {
|
||||
@@ -65,3 +69,34 @@ func (s *Set) ForEach(f func(c *Cid) error) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// StreamingSet is an extension of Set which allows to implement back-pressure
|
||||
// for the Visit function
|
||||
type StreamingSet struct {
|
||||
Set *Set
|
||||
New chan *Cid
|
||||
}
|
||||
|
||||
// NewStreamingSet initializes and returns new Set.
|
||||
func NewStreamingSet() *StreamingSet {
|
||||
return &StreamingSet{
|
||||
Set: NewSet(),
|
||||
New: make(chan *Cid),
|
||||
}
|
||||
}
|
||||
|
||||
// Visitor creates new visitor which adds a Cids to the set and emits them to
|
||||
// the set.New channel
|
||||
func (s *StreamingSet) Visitor(ctx context.Context) func(c *Cid) bool {
|
||||
return func(c *Cid) bool {
|
||||
if s.Set.Visit(c) {
|
||||
select {
|
||||
case s.New <- c:
|
||||
case <-ctx.Done():
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user