Git Product home page Git Product logo

set's Introduction

set - golang set collection

This is a very basic implementation of a set collection type in golang

http://en.wikipedia.org/wiki/Set_(computer_science)

"In computer science, a set is an abstract data structure that can store certain values, without any particular order, and no repeated values. It is a computer implementation of the mathematical concept of a finite set. Unlike most other collection types, rather than retrieving a specific element from a set, one typically tests a value for membership in a set."

This implementation supports initializing empty sets and sets with an initial collection. It supports adding and removing items. You can test whether a set contains a specific value, whether the set is empty, or whether the set is a subset of another set. You can check for the set size, pop items from the set, clear the content of the set, and return an enumerator of the set contents. You can map a function against the set contents and filter a set against a filter function. Additionally, you can get the union, intersection and difference of two sets.

USAGE

package main

import(
    "github.com/shopsmart/set"
    "log"
)

func main() {
    // Initialize an empty set
    mySet := set.New()

    // Initialize a set with a collection of values
    colors := set.New("red", "blue", "green", "yellow")

    // Add items
    colors.Add("purple")

    // Check to see if an item is in the set
    log.Println(colors.Contains("red")) // true

    // Check the size of the set
    log.Println(colors.Size()) // 5

    // Distinct values will only be added one time
    colors.Add("purple")
    log.Println(colors.Size()) // Still 5

    // Check to see if a set is empty
    log.Println(mySet.IsEmpty()) // true
    log.Println(mySet.Size()) // 0
    log.Println(colors.IsEmpty()) // false
    log.Println(colors.Size()) // 5

    // Remove items from the set
    colors.Remove("red")
    log.Println(colors.Contains("red")) // false

    // Clear a map
    colors.Clear()
    log.Println(colors.IsEmpty()) // true
    log.Println(colors.Size()) // 0
}

set's People

Contributors

lostghost avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.