collections

package
v1.2.97 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: MIT Imports: 4 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddIfNotExists

func AddIfNotExists(vs []string, t string) []string

Add item to list only if it does not exist

func All

func All(vs []string, f func(string) bool) bool

All returns `true` if all the strings in the slice satisfy the predicate `f`.

func AllN

func AllN(vs []int, f func(int) bool) bool

AllN returns `true` if all the integers in the slice satisfy the predicate `f`.

func Any

func Any(vs []string, f func(string) bool) bool

Any returns `true` if one of the strings in the slice satisfies the predicate `f`.

func AnyN

func AnyN(vs []int, f func(int) bool) bool

AnyN returns `true` if one of the integers in the slice satisfies the predicate `f`.

func BitMaskInclude

func BitMaskInclude(src, flag int) bool

BitMaskInclude checks if the src bitmask including the flag

func Concat

func Concat(slices ...[]string) []string

Concatenate multiple string slices efficiently

func ConcatN

func ConcatN(slices ...[]int) []int

Concatenate multiple int slices efficiently

func Distinct

func Distinct(vs []string) []string

Distinct returns a new slice without duplications

func DistinctN

func DistinctN(vs []int) []int

DistinctN returns a new slice without duplications

func Filter

func Filter(vs []string, f func(string) bool) []string

Filter returns a new slice containing all strings in the slice that satisfy the predicate `f`.

func FilterN

func FilterN(vs []int, f func(int) bool) []int

FilterN returns a new slice containing all integers in the slice that satisfy the predicate `f`.

func Include

func Include(vs []string, t string) bool

Include returns `true` if the target string t is in the slice.

func IncludeMask

func IncludeMask(vs []int, t int) bool

func IncludeN

func IncludeN(vs []int, t int) bool

IncludeN returns `true` if the target int t is in the slice.

func Index

func Index(vs []string, t string) int

Index returns the first index of the target string `t`, or -1 if no match is found.

func IndexN

func IndexN(vs []int, t int) int

IndexN returns the first index of the target int `t`, or -1 if no match is found.

func Intersect

func Intersect(slices ...[]string) []string

Intersect returns only the string values in all slices

func IntersectN

func IntersectN(slices ...[]int) []int

Intersect returns only the values in all slices

func JoinN

func JoinN(slice []int, sep string) string

JoinN convert all integers in the slice to strings and joins them together as a single string with separator

func Map

func Map(vs []string, f func(string) string) []string

Map returns a new slice containing the results of applying the function `f` to each string in the original slice.

func MapN

func MapN(vs []int, f func(int) int) []int

MapN returns a new slice containing the results of applying the function `f` to each integers in the original slice.

func Remove

func Remove(vs []string, t string) []string

Remove an item from the array

Types

type ConcurrentStringMap

type ConcurrentStringMap[T any] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ConcurrentStringMap enable safe shared map with Read/Write locks

func NewConcurrentStringMap

func NewConcurrentStringMap[T any]() ConcurrentStringMap[T]

NewConcurrentStringMap factory method

func (*ConcurrentStringMap[T]) Get

func (c *ConcurrentStringMap[T]) Get(key string) (T, bool)

Get retrieve item from map

func (*ConcurrentStringMap[T]) Keys added in v1.2.63

func (c *ConcurrentStringMap[T]) Keys() (result []string)

Keys returns all the keys in the map

func (*ConcurrentStringMap[T]) KeysAndValues added in v1.2.63

func (c *ConcurrentStringMap[T]) KeysAndValues() (keys []string, values []T)

KeysAndValues returns all the keys and the values in the map

func (*ConcurrentStringMap[T]) Put

func (c *ConcurrentStringMap[T]) Put(key string, val T)

Put set item in the map

func (*ConcurrentStringMap[T]) Values added in v1.2.63

func (c *ConcurrentStringMap[T]) Values() (result []T)

Values returns all the values in the map

type Queue

type Queue interface {
	// Push item into a queue
	Push(v any)

	// Pop last item
	Pop() (any, bool)

	// Length get length of the queue
	Length() int
}

Queue functions for manager data items in a stack

func NewQueue

func NewQueue() Queue

NewQueue get queue functions manager

type Stack

type Stack interface {
	// push item into a stack
	Push(v any)

	// pop last item
	Pop() (any, bool)

	// pop many items
	PopMany(count int64) ([]any, bool)

	// pop all items
	PopAll() ([]any, bool)

	// peek last item
	Peek() (any, bool)

	// get length of stack
	Length() int64

	// is empty stack
	IsEmpty() bool
}

Stack functions for manager data items in a stack

func NewStack

func NewStack() Stack

New get stack functions manager

Jump to

Keyboard shortcuts

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