godropbox: github.com/dropbox/godropbox/container/set Index | Files

package set

import "github.com/dropbox/godropbox/container/set"

Implementation of a Set container

Index

Package Files

doc.go set.go

type Set Uses

type Set interface {
    // Returns a new empty Set of the same type.
    New() Set

    // Returns a new Set that contains exactly the same elements as this set.
    Copy() Set

    // Returns the cardinality of this set.
    Len() int

    // Returns true if and only if this set contains v (according to Go equality rules).
    Contains(v interface{}) bool
    // Inserts v into this set.
    Add(v interface{})
    // Removes v from this set, if it is present.  Returns true if and only if v was present.
    Remove(v interface{}) bool

    // Executes f(v) for every element v in this set.  If f mutates this set, behavior is undefined.
    Do(f func(interface{}))
    // Executes f(v) once for every element v in the set, aborting if f ever returns false. If f
    // mutates this set, behavior is undefined.
    DoWhile(f func(interface{}) bool)
    // Returns a channel from which each element in the set can be read exactly once.  If this set
    // is mutated before the channel is emptied, the exact data read from the channel is undefined.
    Iter() <-chan interface{}

    // Adds every element in s into this set.
    Union(s Set)
    // Removes every element not in s from this set.
    Intersect(s Set)
    // Removes every element in s from this set.
    Subtract(s Set)
    // Removes all elements from the set.
    Init()
    // Returns true if and only if all elements in this set are elements in s.
    IsSubset(s Set) bool
    // Returns true if and only if all elements in s are elements in this set.
    IsSuperset(s Set) bool
    // Returns true if and only if this set and s contain exactly the same elements.
    IsEqual(s Set) bool
    // Removes all elements v from this set that satisfy f(v) == true.
    RemoveIf(f func(interface{}) bool)
}

An unordered collection of unique elements which supports lookups, insertions, deletions, iteration, and common binary set operations. It is not guaranteed to be thread-safe.

func Intersect Uses

func Intersect(s1 Set, s2 Set) Set

Returns a new set which is the intersect of s1 and s2. s1 and s2 are unmodified.

func NewKeyedSet Uses

func NewKeyedSet(keyf func(interface{}) interface{}, items ...interface{}) Set

Returns a new Set pre-populated with the given items

func NewSet Uses

func NewSet(items ...interface{}) Set

Returns a new Set pre-populated with the given items

func Subtract Uses

func Subtract(s1 Set, s2 Set) Set

Returns a new set which is the difference between s1 and s2. s1 and s2 are unmodified.

func Union Uses

func Union(s1 Set, s2 Set) Set

Returns a new set which is the union of s1 and s2. s1 and s2 are unmodified.

Package set is imported by 165 packages. Updated 2019-12-05. Refresh now. Tools for package owners.