Source File
set.go
Belonging Package
github.com/ipfs/go-cid
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[Cid]struct{}}// NewSet initializes and returns a new Set.func () *Set {return &Set{set: make(map[Cid]struct{})}}// Add puts a Cid in the Set.func ( *Set) ( Cid) {.set[] = struct{}{}}// Has returns if the Set contains a given Cid.func ( *Set) ( Cid) bool {, := .set[]return}// Remove deletes a Cid from the Set.func ( *Set) ( Cid) {delete(.set, )}// Len returns how many elements the Set has.func ( *Set) () int {return len(.set)}// Keys returns the Cids in the set.func ( *Set) () []Cid {:= make([]Cid, 0, len(.set))for := range .set {= append(, )}return}// Visit adds a Cid to the set only if it is// not in it already.func ( *Set) ( Cid) bool {if !.Has() {.Add()return true}return false}// ForEach allows to run a custom function on each// Cid in the set.func ( *Set) ( func( Cid) error) error {for := range .set {:= ()if != nil {return}}return nil}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |