Commit 9eb57afc authored by Hector Sanjuan's avatar Hector Sanjuan

Readme/golint: improve readme with gx instructions. Make golint happy.

License: MIT
Signed-off-by: default avatarHector Sanjuan <hector@protocol.ai>
parent bae78f13
package cid
// 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 {
set map[string]struct{}
}
// NewSet initializes and returns a new Set.
func NewSet() *Set {
return &Set{set: make(map[string]struct{})}
}
// Add puts a Cid in the Set.
func (s *Set) Add(c *Cid) {
s.set[string(c.Bytes())] = struct{}{}
}
// Has returns if the Set contains a given Cid.
func (s *Set) Has(c *Cid) bool {
_, ok := s.set[string(c.Bytes())]
return ok
}
// Remove deletes a Cid from the Set.
func (s *Set) Remove(c *Cid) {
delete(s.set, string(c.Bytes()))
}
// Len returns how many elements the Set has.
func (s *Set) Len() int {
return len(s.set)
}
// Keys returns the Cids in the set.
func (s *Set) Keys() []*Cid {
out := make([]*Cid, 0, len(s.set))
for k := range s.set {
......@@ -34,6 +42,8 @@ func (s *Set) Keys() []*Cid {
return out
}
// Visit adds a Cid to the set only if it is
// not in it already.
func (s *Set) Visit(c *Cid) bool {
if !s.Has(c) {
s.Add(c)
......@@ -43,6 +53,8 @@ func (s *Set) Visit(c *Cid) bool {
return false
}
// ForEach allows to run a custom function on each
// Cid in the set.
func (s *Set) ForEach(f func(c *Cid) error) error {
for cs := range s.set {
c, _ := Cast([]byte(cs))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment