gset

package
v0.0.0-...-3e416e1 Latest Latest
Warning

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

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

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
}

Set each value in set is unique, and keep the sequence of Add() or Merge()

func New

func New() *Set

New returns a new *Set object

func (*Set) Add

func (s *Set) Add(value ...interface{})

Add adds a value to set, if value not exists in set s.

func (*Set) AddFront

func (s *Set) AddFront(value ...interface{})

AddFront adds a value to set, if value not exists in set s. The value will be stored the first in set s if value not exists.

func (*Set) CartesianProduct

func (s *Set) CartesianProduct(sets ...*Set) [][]interface{}

CartesianProduct → {(x, y) | ∀ x ∈ s1, ∀ y ∈ s2} For example:

		CartesianProduct(A, B), where A = {1, 2} and B = {7, 8}
       => {(1, 7), (1, 8), (2, 7), (2, 8)}

func (*Set) Clear

func (s *Set) Clear() *Set

Clear duplicates the set s.

func (*Set) Clone

func (s *Set) Clone() *Set

Clone duplicates the set s.

func (*Set) CloneAndClear

func (s *Set) CloneAndClear() *Set

CloneAndClear duplicates the set s.

func (*Set) Contains

func (s *Set) Contains(value interface{}) (exists bool)

Contains returns true if value exists in set s, otherwise false.

func (*Set) Delete

func (s *Set) Delete(value ...interface{})

Delete removes a value from set.

func (*Set) IndexOf

func (s *Set) IndexOf(k interface{}) int

IndexOf indicates the index of value in Map s, if not found returns -1.

idx start with 0.

func (*Set) Len

func (s *Set) Len() int

Len returns length of the set s.

func (*Set) Merge

func (s *Set) Merge(set *Set)

Merge merges set values to set s.

Kept the Add() sequence.

func (*Set) MergeSlice

func (s *Set) MergeSlice(data []interface{})

MergeSlice merges slice values to set s.

Kept the Add() sequence.

func (*Set) MergeStringSlice

func (s *Set) MergeStringSlice(data []string)

MergeStringSlice merges slice values to set s.

Kept the Add() sequence.

func (*Set) Pop

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

Pop returns last value of set s, and remove it.

func (*Set) Range

func (s *Set) Range(f func(value interface{}) bool)

Range ranges the value in set s, if function f return false, the range loop will break.

Range keeps the Add() sequence.

func (*Set) RangeFast

func (s *Set) RangeFast(f func(value interface{}) bool)

RangeFast ranges the value in set s, if function f return false, the range loop will break.

RangeFast do not create a snapshot for range, so you can not modify list s in range loop, indicate do not call Remove(), Add(), Merge() etc.

func (*Set) Shift

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

Shift returns first value of set s, and remove it.

func (*Set) String

func (s *Set) String() string

String returns string format of the Set.

func (*Set) ToSlice

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

ToSlice convert set s to slice []interface{}.

Kept the Add() sequence.

func (*Set) ToStringSlice

func (s *Set) ToStringSlice() []string

ToStringSlice convert set s to slice []interface{}.

Kept the Add() sequence.

Jump to

Keyboard shortcuts

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