set

package
v0.0.0-...-9db4afe Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2018 License: Apache-2.0 Imports: 1 Imported by: 0

README

集合

类似于python的set,使用map的key唯一来确保集合元素的唯一。实现的方法有交集,并集,差集等。

使用例子:

package main

import (
    "github.com/luopengift/golibs/set"
    "fmt"
)

func main() {
    set1 := set.NewSet(1, "2", "3")
    set1.Add(1)
    fmt.Println(set1.Contains(1))
    set2 := set.NewSet("1", "2", "3", "4")
    fmt.Println(set1, set2)
    set3 := set.NewSet()
    fmt.Println("2-1", set2.Diff(set1))
    fmt.Println("1-2", set1.Diff(set2))
    fmt.Println(set1.Diff(set3))
    fmt.Println(set3.Len())
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set struct {
	// contains filtered or unexported fields
}

func NewSet

func NewSet(e ...interface{}) *Set

func (*Set) Add

func (self *Set) Add(e ...interface{}) *Set

func (*Set) Clear

func (self *Set) Clear() error

func (*Set) Contains

func (self *Set) Contains(v interface{}) bool

func (*Set) Diff

func (self *Set) Diff(o Setter) *Set

func (*Set) Elements

func (self *Set) Elements() []interface{}

func (*Set) Inter

func (self *Set) Inter(o Setter) *Set

func (*Set) Len

func (self *Set) Len() int

func (*Set) Remove

func (self *Set) Remove(v interface{}) *Set

func (*Set) Same

func (self *Set) Same(o Setter) bool

func (*Set) Union

func (self *Set) Union(o Setter) *Set

type Setter

type Setter interface {
	Add(e ...interface{}) *Set   //添加一个元素
	Remove(e interface{}) *Set   //删除一个元素
	Clear() error                //清空所有元素
	Contains(e interface{}) bool //
	Elements() []interface{}     //获取元素集合
	Len() int
	Same(other Setter) bool  //是否和其他set一致
	Union(other Setter) *Set //并集
	Inter(other Setter) *Set //交集
	Diff(other Setter) *Set  //差集
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳