Skip to content

abishekk92/goset

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

goset

Build Status codecov GoDoc Go Report Card experimental

Set implementation for golang

To install goset

    go get github.com/abishekk92/goset

To Create a new set

    import (
        "github.com/abishekk92/goset"
        )

    func main() {
        newSet := goset.NewSet() //Creates a new set
        newSet.Add("a", "b") //Adds a new element to the set
        newSet.Remove("b") //Removes an element from the set
        newSet.IsMember("a") //Checks if 'a' is a member of the set
    }

To Union two sets

    import (
        "github.com/abishekk92/goset"
        )

    func main() {
        A := goset.NewSet()
        B := goset.NewSet()
        A.Add("a", "b")
        B.Add("a")
        uninonSet := A.Union(B)
    }

To Intersect two sets

    import (
        "github.com/abishekk92/goset"
        )

    func main() {
        A := goset.NewSet()
        B := goset.NewSet()
        A.Add("a", "b")
        B.Add("a")
        intersectionSet := A.Intersect(B)
    }

To get an array of elements

    import (
        "github.com/abishekk92/goset"
        )

    func main() {
        A := goset.NewSet()
        A.Add("a", "b")
        items := A.ToArray()
    }

To find set difference

    import (
        "github.com/abishekk92/goset"
        )

    func main() {
        A := goset.NewSet()
        A.Add("a", "b", "c", "d")
        B := goset.NewSet()
        B.Add("a", "b")
        C := A.Difference(B) // result would be C{"c", "d"}
    }

About

Set implementation for golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages