set

package
v0.23.8 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2022 License: AGPL-3.0, AGPL-3.0-only Imports: 0 Imported by: 0

Documentation

Overview

Example
package main

import (
	"fmt"

	"github.com/bangumi/server/internal/pkg/generic/set"
)

func main() {
	s := set.New[string]()
	s.Add("foo")
	s.Add("bar")
	s.Add("baz")

	fmt.Println(s.Has("foo"))
	fmt.Println(s.Has("quux"))
}
Output:

true
false

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

Set is a not thread-safe set based on built-in map.

func FromSlice

func FromSlice[T comparable](in []T) Set[T]

func New

func New[T comparable]() Set[T]

func (Set[T]) Add

func (s Set[T]) Add(item T)

func (Set[K]) Each

func (s Set[K]) Each(fn func(key K))

func (Set[T]) Has

func (s Set[T]) Has(item T) bool

func (Set[T]) Intersection

func (s Set[T]) Intersection(o Set[T]) Set[T]

Intersection return a new set = (s1 & s2).

func (Set[T]) Len

func (s Set[T]) Len() int

func (Set[T]) Remove

func (s Set[T]) Remove(item T)

func (Set[T]) Union

func (s Set[T]) Union(o Set[T]) Set[T]

Union return a new set = (s1 | s2).

Jump to

Keyboard shortcuts

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