Source File
set.go
Belonging Package
github.com/multiformats/go-multihash
package multihash// Set is a set of Multihashes, holding one copy per Multihash.type Set struct {set map[string]struct{}}// NewSet creates a new set correctly initialized.func () *Set {return &Set{set: make(map[string]struct{}),}}// Add adds a new multihash to the set.func ( *Set) ( Multihash) {.set[string()] = struct{}{}}// Len returns the number of elements in the set.func ( *Set) () int {return len(.set)}// Has returns true if the element is in the set.func ( *Set) ( Multihash) bool {, := .set[string()]return}// Visit adds a multihash only if it is not in the set already. Returns true// if the multihash was added (was not in the set before).func ( *Set) ( Multihash) bool {, := .set[string()]if ! {.set[string()] = struct{}{}return true}return false}// ForEach runs f(m) with each multihash in the set. If returns immediately if// f(m) returns an error.func ( *Set) ( func( Multihash) error) error {for := range .set {:= Multihash()if := (); != nil {return}}return nil}// Remove removes an element from the set.func ( *Set) ( Multihash) {delete(.set, string())}// All returns a slice with all the elements in the set.func ( *Set) () []Multihash {:= make([]Multihash, 0, len(.set))for := range .set {= append(, Multihash())}return}
![]() |
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. |