set

package
v0.0.0-...-4553cd5 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2016 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package set Set Data Structure based on map and sync.RWMutex

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

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

Set safe map

Example
package main

import (
	"fmt"

	"github.com/upyun/utilgo/set"
)

func main() {
	s := set.New()
	s.Add(1)
	s.Add(2)
	s.Add(3)
	s.Remove(2)
	fmt.Println(s.Len())
	fmt.Println(s.Has(1))
	fmt.Println(s.Has(2))
	fmt.Println(s.Has(3))
}
Output:

2
true
false
true

func New

func New() *Set

New new set

func (*Set) Add

func (s *Set) Add(item interface{})

Add add

func (*Set) Clear

func (s *Set) Clear()

Clear removes all items from the set

func (*Set) Each

func (s *Set) Each(fn func(interface{}))

Each call fn on each element in the Set

func (*Set) Has

func (s *Set) Has(item interface{}) bool

Has looks for the existence of an item

func (*Set) IsEmpty

func (s *Set) IsEmpty() bool

IsEmpty checks for emptiness

func (*Set) Len

func (s *Set) Len() int

Len returns the number of items in a set.

func (*Set) List

func (s *Set) List() []interface{}

List Set returns a slice of all items

func (*Set) Remove

func (s *Set) Remove(item interface{})

Remove deletes the specified item from the map

Jump to

Keyboard shortcuts

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