memberset

package module
v0.0.0-...-c628f6f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2018 License: Unlicense Imports: 1 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

memberset

Build Status GoDoc

A simple set used for testing memberships in Go.

Usage

import "github.com/davidk/memberset"

m := memberset.New()

// Adding a value into the set is just a m.Add() call
// Other types are also acceptable, like ints, floats, etc (as long as it works with an interface{})
m.Add("123")

// If it helps your mnemonic memory, m.Add() is just an alias to m.Set()
m.Set(123) // <--- This is the same as m.Add(123)

// Eventually, we'll need to check to see if what we added is present in the set
if ok := m.Get("123"); ok {
  // Yes, do something
} else {
  // No, do something else
}

// And maybe we'll need to remove "123" from the set
m.Delete("123")

Installation

Get started by vendoring or by using go get -u github.com/davidk/memberset

There are other projects that have more through set implementations. Check these out:

And a proposal on golang/go to add a built-in set type.

License

CC0 1.0 Universal

Documentation

Overview

Package memberset is a simple set used for testing memberships in Go.

import "github.com/davidk/memberset"

m := memberset.New()

// Other types are also acceptable, like ints

m.Add("123")

// Is string "123" a member?

if ok := m.Get("123"); ok {
  // Yes
} else {
  // No
}

// To remove "123" from the set

m.Delete("123")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemberSet

type MemberSet struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

MemberSet wraps up a map[interface{}]struct{} for ease of use.

func New

func New() *MemberSet

New initializes a new MemberSet

func (*MemberSet) Add

func (s *MemberSet) Add(value interface{})

Add is an alias to Set()

func (*MemberSet) Delete

func (s *MemberSet) Delete(value interface{})

Delete removes the value from the set

func (*MemberSet) Get

func (s *MemberSet) Get(value interface{}) bool

Get looks for an item in the set. It doesn't really retrieve anything, just checks for existence.

func (*MemberSet) Set

func (s *MemberSet) Set(value interface{})

Set adds a value to the set

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址