set

package
v1.0.47 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MIT Imports: 2 Imported by: 3

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set[V comparable] map[V]struct{}

Set 基于map的Set.

func NewSet

func NewSet[V comparable](elems ...V) Set[V]

NewSet 新建MapSet.

Example

ExampleNewSet is an example function.

package main

import (
	"fmt"
	"sort"

	"github.com/xuender/kit/set"
)

func main() {
	nums := set.NewSet(1, 2, 3)

	fmt.Println(len(nums))
	fmt.Println(len(nums.Add(3, 4, 5)))

	fmt.Println(nums.Has(0))
	fmt.Println(nums.Has(3))

	delete(nums, 2)
	ints := nums.Slice()
	sort.Ints(ints)

	fmt.Println(ints)

}
Output:

3
5
false
true
[1 3 4 5]

func (Set[V]) Add

func (p Set[V]) Add(elems ...V) Set[V]

Add 增加元素.

func (Set[V]) AddSet

func (p Set[V]) AddSet(set ...Set[V]) Set[V]

AddSet 增加集合.

func (Set[V]) Has

func (p Set[V]) Has(elem V) bool

Has 包含.

func (Set[V]) Slice

func (p Set[V]) Slice() []V

Slice 转换切片.

type Sync

type Sync[V comparable] struct {
	// contains filtered or unexported fields
}

Sync 线程安全Set.

func NewSync

func NewSync[V comparable](elems ...V) *Sync[V]

NewSync 新建线程安全Set.

Example

ExampleNewSync is an example function.

package main

import (
	"fmt"
	"sort"

	"github.com/xuender/kit/set"
)

func main() {
	nums := set.NewSync(1, 2, 3)

	fmt.Println(nums.Len())
	fmt.Println(nums.Add(3, 4, 5).Len())

	fmt.Println(nums.Has(0))
	fmt.Println(nums.Has(3))

	nums.Delete(2)
	ints := nums.Slice()
	sort.Ints(ints)

	fmt.Println(ints)

}
Output:

3
5
false
true
[1 3 4 5]

func (*Sync[V]) Add

func (p *Sync[V]) Add(elems ...V) *Sync[V]

Add 增加元素.

func (*Sync[V]) Delete

func (p *Sync[V]) Delete(elems ...V) *Sync[V]

Delete 删除元素.

func (*Sync[V]) Has

func (p *Sync[V]) Has(elem V) bool

Has 包含.

func (*Sync[V]) Iterate

func (p *Sync[V]) Iterate(yield func(V) error) error

Iterate 迭代.

func (*Sync[V]) Len

func (p *Sync[V]) Len() int

Len 集合长度.

func (*Sync[V]) Slice

func (p *Sync[V]) Slice() []V

Slice 转换成切片.

Jump to

Keyboard shortcuts

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