sets

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: MIT Imports: 8 Imported by: 0

README

go-sets

Go Reference Build Status Release License

Easy-to-use generic set collections for Go (golang).

Provides separate implementations for mutable and immutable sets whilst making it easy to create clones of varying mutability. Immutable sets play well with concurrency out-of-the-box, however, a special implementation of a mutable set is available for concurrent use without requiring additional locking or coordination.

Set Elements Mutable Concurrency Safe
Empty 0 No Yes
Hash Infinite No Yes
MutableHash Infinite Yes No
Singleton 1 No Yes
SyncHash Infinite Yes Yes

Installation

Install using go install:

go install github.com/neocotic/go-sets

Then import the package into your own code:

import "github.com/neocotic/go-sets"

Documentation

Documentation is available on pkg.go.dev. It contains an overview and reference.

Example
set := sets.Hash(123, 456, 789, 456, 123)
set.Len() // => 3
set.IsEmpty() // => false
set.Contains(456) // => true
set.Contains(-456) // => false
set.Find(func(e int) bool { return e < 200 }) // => 123, true
set.Min(sets.Asc[int]) // => 123
set.Max(sets.Asc[int]) // => 789
set.Equal(sets.Hash(789, 456, 123)) // => true
set.Range(func(e int) bool { fmt.Printf("%v\n", e); return false })
set.Every(func(e int) bool { return e < 200 }) // => false
set.None(func(e int) bool { return e < 200 }) // => false
set.Some(func(e int) bool { return e < 200 }) // => true

filtered := set.Filter(func(e int) bool { return e < 200 })
filtered.Equal(sets.Singleton(123)) // => true

mset := set.Mutable()
mset.Put(0)
mset.Equal(sets.Hash(0, 123, 456, 789)) // => true

set.Intersection(mset).Equal(sets.Hash(123, 456, 789)) // => true
set.Diff(mset).IsEmpty() // => true
mset.Diff(set).Equal(sets.Singleton(0)) // => true
set.DiffSymmetric(mset).Equal(sets.Singleton(0)) // => true

cset := mset.Clone()
cset.Delete(789)
cset.Equal(sets.Hash(0, 123, 456)) // => true
cset.Clear()
cset.IsEmpty() // => true
mset.Equal(sets.Hash(0, 123, 456, 789)) // => true

mapped := sets.Map[int, string](set, func(e int) string { return strconv.FormatInt(int64(e), 10) })
mapped.Equal(sets.Hash("123", "456", "789")) // => true

sets.Reduce(set, func(acc uint, e int) uint { return acc + uint(e) }) // => 1368

sets.Min(set) // => 123
sets.Max(set) // => 789
sets.SortedSlice(set) // => [123 456 789]
sets.SortedJoinInt(set, ",") // => "123,456,789"

There's many more functions available to explore!

Issues

If you have any problems or would like to see changes currently in development you can do so here.

Contributors

If you want to contribute, you're a legend! Information on how you can do so can be found in CONTRIBUTING.md. We want your suggestions and pull requests!

A list of contributors can be found in AUTHORS.md.

License

Copyright © 2023 neocotic

See LICENSE.md for more information on our MIT license.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrJSONElementCount = errors.New("invalid number of elements unmarshalled from json")

ErrJSONElementCount is returned by a fixed-size Set implementation of json.Unmarshaler when the number of unmarshalled elements do not meet the requirements of the Set.

Functions

func Asc

func Asc[E constraints.Ordered](x, y E) bool

Asc is a convenient generic less function sorts in ascending order.

func Desc

func Desc[E constraints.Ordered](x, y E) bool

Desc is a convenient generic less function sorts in descending order.

func Equal

func Equal[E comparable](set Set[E], others ...Set[E]) bool

Equal is a convenient shorthand for Set.Equal where the Set can be compared against one or more other Set.

If the Set is nil it is treated as having no elements and the same logic applies to the others. To clarify; this means that a nil Set is equal to a non-nil Set that contains no elements.

func Group

func Group[E comparable, G comparable](set Set[E], grouper func(element E) G) map[G]Set[E]

Group returns a map containing the elements within the Set grouped using the grouper function.

The mapped struct implementations of Set are always immutable.

If the Set is nil, Group returns nil.

func JoinBool

func JoinBool[E ~bool](set Set[E], sep string) string

JoinBool is a convenient shorthand for Set.Join where the generic type is a bool, replacing the need for a convert function to be provided for casting each element to a string with strconv.FormatBool.

If the Set is nil, JoinBool returns an empty string.

func JoinComplex128

func JoinComplex128[E ~complex128](set Set[E], sep string, opts ...JoinComplexOption) string

JoinComplex128 is a convenient shorthand for Set.Join where the generic type is a complex128, replacing the need for a convert function to be provided for casting each element to a string with strconv.FormatComplex which can be controlled by passing options.

By default, the elements are formatted the 'f' (-ddd.dddd, no exponent) format with the smallest number of digits necessary such that strconv.ParseComplex will return the complex128 element exactly.

If the Set is nil, JoinComplex128 returns an empty string.

func JoinComplex64

func JoinComplex64[E ~complex64](set Set[E], sep string, opts ...JoinComplexOption) string

JoinComplex64 is a convenient shorthand for Set.Join where the generic type is a complex64, replacing the need for a convert function to be provided for casting each element to a string with strconv.FormatComplex which can be controlled by passing options.

By default, the elements are formatted the 'f' (-ddd.dddd, no exponent) format with the smallest number of digits necessary such that strconv.ParseComplex will return the complex64 element exactly.

If the Set is nil, JoinComplex64 returns an empty string.

func JoinFloat32

func JoinFloat32[E ~float32](set Set[E], sep string, opts ...JoinFloatOption) string

JoinFloat32 is a convenient shorthand for Set.Join where the generic type is a float32, replacing the need for a convert function to be provided for casting each element to a string with strconv.FormatFloat which can be controlled by passing options (excluding sorting options).

By default, the elements are formatted the 'f' (-ddd.dddd, no exponent) format with the smallest number of digits necessary such that strconv.ParseFloat will return the float32 element exactly.

If the Set is nil, JoinFloat32 returns an empty string.

func JoinFloat64

func JoinFloat64[E ~float64](set Set[E], sep string, opts ...JoinFloatOption) string

JoinFloat64 is a convenient shorthand for Set.Join where the generic type is a float64, replacing the need for a convert function to be provided for casting each element to a string with strconv.FormatFloat which can be controlled by passing options (excluding sorting options).

By default, the elements are formatted the 'f' (-ddd.dddd, no exponent) format with the smallest number of digits necessary such that strconv.ParseFloat will return the float64 element exactly.

If the Set is nil, JoinFloat64 returns an empty string.

func JoinInt

func JoinInt[E constraints.Signed](set Set[E], sep string, opts ...JoinIntOption) string

JoinInt is a convenient shorthand for Set.Join where the generic type is a signed integer, replacing the need for a convert function to be provided for casting each element to a string with strconv.FormatInt which can be controlled by passing options (excluding sorting options).

By default, the elements are formatted using base-10.

If the Set is nil, JoinInt returns an empty string.

func JoinRune

func JoinRune[E ~rune](set Set[E], sep string) string

JoinRune is a convenient shorthand for Set.Join where the generic type is a rune, removing the need for a convert function to be provided for casting each element to a string (excluding sorting options).

If the Set is nil, JoinRune returns an empty string.

func JoinString

func JoinString[E ~string](set Set[E], sep string) string

JoinString is a convenient shorthand for Set.Join where the generic type is a string, removing the need for a convert function to be provided for casting each element to a string.

If the Set is nil, JoinString returns an empty string.

func JoinUint

func JoinUint[E constraints.Unsigned](set Set[E], sep string, opts ...JoinUintOption) string

JoinUint is a convenient shorthand for Set.Join where the generic type is an unsigned integer, replacing the need for a convert function to be provided for casting each element to a string with strconv.FormatUint which can be controlled by passing options (excluding sorting options).

By default, the elements are formatted using base-10.

If the Set is nil, JoinUint returns an empty string.

func Max

func Max[E constraints.Ordered](set Set[E]) (E, bool)

Max is a convenient shorthand for Set.Max where the generic type is ordered, removing the need for a less function to be provided to control sorting.

If the Set is nil, Max returns the zero value for E and false.

func Min

func Min[E constraints.Ordered](set Set[E]) (E, bool)

Min is a convenient shorthand for Set.Min where the generic type is ordered, removing the need for a less function to be provided to control sorting.

If the Set is nil, Min returns the zero value for E and false.

func Reduce

func Reduce[E comparable, R any](set Set[E], reducer func(acc R, element E) R, initValue ...R) R

Reduce returns the final result of running the reducer function across all elements within the Set as a single value.

Optionally, an initial value can be specified. Otherwise, the zero value of R is used.

If the Set is nil, Reduce returns initial value or the zero value of R if not specified.

func SortedJoinFloat32

func SortedJoinFloat32[E ~float32](set Set[E], sep string, opts ...JoinFloatOption) string

SortedJoinFloat32 is a convenient shorthand for Set.Join where the generic type is a float32, removing the need for a less function to be provided for sorting elements and replacing the need for a convert function to be provided for casting each element to a string with strconv.FormatFloat which can be controlled by passing options.

By default, the elements are formatted the 'f' (-ddd.dddd, no exponent) format with the smallest number of digits necessary such that strconv.ParseFloat will return the float32 element exactly.

If the Set is nil, SortedJoinFloat32 returns an empty string.

func SortedJoinFloat64

func SortedJoinFloat64[E ~float64](set Set[E], sep string, opts ...JoinFloatOption) string

SortedJoinFloat64 is a convenient shorthand for Set.Join where the generic type is a float64, removing the need for a less function to be provided for sorting elements and replacing the need for a convert function to be provided for casting each element to a string with strconv.FormatFloat which can be controlled by passing options.

By default, the elements are formatted the 'f' (-ddd.dddd, no exponent) format with the smallest number of digits necessary such that strconv.ParseFloat will return the float64 element exactly.

If the Set is nil, SortedJoinFloat64 returns an empty string.

func SortedJoinInt

func SortedJoinInt[E constraints.Signed](set Set[E], sep string, opts ...JoinIntOption) string

SortedJoinInt is a convenient shorthand for Set.Join where the generic type is a signed integer, removing the need for a less function to be provided for sorting elements and replacing the need for a convert function to be provided for casting each element to a string with strconv.FormatInt which can be controlled by passing options.

By default, the elements are formatted using base-10.

If the Set is nil, SortedJoinInt returns an empty string.

func SortedJoinRune

func SortedJoinRune[E ~rune](set Set[E], sep string, opts ...SortedJoinRuneOption) string

SortedJoinRune is a convenient shorthand for Set.SortedJoin where the generic type is a rune, removing the need for less and convert functions to be provided for sorting elements and then casting them into a string which can be controlled by passing options.

If the Set is nil, SortedJoinRune returns an empty string.

func SortedJoinString

func SortedJoinString[E ~string](set Set[E], sep string, opts ...SortedJoinStringOption) string

SortedJoinString is a convenient shorthand for Set.SortedJoin where the generic type is a string, removing the need for less and convert functions to be provided for sorting elements and then casting them into a string which can be controlled by passing options.

If the Set is nil, SortedJoinString returns an empty string.

func SortedJoinUint

func SortedJoinUint[E constraints.Unsigned](set Set[E], sep string, opts ...JoinUintOption) string

SortedJoinUint is a convenient shorthand for Set.Join where the generic type is an unsigned integer, removing the need for a less function to be provided for sorting elements and replacing the need for a convert function to be provided for casting each element to a string with strconv.FormatUint which can be controlled by passing options.

By default, the elements are formatted using base-10.

If the Set is nil, SortedJoinUint returns an empty string.

func SortedSlice

func SortedSlice[E constraints.Ordered](set Set[E], less ...func(x, y E) bool) []E

SortedSlice is a convenient shorthand for Set.SortedSlice where the generic type is ordered, removing the need for a less function to be provided to control sorting. However, a less function can still be passed optionally for more granular control over sorting.

If the Set is nil, SortedSlice returns nil.

func TryReduce

func TryReduce[E comparable, T any](set Set[E], reducer func(acc T, element E) (T, error), initValue ...T) (T, error)

TryReduce returns the final result of running the reducer function across all elements within the Set as a single value, which may return an error should an element fail to be reduced.

Optionally, an initial value can be specified. Otherwise, the zero value of T is used.

If the Set is nil, TryReduce returns initial value or the zero value of T if not specified.

Types

type EmptySet

type EmptySet[E comparable] struct{}

EmptySet is an immutable implementation of Set that contains no data.

As EmptySet is immutable it is safe for concurrent use by multiple goroutines without additional locking or coordination.

func Empty

func Empty[E comparable]() *EmptySet[E]

Empty returns an immutable EmptySet struct that implements Set containing no data.

As Empty returns an immutable struct it is safe for concurrent use by multiple goroutines without additional locking or coordination.

func EmptyFromJSON

func EmptyFromJSON[E comparable](data []byte) (*EmptySet[E], error)

EmptyFromJSON returns an immutable EmptySet struct that implements Set containing no data parsed from the JSON-encoded data provided.

As EmptyFromJSON returns an immutable struct it is safe for concurrent use by multiple goroutines without additional locking or coordination.

As EmptySet cannot contain any data, this function simply provides consistency with other Set implementations while also offering validation of sorts. That is; it will return an error if the JSON data does not form an empty array.

func (*EmptySet[E]) Clone

func (s *EmptySet[E]) Clone() Set[E]

Clone returns a clone of the EmptySet.

If the EmptySet is nil, EmptySet.Clone returns nil.

func (*EmptySet[E]) Contains

func (s *EmptySet[E]) Contains(_ E) bool

Contains always returns false to conform with Set.Contains.

func (*EmptySet[E]) Diff

func (s *EmptySet[E]) Diff(_ Set[E]) Set[E]

Diff returns a new EmptySet struct to conform with Set.Diff.

If the EmptySet is nil, EmptySet.Diff returns nil.

func (*EmptySet[E]) DiffSymmetric

func (s *EmptySet[E]) DiffSymmetric(other Set[E]) Set[E]

DiffSymmetric returns an immutable clone of another Set to conform with Set.DiffSymmetric.

If the EmptySet is nil, EmptySet.DiffSymmetric returns nil.

func (*EmptySet[E]) Equal

func (s *EmptySet[E]) Equal(other Set[E]) bool

Equal returns whether the other Set also contains no elements.

If the EmptySet is nil it is treated as having no elements and the same logic applies to the other Set. To clarify; this means that a nil Set is equal to a non-nil Set that contains no elements.

func (*EmptySet[E]) Every

func (s *EmptySet[E]) Every(_ func(element E) bool) bool

Every always returns false to conform with Set.Every.

func (*EmptySet[E]) Filter

func (s *EmptySet[E]) Filter(_ func(element E) bool) Set[E]

Filter returns a new EmptySet struct to conform with Set.Filter.

If the EmptySet is nil, EmptySet.Filter returns nil.

func (*EmptySet[E]) Find

func (s *EmptySet[E]) Find(_ func(element E) bool) (E, bool)

Find always returns the zero value for E and false to conform with Set.Find.

func (*EmptySet[E]) Immutable

func (s *EmptySet[E]) Immutable() Set[E]

Immutable returns a reference to itself to conform with Set.Immutable.

If the EmptySet is nil, EmptySet.Immutable returns nil.

func (*EmptySet[E]) Intersection

func (s *EmptySet[E]) Intersection(_ Set[E]) Set[E]

Intersection returns a new EmptySet struct to conform with Set.Intersection.

If the EmptySet is nil, EmptySet.Intersection returns nil.

func (*EmptySet[E]) IsEmpty

func (s *EmptySet[E]) IsEmpty() bool

IsEmpty always returns true to conform with Set.IsEmpty.

func (*EmptySet[E]) IsMutable

func (s *EmptySet[E]) IsMutable() bool

IsMutable always returns false to conform with Set.IsMutable.

func (*EmptySet[E]) Join

func (s *EmptySet[E]) Join(_ string, _ func(element E) string) string

Join always returns an empty string to conform with Set.Join.

func (*EmptySet[E]) Len

func (s *EmptySet[E]) Len() int

Len always returns zero to conform with Set.Len.

func (*EmptySet[E]) MarshalJSON

func (s *EmptySet[E]) MarshalJSON() ([]byte, error)

func (*EmptySet[E]) Max

func (s *EmptySet[E]) Max(_ func(x, y E) bool) (E, bool)

Max always returns the zero value for E and false to conform with Set.Max.

func (*EmptySet[E]) Min

func (s *EmptySet[E]) Min(_ func(x, y E) bool) (E, bool)

Min always returns the zero value for E and false to conform with Set.Min.

func (*EmptySet[E]) Mutable

func (s *EmptySet[E]) Mutable() MutableSet[E]

Mutable returns a mutable clone of the EmptySet.

If the EmptySet is nil, EmptySet.Mutable returns nil.

func (*EmptySet[E]) None

func (s *EmptySet[E]) None(_ func(element E) bool) bool

None always returns true to conform with Set.None.

func (*EmptySet[E]) Range

func (s *EmptySet[E]) Range(_ func(element E) bool)

Range does nothing to conform with Set.Range.

func (*EmptySet[E]) Slice

func (s *EmptySet[E]) Slice() []E

Slice returns an empty slice to conform with Set.Slice.

If the EmptySet is nil, EmptySet.Slice returns nil.

func (*EmptySet[E]) Some

func (s *EmptySet[E]) Some(_ func(element E) bool) bool

Some always returns false to conform with Set.Some.

func (*EmptySet[E]) SortedJoin

func (s *EmptySet[E]) SortedJoin(_ string, _ func(element E) string, _ func(x, y E) bool) string

SortedJoin always returns an empty string to conform with Set.SortedJoin.

func (*EmptySet[E]) SortedSlice

func (s *EmptySet[E]) SortedSlice(_ func(x, y E) bool) []E

SortedSlice returns an empty slice to conform with Set.SortedSlice.

If the EmptySet is nil, EmptySet.SortedSlice returns nil.

func (*EmptySet[E]) String

func (s *EmptySet[E]) String() string

func (*EmptySet[E]) TryRange

func (s *EmptySet[E]) TryRange(_ func(element E) error) error

TryRange does nothing and returns nil to conform with Set.TryRange.

func (*EmptySet[E]) Union

func (s *EmptySet[E]) Union(other Set[E]) Set[E]

Union returns a new immutable Set containing a union of the EmptySet with another Set.

If the EmptySet and the other Set are both nil, EmptySet.Union returns nil.

func (*EmptySet[E]) UnmarshalJSON

func (s *EmptySet[E]) UnmarshalJSON(data []byte) error

type HashSet

type HashSet[E comparable] struct {
	// contains filtered or unexported fields
}

HashSet is an immutable implementation of Set that contains a unique data set.

As HashSet is immutable it is safe for concurrent use by multiple goroutines without additional locking or coordination.

The exception to its immutability is when passed to json.Unmarshal, however, this has been implemented in a way that is safe for concurrent use. That said; HashSet only implements json.Unmarshaler for the purpose of being able to have a HashSet field value on a struct being unmarshalled. It's recommended to unmarshal JSON into a HashSet using HashFromJSON as JSON is typically only unmarshalled into a struct once.

func Hash

func Hash[E comparable](elements ...E) *HashSet[E]

Hash returns an immutable HashSet struct that implements Set containing each unique element provided.

As Hash returns an immutable struct it is safe for concurrent use by multiple goroutines without additional locking or coordination.

The exception to its immutability is when passed to json.Unmarshal, however, this has been implemented in a way that is safe for concurrent use. The exception to its immutability is when passed to json.Unmarshal, however, this has been implemented in a way that is safe for concurrent use. That said; HashSet only implements json.Unmarshaler for the purpose of being able to have a HashSet field value on a struct being unmarshalled. It's recommended to unmarshal JSON into a HashSet using HashFromJSON as JSON is typically only unmarshalled into a struct once.

func HashFromJSON

func HashFromJSON[E comparable](data []byte) (*HashSet[E], error)

HashFromJSON returns an immutable HashSet struct that implements Set containing each unique element parsed from the JSON-encoded data provided.

As HashFromJSON returns an immutable struct it is safe for concurrent use by multiple goroutines without additional locking or coordination.

The exception to its immutability is when passed to json.Unmarshal, however, this has been implemented in a way that is safe for concurrent use and, as JSON is typically only unmarshalled into a struct once, it's unlikely that this needs to be called on the returned HashSet again after calling this function.

func HashFromSlice

func HashFromSlice[E comparable](elements []E) *HashSet[E]

HashFromSlice returns an immutable HashSet struct that implements Set containing each unique element from the slice provided.

As HashFromSlice returns an immutable struct it is safe for concurrent use by multiple goroutines without additional locking or coordination.

The exception to its immutability is when passed to json.Unmarshal, however, this has been implemented in a way that is safe for concurrent use.

func (*HashSet[E]) Clone

func (s *HashSet[E]) Clone() Set[E]

Clone returns a clone of the HashSet.

If the HashSet is nil, HashSet.Clone returns nil.

func (*HashSet[E]) Contains

func (s *HashSet[E]) Contains(element E) bool

Contains returns whether the HashSet contains the element.

If the HashSet is nil, HashSet.Contains returns false.

func (*HashSet[E]) Diff

func (s *HashSet[E]) Diff(other Set[E]) Set[E]

Diff returns a new HashSet struct containing only elements of the HashSet that do not exist in another Set.

If the HashSet is nil, HashSet.Diff returns nil.

func (*HashSet[E]) DiffSymmetric

func (s *HashSet[E]) DiffSymmetric(other Set[E]) Set[E]

DiffSymmetric returns a new HashSet struct containing elements that exist within the HashSet or another Set, but not both.

If the HashSet is nil, HashSet.DiffSymmetric returns nil.

func (*HashSet[E]) Equal

func (s *HashSet[E]) Equal(other Set[E]) bool

Equal returns whether the HashSet contains the exact same elements as another Set.

If the HashSet is nil it is treated as having no elements and the same logic applies to the other Set. To clarify; this means that a nil Set is equal to a non-nil Set that contains no elements.

func (*HashSet[E]) Every

func (s *HashSet[E]) Every(predicate func(element E) bool) bool

Every returns whether the HashSet contains elements that all match the predicate function.

If the HashSet is nil, HashSet.Every returns false.

func (*HashSet[E]) Filter

func (s *HashSet[E]) Filter(filter func(element E) bool) Set[E]

Filter returns a new HashSet struct containing only elements of the HashSet that match the filter function.

If the HashSet is nil, HashSet.Filter returns nil.

func (*HashSet[E]) Find

func (s *HashSet[E]) Find(search func(element E) bool) (E, bool)

Find returns an element within the HashSet that matches the search function as well as an indication of whether a match was found.

Iteration order is not guaranteed to be consistent so results may vary.

If the HashSet is nil, HashSet.Find returns the zero value for E and false.

func (*HashSet[E]) Immutable

func (s *HashSet[E]) Immutable() Set[E]

Immutable returns a reference to itself to conform with Set.Immutable.

If the HashSet is nil, HashSet.Immutable returns nil.

func (*HashSet[E]) Intersection

func (s *HashSet[E]) Intersection(other Set[E]) Set[E]

Intersection returns a new HashSet struct containing only elements of the HashSet that also exist in another Set.

If the HashSet is nil, HashSet.Intersection returns nil.

func (*HashSet[E]) IsEmpty

func (s *HashSet[E]) IsEmpty() bool

IsEmpty returns whether the HashSet contains no elements.

If the HashSet is nil, HashSet.IsEmpty returns true.

func (*HashSet[E]) IsMutable

func (s *HashSet[E]) IsMutable() bool

IsMutable always returns false to conform with Set.IsMutable.

func (*HashSet[E]) Join

func (s *HashSet[E]) Join(sep string, convert func(element E) string) string

Join converts the elements within the HashSet to strings which are then concatenated to create a single string, placing sep between the converted elements in the resulting string.

The order of elements within the resulting string is not guaranteed to be consistent. HashSet.SortedJoin should be used instead for such cases where consistent ordering is required.

If the HashSet is nil, HashSet.Join returns an empty string.

func (*HashSet[E]) Len

func (s *HashSet[E]) Len() int

Len returns the number of elements within the HashSet.

If the HashSet is nil, HashSet.Len returns zero.

func (*HashSet[E]) MarshalJSON

func (s *HashSet[E]) MarshalJSON() ([]byte, error)

func (*HashSet[E]) Max

func (s *HashSet[E]) Max(less func(x, y E) bool) (E, bool)

Max returns the maximum element within the HashSet using the provided less function.

If the HashSet is nil, HashSet.Max returns the zero value for E and false.

func (*HashSet[E]) Min

func (s *HashSet[E]) Min(less func(x, y E) bool) (E, bool)

Min returns the minimum element within the HashSet using the provided less function.

If the HashSet is nil, HashSet.Min returns the zero value for E and false.

func (*HashSet[E]) Mutable

func (s *HashSet[E]) Mutable() MutableSet[E]

Mutable returns a mutable clone of the HashSet.

If the HashSet is nil, HashSet.Mutable returns nil.

func (*HashSet[E]) None

func (s *HashSet[E]) None(predicate func(element E) bool) bool

None returns whether the HashSet contains no elements that match the predicate function.

If the HashSet is nil, HashSet.None returns true.

func (*HashSet[E]) Range

func (s *HashSet[E]) Range(iter func(element E) bool)

Range calls the iter function with each element within the HashSet but will stop early whenever the iter function returns true.

Iteration order is not guaranteed to be consistent.

If the HashSet is nil, HashSet.Range is a no-op.

func (*HashSet[E]) Slice

func (s *HashSet[E]) Slice() []E

Slice returns a slice containing all elements of the HashSet.

The order of elements within the resulting slice is not guaranteed to be consistent. HashSet.SortedSlice should be used instead for such cases where consistent ordering is required.

If the HashSet is nil, HashSet.Slice returns nil.

func (*HashSet[E]) Some

func (s *HashSet[E]) Some(predicate func(element E) bool) bool

Some returns whether the HashSet contains any element that matches the predicate function.

If the HashSet is nil, HashSet.Some returns false.

func (*HashSet[E]) SortedJoin

func (s *HashSet[E]) SortedJoin(sep string, convert func(element E) string, less func(x, y E) bool) string

SortedJoin sorts the elements within the HashSet using the provided less function and then converts those elements into strings which are then joined using the specified separator to create the resulting string.

If the HashSet is nil, HashSet.SortedJoin returns an empty string.

func (*HashSet[E]) SortedSlice

func (s *HashSet[E]) SortedSlice(less func(x, y E) bool) []E

SortedSlice returns a slice containing all elements of the HashSet sorted using the provided less function.

If the HashSet is nil, HashSet.SortedSlice returns nil.

func (*HashSet[E]) String

func (s *HashSet[E]) String() string

func (*HashSet[E]) TryRange

func (s *HashSet[E]) TryRange(iter func(element E) error) error

TryRange calls the iter function with each element within the HashSet but will stop early whenever the iter function returns an error.

Iteration order is not guaranteed to be consistent.

If the HashSet is nil, HashSet.TryRange is a no-op.

func (*HashSet[E]) Union

func (s *HashSet[E]) Union(other Set[E]) Set[E]

Union returns a new HashSet containing a union of the HashSet with another Set.

If the HashSet and the other Set are both nil, HashSet.Union returns nil.

func (*HashSet[E]) UnmarshalJSON

func (s *HashSet[E]) UnmarshalJSON(data []byte) error

type JoinComplexOption

type JoinComplexOption func(opts *joinComplexOptions)

JoinComplexOption allows control over the conversion of complex64/complex128 elements into strings when calling JoinComplex64 or JoinComplex128 respectively.

func WithComplexFormat

func WithComplexFormat(format byte) JoinComplexOption

WithComplexFormat controls the format in which the complex64/complex128 element is formatted into a string.

By default, the 'f' (-ddd.dddd, no exponent) format is used.

func WithComplexPrecision

func WithComplexPrecision(precision int) JoinComplexOption

WithComplexPrecision controls the precision to which the complex64/complex128 element is formatted into a string.

By default, the smallest number of digits necessary such that strconv.ParseComplex will return the complex64/complex128 element exactly.

type JoinFloatOption

type JoinFloatOption func(opts *joinFloatOptions)

JoinFloatOption allows control over the conversion of float32/float64 elements into strings when calling JoinFloat64 or SortedJoinFloat64 or the 32-bit equivalents. Sorting is also controllable for the latter functions.

func WithFloatFormat

func WithFloatFormat(format byte) JoinFloatOption

WithFloatFormat controls the format in which the float32/float64 element is formatted into a string.

By default, the 'f' (-ddd.dddd, no exponent) format is used.

func WithFloatPrecision

func WithFloatPrecision(precision int) JoinFloatOption

WithFloatPrecision controls the precision to which the float32/float64 element is formatted into a string.

By default, the smallest number of digits necessary such that strconv.ParseFloat will return the float32/float64 element exactly.

func WithFloatSorting

func WithFloatSorting(less func(x, y float64) bool) JoinFloatOption

WithFloatSorting controls the sorting of float32/float64 elements.

By default, float32/float64 elements are sorted in ascending order.

func WithFloatSortingAsc

func WithFloatSortingAsc() JoinFloatOption

WithFloatSortingAsc controls the sorting of float32/float64 elements to use ascending ordering.

This is the default ordering for float32/float64 elements.

func WithFloatSortingDesc

func WithFloatSortingDesc() JoinFloatOption

WithFloatSortingDesc controls the sorting of float32/float64 elements to use descending ordering.

By default, float32/float64 elements are sorted in ascending order.

type JoinIntOption

type JoinIntOption func(opts *joinIntOptions)

JoinIntOption allows control over the conversion of signed integer elements into strings when calling JoinInt or SortedJoinInt. Sorting is also controllable for the latter functions.

func WithIntBase

func WithIntBase(base int) JoinIntOption

WithIntBase controls the base in which the signed integer element is formatted into a string.

By default, base-10 is used.

func WithIntSorting

func WithIntSorting(less func(x, y int64) bool) JoinIntOption

WithIntSorting controls the sorting of signed integer elements.

By default, signed integer elements are sorted in ascending order.

func WithIntSortingAsc

func WithIntSortingAsc() JoinIntOption

WithIntSortingAsc controls the sorting of signed integer elements to use ascending ordering.

This is the default ordering for signed integer elements.

func WithIntSortingDesc

func WithIntSortingDesc() JoinIntOption

WithIntSortingDesc controls the sorting of signed integer elements to use descending ordering.

By default, signed integer elements are sorted in ascending order.

type JoinUintOption

type JoinUintOption func(opts *joinUintOptions)

JoinUintOption allows control over the conversion of unsigned integer elements into strings when calling JoinUint or SortedJoinUint. Sorting is also controllable for the latter functions.

func WithUintBase

func WithUintBase(base int) JoinUintOption

WithUintBase controls the base in which the unsigned integer element is formatted into a string.

By default, base-10 is used.

func WithUintSorting

func WithUintSorting(less func(x, y uint64) bool) JoinUintOption

WithUintSorting controls the sorting of unsigned integer elements.

By default, unsigned integer elements are sorted in ascending order.

func WithUintSortingAsc

func WithUintSortingAsc() JoinUintOption

WithUintSortingAsc controls the sorting of unsigned integer elements to use ascending ordering.

This is the default ordering for unsigned integer elements.

func WithUintSortingDesc

func WithUintSortingDesc() JoinUintOption

WithUintSortingDesc controls the sorting of unsigned integer elements to use descending ordering.

By default, unsigned integer elements are sorted in ascending order.

type MutableHashSet

type MutableHashSet[E comparable] struct {
	// contains filtered or unexported fields
}

MutableHashSet is an implementation of MutableSet that contains a unique data set.

As MutableHash is mutable it is not safe for concurrent use by multiple goroutines. SyncHashSet should be used instead for such cases where mutability is required, otherwise HashSet for a simple immutable Set.

func MutableHash

func MutableHash[E comparable](elements ...E) *MutableHashSet[E]

MutableHash returns a MutableHashSet struct that implements MutableSet containing each unique element provided.

As MutableHash returns a mutable struct it is not safe for concurrent use by multiple goroutines. SyncHash should be used instead for such cases where mutability is required, otherwise Hash for a simple immutable Set.

func MutableHashFromJSON

func MutableHashFromJSON[E comparable](data []byte) (*MutableHashSet[E], error)

MutableHashFromJSON returns a MutableHashSet struct that implements MutableSet containing each unique element parsed from the JSON-encoded data provided.

As MutableHashFromJSON returns a mutable struct it is not safe for concurrent use by multiple goroutines. SyncHashFromJSON should be used instead for such cases where mutability is required, otherwise HashFromJSON for a simple immutable Set.

func MutableHashFromSlice

func MutableHashFromSlice[E comparable](elements []E) *MutableHashSet[E]

MutableHashFromSlice returns a MutableHashSet struct that implements MutableSet containing each unique element from the slice provided.

As MutableHashFromSlice returns a mutable struct it is not safe for concurrent use by multiple goroutines. SyncHashFromSlice should be used instead for such cases where mutability is required, otherwise HashFromSlice for a simple immutable Set.

func (*MutableHashSet[E]) Clear

func (s *MutableHashSet[E]) Clear() MutableSet[E]

Clear removes all elements from the MutableHashSet.

If the MutableHashSet is nil, MutableHashSet.Clear is a no-op.

A reference to the MutableHashSet is returned for method chaining.

func (*MutableHashSet[E]) Clone

func (s *MutableHashSet[E]) Clone() Set[E]

Clone returns a clone of the MutableHashSet.

If the MutableHashSet is nil, MutableHashSet.Clone returns nil.

func (*MutableHashSet[E]) Contains

func (s *MutableHashSet[E]) Contains(element E) bool

Contains returns whether the MutableHashSet contains the element.

If the MutableHashSet is nil, MutableHashSet.Contains returns false.

func (*MutableHashSet[E]) Delete

func (s *MutableHashSet[E]) Delete(element E, elements ...E) MutableSet[E]

Delete removes the element from the MutableHashSet as well as any additional elements specified.

If the MutableHashSet is nil, MutableHashSet.Delete is a no-op.

A reference to the MutableHashSet is returned for method chaining.

func (*MutableHashSet[E]) DeleteAll

func (s *MutableHashSet[E]) DeleteAll(elements Set[E]) MutableSet[E]

DeleteAll removes all elements in the specified Set from the MutableHashSet.

If the MutableHashSet is nil, MutableHashSet.DeleteAll is a no-op.

A reference to the MutableHashSet is returned for method chaining.

func (*MutableHashSet[E]) DeleteSlice

func (s *MutableHashSet[E]) DeleteSlice(elements []E) MutableSet[E]

DeleteSlice removes all elements in the specified slice from the MutableHashSet.

If the MutableHashSet is nil, MutableHashSet.DeleteSlice is a no-op.

A reference to the MutableHashSet is returned for method chaining.

func (*MutableHashSet[E]) DeleteWhere

func (s *MutableHashSet[E]) DeleteWhere(predicate func(element E) bool) MutableSet[E]

DeleteWhere removes all elements that match the predicate function from the MutableHashSet.

If the MutableHashSet is nil, MutableHashSet.DeleteWhere is a no-op.

A reference to the MutableHashSet is returned for method chaining.

func (*MutableHashSet[E]) Diff

func (s *MutableHashSet[E]) Diff(other Set[E]) Set[E]

Diff returns a new MutableHashSet struct containing only elements of the MutableHashSet that do not exist in another Set.

If the MutableHashSet is nil, MutableHashSet.Diff returns nil.

func (*MutableHashSet[E]) DiffSymmetric

func (s *MutableHashSet[E]) DiffSymmetric(other Set[E]) Set[E]

DiffSymmetric returns a new MutableHashSet struct containing elements that exist within the MutableHashSet or another Set, but not both.

If the MutableHashSet is nil, MutableHashSet.DiffSymmetric returns nil.

func (*MutableHashSet[E]) Equal

func (s *MutableHashSet[E]) Equal(other Set[E]) bool

Equal returns whether the MutableHashSet contains the exact same elements as another Set.

If the MutableHashSet is nil it is treated as having no elements and the same logic applies to the other Set. To clarify; this means that a nil Set is equal to a non-nil Set that contains no elements.

func (*MutableHashSet[E]) Every

func (s *MutableHashSet[E]) Every(predicate func(element E) bool) bool

Every returns whether the MutableHashSet contains elements that all match the predicate function.

If the MutableHashSet is nil, MutableHashSet.Every returns false.

func (*MutableHashSet[E]) Filter

func (s *MutableHashSet[E]) Filter(filter func(element E) bool) Set[E]

Filter returns a new MutableHashSet struct containing only elements of the MutableHashSet that match the filter function.

If the MutableHashSet is nil, MutableHashSet.Filter returns nil.

func (*MutableHashSet[E]) Find

func (s *MutableHashSet[E]) Find(search func(element E) bool) (E, bool)

Find returns an element within the MutableHashSet that matches the search function as well as an indication of whether a match was found.

Iteration order is not guaranteed to be consistent so results may vary.

If the MutableHashSet is nil, MutableHashSet.Find returns the zero value for E and false.

func (*MutableHashSet[E]) Immutable

func (s *MutableHashSet[E]) Immutable() Set[E]

Immutable returns an immutable clone of the MutableHashSet.

If the MutableHashSet is nil, MutableHashSet.Immutable returns nil.

func (*MutableHashSet[E]) Intersection

func (s *MutableHashSet[E]) Intersection(other Set[E]) Set[E]

Intersection returns a new MutableHashSet struct containing only elements of the MutableHashSet that also exist in another Set.

If the MutableHashSet is nil, MutableHashSet.Intersection returns nil.

func (*MutableHashSet[E]) IsEmpty

func (s *MutableHashSet[E]) IsEmpty() bool

IsEmpty returns whether the MutableHashSet contains no elements.

If the MutableHashSet is nil, MutableHashSet.IsEmpty returns true.

func (*MutableHashSet[E]) IsMutable

func (s *MutableHashSet[E]) IsMutable() bool

IsMutable always returns true to conform with Set.IsMutable.

func (*MutableHashSet[E]) Join

func (s *MutableHashSet[E]) Join(sep string, convert func(element E) string) string

Join converts the elements within the MutableHashSet to strings which are then concatenated to create a single string, placing sep between the converted elements in the resulting string.

The order of elements within the resulting string is not guaranteed to be consistent. MutableHashSet.SortedJoin should be used instead for such cases where consistent ordering is required.

If the MutableHashSet is nil, MutableHashSet.Join returns an empty string.

func (*MutableHashSet[E]) Len

func (s *MutableHashSet[E]) Len() int

Len returns the number of elements within the MutableHashSet.

If the MutableHashSet is nil, MutableHashSet.Len returns zero.

func (*MutableHashSet[E]) MarshalJSON

func (s *MutableHashSet[E]) MarshalJSON() ([]byte, error)

func (*MutableHashSet[E]) Max

func (s *MutableHashSet[E]) Max(less func(x, y E) bool) (E, bool)

Max returns the maximum element within the MutableHashSet using the provided less function.

If the MutableHashSet is nil, MutableHashSet.Max returns the zero value for E and false.

func (*MutableHashSet[E]) Min

func (s *MutableHashSet[E]) Min(less func(x, y E) bool) (E, bool)

Min returns the minimum element within the MutableHashSet using the provided less function.

If the MutableHashSet is nil, MutableHashSet.Min returns the zero value for E and false.

func (*MutableHashSet[E]) Mutable

func (s *MutableHashSet[E]) Mutable() MutableSet[E]

Mutable returns a reference to itself to conform with Set.Mutable.

If the MutableHashSet is nil, MutableHashSet.Mutable returns nil.

func (*MutableHashSet[E]) None

func (s *MutableHashSet[E]) None(predicate func(element E) bool) bool

None returns whether the MutableHashSet contains no elements that match the predicate function.

If the MutableHashSet is nil, MutableHashSet.None returns true.

func (*MutableHashSet[E]) Put

func (s *MutableHashSet[E]) Put(element E, elements ...E) MutableSet[E]

Put adds the element to the MutableHashSet as well as any additional elements specified. Nothing changes for elements that already exist within the MutableHashSet.

If the MutableHashSet is nil, MutableHashSet.Put is a no-op.

A reference to the MutableHashSet is returned for method chaining.

func (*MutableHashSet[E]) PutAll

func (s *MutableHashSet[E]) PutAll(elements Set[E]) MutableSet[E]

PutAll adds all elements in the specified Set to the MutableHashSet. Nothing changes for elements that already exist within the SyncHashSet.

If the MutableHashSet is nil, MutableHashSet.PutAll is a no-op.

A reference to the MutableHashSet is returned for method chaining.

func (*MutableHashSet[E]) PutSlice

func (s *MutableHashSet[E]) PutSlice(elements []E) MutableSet[E]

PutSlice adds all elements in the specified slice to the MutableHashSet. Nothing changes for elements that already exist within the MutableHashSet.

If the MutableHashSet is nil, MutableHashSet.PutSlice is a no-op.

A reference to the MutableHashSet is returned for method chaining.

func (*MutableHashSet[E]) Range

func (s *MutableHashSet[E]) Range(iter func(element E) bool)

Range calls the iter function with each element within the MutableHashSet but will stop early whenever the iter function returns true.

Iteration order is not guaranteed to be consistent.

If the MutableHashSet is nil, MutableHashSet.Range is a no-op.

func (*MutableHashSet[E]) Retain

func (s *MutableHashSet[E]) Retain(element E, elements ...E) MutableSet[E]

Retain removes all elements from the MutableHashSet except the element(s) specified.

If the MutableHashSet is nil, MutableHashSet.Retain is a no-op.

A reference to the MutableHashSet is returned for method chaining.

func (*MutableHashSet[E]) RetainAll

func (s *MutableHashSet[E]) RetainAll(elements Set[E]) MutableSet[E]

RetainAll removes all elements from the MutableHashSet except those in the specified Set.

If the MutableHashSet is nil, MutableHashSet.RetainAll is a no-op.

A reference to the MutableHashSet is returned for method chaining.

func (*MutableHashSet[E]) RetainSlice

func (s *MutableHashSet[E]) RetainSlice(elements []E) MutableSet[E]

RetainSlice removes all elements from the MutableHashSet except those in the specified slice.

If the MutableHashSet is nil, MutableHashSet.RetainSlice is a no-op.

A reference to the MutableHashSet is returned for method chaining.

func (*MutableHashSet[E]) RetainWhere

func (s *MutableHashSet[E]) RetainWhere(predicate func(element E) bool) MutableSet[E]

RetainWhere removes all elements except those that match the predicate function from the MutableHashSet.

If the MutableHashSet is nil, MutableHashSet.RetainWhere is a no-op.

A reference to the MutableHashSet is returned for method chaining.

func (*MutableHashSet[E]) Slice

func (s *MutableHashSet[E]) Slice() []E

Slice returns a slice containing all elements of the MutableHashSet.

The order of elements within the resulting slice is not guaranteed to be consistent. MutableHashSet.SortedSlice should be used instead for such cases where consistent ordering is required.

If the MutableHashSet is nil, MutableHashSet.Slice returns nil.

func (*MutableHashSet[E]) Some

func (s *MutableHashSet[E]) Some(predicate func(element E) bool) bool

Some returns whether the MutableHashSet contains any element that matches the predicate function.

If the MutableHashSet is nil, MutableHashSet.Some returns false.

func (*MutableHashSet[E]) SortedJoin

func (s *MutableHashSet[E]) SortedJoin(sep string, convert func(element E) string, less func(x, y E) bool) string

SortedJoin sorts the elements within the MutableHashSet using the provided less function and then converts those elements into strings which are then joined using the specified separator to create the resulting string.

If the MutableHashSet is nil, MutableHashSet.SortedJoin returns an empty string.

func (*MutableHashSet[E]) SortedSlice

func (s *MutableHashSet[E]) SortedSlice(less func(x, y E) bool) []E

SortedSlice returns a slice containing all elements of the MutableHashSet sorted using the provided less function.

If the MutableHashSet is nil, MutableHashSet.SortedSlice returns nil.

func (*MutableHashSet[E]) String

func (s *MutableHashSet[E]) String() string

func (*MutableHashSet[E]) TryRange

func (s *MutableHashSet[E]) TryRange(iter func(element E) error) error

TryRange calls the iter function with each element within the MutableHashSet but will stop early whenever the iter function returns an error.

Iteration order is not guaranteed to be consistent.

If the MutableHashSet is nil, MutableHashSet.TryRange is a no-op.

func (*MutableHashSet[E]) Union

func (s *MutableHashSet[E]) Union(other Set[E]) Set[E]

Union returns a new MutableHashSet containing a union of the MutableHashSet with another Set.

If the MutableHashSet and the other Set are both nil, MutableHashSet.Union returns nil.

func (*MutableHashSet[E]) UnmarshalJSON

func (s *MutableHashSet[E]) UnmarshalJSON(data []byte) error

type MutableSet

type MutableSet[E comparable] interface {
	// Clear removes all elements from the MutableSet.
	//
	// If the MutableSet is nil, MutableSet.Clear is a no-op.
	//
	// A reference to the MutableSet is returned for method chaining.
	Clear() MutableSet[E]
	// Delete removes the element from the MutableSet as well as any additional elements specified.
	//
	// If the MutableSet is nil, MutableSet.Delete is a no-op.
	//
	// A reference to the MutableSet is returned for method chaining.
	Delete(element E, elements ...E) MutableSet[E]
	// DeleteAll removes all elements in the specified Set from the MutableSet.
	//
	// If the MutableSet is nil, MutableSet.DeleteAll is a no-op.
	//
	// A reference to the MutableSet is returned for method chaining.
	DeleteAll(elements Set[E]) MutableSet[E]
	// DeleteSlice removes all elements in the specified slice from the MutableSet.
	//
	// If the MutableSet is nil, MutableSet.DeleteSlice is a no-op.
	//
	// A reference to the MutableSet is returned for method chaining.
	DeleteSlice(elements []E) MutableSet[E]
	// DeleteWhere removes all elements that match the predicate function from the MutableSet.
	//
	// If the MutableSet is nil, MutableSet.DeleteWhere is a no-op.
	//
	// A reference to the MutableSet is returned for method chaining.
	DeleteWhere(predicate func(element E) bool) MutableSet[E]
	// Put adds the element to the MutableSet as well as any additional elements specified. Nothing changes for
	// elements that already exist within the MutableSet.
	//
	// If the MutableSet is nil, MutableSet.Put is a no-op.
	//
	// A reference to the MutableSet is returned for method chaining.
	Put(element E, elements ...E) MutableSet[E]
	// PutAll adds all elements in the specified Set to the MutableSet. Nothing changes for elements that already
	// exist within the MutableSet.
	//
	// If the MutableSet is nil, MutableSet.PutAll is a no-op.
	//
	// A reference to the MutableSet is returned for method chaining.
	PutAll(elements Set[E]) MutableSet[E]
	// PutSlice adds all elements in the specified slice to the MutableSet. Nothing changes for elements that
	// already exist within the MutableSet.
	//
	// If the MutableSet is nil, MutableSet.PutSlice is a no-op.
	//
	// A reference to the MutableSet is returned for method chaining.
	PutSlice(elements []E) MutableSet[E]
	// Retain removes all elements from the MutableSet except the element(s) specified.
	//
	// If the MutableSet is nil, MutableSet.Retain is a no-op.
	//
	// A reference to the MutableSet is returned for method chaining.
	Retain(element E, elements ...E) MutableSet[E]
	// RetainAll removes all elements from the MutableSet except those in the specified Set.
	//
	// If the MutableSet is nil, MutableSet.RetainAll is a no-op.
	//
	// A reference to the MutableSet is returned for method chaining.
	RetainAll(elements Set[E]) MutableSet[E]
	// RetainSlice removes all elements from the MutableSet except those in the specified slice.
	//
	// If the MutableSet is nil, MutableSet.RetainSlice is a no-op.
	//
	// A reference to the MutableSet is returned for method chaining.
	RetainSlice(elements []E) MutableSet[E]
	// RetainWhere removes all elements except those that match the predicate function from the MutableSet.
	//
	// If the MutableSet is nil, MutableSet.RetainWhere is a no-op.
	//
	// A reference to the MutableSet is returned for method chaining.
	RetainWhere(predicate func(element E) bool) MutableSet[E]
	Set[E]
}

MutableSet represents a mutable Set.

type Set

type Set[E comparable] interface {
	// Clone returns a clone of the Set.
	//
	// The returned struct implementation of Set will always match that of the Set being cloned.
	//
	// If the Set is nil, Set.Clone returns nil.
	Clone() Set[E]
	// Contains returns whether the Set contains the element.
	//
	// If the Set is nil, Set.Contains returns false.
	Contains(element E) bool
	// Diff returns a new Set struct containing only elements of the Set that do not exist in another Set.
	//
	// The returned struct implementation of Set should match that of the Set, where possible, but must never differ
	// in mutability.
	//
	// If the Set is nil, Set.Diff returns nil.
	Diff(other Set[E]) Set[E]
	// DiffSymmetric returns a new Set struct containing elements that exist within the Set or another Set, but not
	// both.
	//
	// The returned struct implementation of Set should match that of the Set, where possible, but must never differ
	// in mutability.
	//
	// If the Set is nil, Set.DiffSymmetric returns nil.
	DiffSymmetric(other Set[E]) Set[E]
	// Equal returns whether the Set contains the exact same elements as another Set.
	//
	// If the Set is nil it is treated as having no elements and the same logic applies to the other Set. To
	// clarify; this means that a nil Set is equal to a non-nil Set that contains no elements.
	Equal(other Set[E]) bool
	// Every returns whether the Set contains elements that all match the predicate function.
	//
	// If the Set is nil, Set.Every returns false.
	Every(predicate func(element E) bool) bool
	// Filter returns a new Set struct containing only elements of the Set that match the filter function.
	//
	// The returned struct implementation of Set should match that of the Set being filtered, where possible, but
	// must never differ in mutability.
	//
	// If the Set is nil, Set.Filter returns nil.
	Filter(filter func(element E) bool) Set[E]
	// Find returns an element within the Set that matches the search function as well as an indication of whether a
	// match was found.
	//
	// Iteration order is not guaranteed to be consistent so results may vary.
	//
	// If the Set is nil, Set.Find returns the zero value for E and false.
	Find(search func(element E) bool) (E, bool)
	// Immutable returns an immutable version of the Set.
	//
	// The Set is returned if it is already immutable, otherwise an immutable clone is returned.
	//
	// If the Set is nil, Set.Immutable returns nil.
	Immutable() Set[E]
	// Intersection returns a new Set struct containing only elements of the Set that also exist in another Set.
	//
	// The returned struct implementation of Set should match that of the Set, where possible, but must never differ
	// in mutability.
	//
	// If the Set is nil, Set.Intersection returns nil.
	Intersection(other Set[E]) Set[E]
	// IsEmpty returns whether the Set contains no elements.
	//
	// If the Set is nil, Set.IsEmpty returns true.
	IsEmpty() bool
	// IsMutable returns whether the Set is mutable.
	IsMutable() bool
	// Join converts the elements within the Set to strings which are then concatenated to create a single string,
	// placing sep between the converted elements in the resulting string.
	//
	// The order of elements within the resulting string is not guaranteed to be consistent. Set.SortedJoin or
	// should be used instead for such cases where consistent ordering is required.
	//
	// If the Set is nil, Set.Join returns an empty string.
	Join(sep string, convert func(element E) string) string
	// Len returns the number of elements within the Set.
	//
	// If the Set is nil, Set.Len returns zero.
	Len() int
	// Max returns the maximum element within the Set using the provided less function.
	//
	// If the Set is nil, Set.Max returns the zero value for E and false.
	Max(less func(x, y E) bool) (E, bool)
	// Min returns the minimum element within the Set using the provided less function.
	//
	// If the Set is nil, Set.Min returns the zero value for E and false.
	Min(less func(x, y E) bool) (E, bool)
	// Mutable returns a mutable version of the Set.
	//
	// The Set is returned if it is already mutable, otherwise a mutable clone is returned.
	//
	// If the Set is nil, Set.Mutable returns nil.
	Mutable() MutableSet[E]
	// None returns whether the Set contains no elements that match the predicate function.
	//
	// If the Set is nil, Set.None returns true.
	None(predicate func(element E) bool) bool
	// Range calls the iter function with each element within the Set but will stop early whenever the iter function
	// returns true.
	//
	// Iteration order is not guaranteed to be consistent.
	//
	// If the Set is nil, Set.Range is a no-op.
	Range(iter func(element E) bool)
	// Slice returns a slice containing all elements of the Set.
	//
	// The order of elements within the resulting slice is not guaranteed to be consistent. Set.SortedSlice should
	// be used instead for such cases where consistent ordering is required.
	//
	// If the Set is nil, Set.Slice returns nil.
	Slice() []E
	// Some returns whether the Set contains any element that matches the predicate function.
	//
	// If the Set is nil, Set.Some returns false.
	Some(predicate func(element E) bool) bool
	// SortedJoin sorts the elements within the Set using the provided less function and then converts those
	// elements into strings which are then joined using the specified separator to create the resulting string.
	//
	// If the Set is nil, Set.SortedJoin returns an empty string.
	SortedJoin(sep string, convert func(element E) string, less func(x, y E) bool) string
	// SortedSlice returns a slice containing all elements of the Set sorted using the provided less function.
	//
	// If the Set is nil, Set.SortedSlice returns nil.
	SortedSlice(less func(x, y E) bool) []E
	// TryRange calls the iter function with each element within the Set but will stop early whenever the iter
	// function returns an error.
	//
	// Iteration order is not guaranteed to be consistent.
	//
	// If the Set is nil, Set.TryRange is a no-op.
	TryRange(iter func(element E) error) error
	// Union returns a new Set containing a union of the Set with another Set.
	//
	// The returned struct implementation of Set should match that of the Set, where possible, but must never
	// differ in mutability.
	//
	// If the Set and the other Set are both nil, Set.Union returns nil.
	Union(other Set[E]) Set[E]
}

Set represents a data set which contains only unique elements.

func Diff

func Diff[E comparable](set Set[E], others ...Set[E]) Set[E]

Diff returns a new Set struct containing only elements of the Set that do not exist in any other provided Set.

Unlike Set.Diff, the return struct implementation of Set is determined by important characteristics of the Set provided. That is; if the Set is mutable, then the returned struct implementation of Set will also be mutable. Otherwise, it will be immutable. Likewise for whether any Set is synchronized.

If the Set is nil, Diff returns nil.

func DiffSymmetric

func DiffSymmetric[E comparable](set Set[E], others ...Set[E]) Set[E]

DiffSymmetric returns a new Set struct containing elements that exist within the Set or any other Set, but not in more than one.

Unlike Set.DiffSymmetric, the return struct implementation of Set is determined by important characteristics of the Set provided. That is; if the Set is mutable, then the returned struct implementation of Set will also be mutable. Otherwise, it will be immutable. Likewise for whether any Set is synchronized.

If the Set is nil, DiffSymmetric returns nil.

func Intersection

func Intersection[E comparable](set Set[E], others ...Set[E]) Set[E]

Intersection returns a new Set struct containing only elements of the Set that also exist in any other provided Set.

Unlike Set.Intersection, the return struct implementation of Set is determined by important characteristics of the Set provided. That is; if the Set is mutable, then the returned struct implementation of Set will also be mutable. Otherwise, it will be immutable. Likewise for whether any Set is synchronized.

If the Set is nil, Intersection returns nil.

func Map

func Map[E comparable, T comparable](set Set[E], mapper func(element E) T) Set[T]

Map returns a new Set struct containing values converted from elements within the Set using the mapper function.

The returned struct implementation of Set should match that of the Set being mapped, where possible, but must never differ in mutability.

If the Set is nil, Map returns nil.

func TryMap

func TryMap[E comparable, T comparable](set Set[E], mapper func(element E) (T, error)) (Set[T], error)

TryMap returns a new Set struct containing values converted from elements within the Set using the mapper function, which may return an error should an element fail to be mapped.

The returned struct implementation of Set should match that of the Set being mapped, where possible, but must never differ in mutability.

If the Set is nil, TryMap returns nil.

func Union

func Union[E comparable](set Set[E], others ...Set[E]) Set[E]

Union returns a new Set containing a union of each Set.

Unlike Set.Union, the return struct implementation of Set is determined by important characteristics of each Set provided. That is; if any Set is mutable, then the returned struct implementation of Set will also be mutable. Otherwise, it will be immutable. Likewise for whether any Set is synchronized.

If each given Set is nil, Union returns nil.

type SingletonSet

type SingletonSet[E comparable] struct {
	// contains filtered or unexported fields
}

SingletonSet is an immutable implementation of Set that contains a single datum.

As SingletonSet is immutable it is safe for concurrent use by multiple goroutines without additional locking or coordination.

The exception to its immutability is when passed to json.Unmarshal, however, this has been implemented in a way that is safe for concurrent use. That said; SingletonSet only implements json.Unmarshaler for the purpose of being able to have a SingletonSet field value on a struct being unmarshalled. It's recommended to unmarshal JSON into a SingletonSet using SingletonFromJSON as JSON is typically only unmarshalled into a struct once.

func Singleton

func Singleton[E comparable](element E) *SingletonSet[E]

Singleton returns an immutable SingletonSet struct that implements Set containing a single datum.

As Singleton returns an immutable struct it is safe for concurrent use by multiple goroutines without additional locking or coordination.

The exception to its immutability is when passed to json.Unmarshal, however, this has been implemented in a way that is safe for concurrent use. That said; SingletonSet only implements json.Unmarshaler for the purpose of being able to have a SingletonSet field value on a struct being unmarshalled. It's recommended to unmarshal JSON into a SingletonSet using SingletonFromJSON as JSON is typically only unmarshalled into a struct once.

func SingletonFromJSON

func SingletonFromJSON[E comparable](data []byte) (*SingletonSet[E], error)

SingletonFromJSON returns an immutable SingletonSet struct that implements Set containing a single datum parsed from the JSON-encoded data provided.

As SingletonFromJSON returns an immutable struct it is safe for concurrent use by multiple goroutines without additional locking or coordination.

The exception to its immutability is when passed to json.Unmarshal, however, this has been implemented in a way that is safe for concurrent use and, as JSON is typically only unmarshalled into a struct once, it's unlikely that this needs to be called on the returned SingletonSet again after calling this function.

func (*SingletonSet[E]) Clone

func (s *SingletonSet[E]) Clone() Set[E]

Clone returns a clone of the SingletonSet.

If the SingletonSet is nil, SingletonSet.Clone returns nil.

func (*SingletonSet[E]) Contains

func (s *SingletonSet[E]) Contains(element E) bool

Contains returns whether the SingletonSet contains the element.

If the SingletonSet is nil, SingletonSet.Contains returns false.

func (*SingletonSet[E]) Diff

func (s *SingletonSet[E]) Diff(other Set[E]) Set[E]

Diff returns a new SingletonSet struct containing the element of the SingletonSet if it does not exist in another Set; otherwise an EmptySet.

If the SingletonSet is nil, SingletonSet.Diff returns nil.

func (*SingletonSet[E]) DiffSymmetric

func (s *SingletonSet[E]) DiffSymmetric(other Set[E]) Set[E]

DiffSymmetric returns a new HashSet struct containing elements that exist within the SingletonSet or another Set, but not both.

If the SingletonSet is nil, SingletonSet.DiffSymmetric returns nil.

func (*SingletonSet[E]) Equal

func (s *SingletonSet[E]) Equal(other Set[E]) bool

Equal returns whether the other Set also contains the same element.

If the SingletonSet is nil it is treated as having no elements and the same logic applies to the other Set. To clarify; this means that a nil Set is equal to a non-nil Set that contains no elements.

func (*SingletonSet[E]) Every

func (s *SingletonSet[E]) Every(predicate func(element E) bool) bool

Every returns whether the element within the SingletonSet matches the predicate function.

If the SingletonSet is nil, SingletonSet.Every returns false.

func (*SingletonSet[E]) Filter

func (s *SingletonSet[E]) Filter(filter func(element E) bool) Set[E]

Filter returns a clone of the SingletonSet if its element matches the filter function; otherwise an EmptySet.

If the SingletonSet is nil, SingletonSet.Filter returns nil.

func (*SingletonSet[E]) Find

func (s *SingletonSet[E]) Find(search func(element E) bool) (E, bool)

Find returns the element within the SingletonSet if it matches the search function as well as an indication of whether it was matched.

If the SingletonSet is nil, SingletonSet.Find returns the zero value for E and false.

func (*SingletonSet[E]) Immutable

func (s *SingletonSet[E]) Immutable() Set[E]

Immutable returns a reference to itself to conform with Set.Immutable.

If the SingletonSet is nil, SingletonSet.Immutable returns nil.

func (*SingletonSet[E]) Intersection

func (s *SingletonSet[E]) Intersection(other Set[E]) Set[E]

Intersection returns a clone of the SingletonSet if its element exists in another Set; otherwise an EmptySet.

If the SingletonSet is nil, SingletonSet.Intersection returns nil.

func (*SingletonSet[E]) IsEmpty

func (s *SingletonSet[E]) IsEmpty() bool

IsEmpty returns whether the SingletonSet is nil to conform with Set.IsEmpty.

func (*SingletonSet[E]) IsMutable

func (s *SingletonSet[E]) IsMutable() bool

IsMutable always returns false to conform with Set.IsMutable.

func (*SingletonSet[E]) Join

func (s *SingletonSet[E]) Join(_ string, convert func(element E) string) string

Join returns the element within the SingletonSet converted to a string to conform with Set.Join.

If the SingletonSet is nil, SingletonSet.Join returns an empty string.

func (*SingletonSet[E]) Len

func (s *SingletonSet[E]) Len() int

Len returns one if the SingletonSet is not nil; otherwise zero.

func (*SingletonSet[E]) MarshalJSON

func (s *SingletonSet[E]) MarshalJSON() ([]byte, error)

func (*SingletonSet[E]) Max

func (s *SingletonSet[E]) Max(_ func(x, y E) bool) (E, bool)

Max returns the element within the SingletonSet to conform with Set.Max.

If the SingletonSet is nil, SingletonSet.Max returns the zero value for E and false.

func (*SingletonSet[E]) Min

func (s *SingletonSet[E]) Min(_ func(x, y E) bool) (E, bool)

Min returns the element within the SingletonSet to conform with Set.Min.

If the SingletonSet is nil, SingletonSet.Min returns the zero value for E and false.

func (*SingletonSet[E]) Mutable

func (s *SingletonSet[E]) Mutable() MutableSet[E]

Mutable returns a mutable clone of the SingletonSet.

If the SingletonSet is nil, SingletonSet.Mutable returns nil.

func (*SingletonSet[E]) None

func (s *SingletonSet[E]) None(predicate func(element E) bool) bool

None returns whether the element within the SingletonSet does not match the predicate function.

If the SingletonSet is nil, SingletonSet.None returns true.

func (*SingletonSet[E]) Range

func (s *SingletonSet[E]) Range(iter func(element E) bool)

Range calls the iter function with the element within the SingletonSet.

If the SingletonSet is nil, SingletonSet.Range is a no-op.

func (*SingletonSet[E]) Slice

func (s *SingletonSet[E]) Slice() []E

Slice returns a slice containing the element within the SingletonSet.

If the SingletonSet is nil, SingletonSet.Slice returns nil.

func (*SingletonSet[E]) Some

func (s *SingletonSet[E]) Some(predicate func(element E) bool) bool

Some returns whether the element within the SingletonSet matches the predicate function.

If the SingletonSet is nil, SingletonSet.Some returns false.

func (*SingletonSet[E]) SortedJoin

func (s *SingletonSet[E]) SortedJoin(sep string, convert func(element E) string, _ func(x, y E) bool) string

SortedJoin returns the element within the SingletonSet converted to a string to conform with Set.SortedJoin.

If the SingletonSet is nil, SingletonSet.SortedJoin returns an empty string.

func (*SingletonSet[E]) SortedSlice

func (s *SingletonSet[E]) SortedSlice(_ func(x, y E) bool) []E

SortedSlice returns a slice containing the element within the SingletonSet to conform with Set.SortedSlice.

If the SingletonSet is nil, SingletonSet.SortedSlice returns nil.

func (*SingletonSet[E]) String

func (s *SingletonSet[E]) String() string

func (*SingletonSet[E]) TryRange

func (s *SingletonSet[E]) TryRange(iter func(element E) error) error

TryRange calls the iter function with the element within the SingletonSet, which may return an error.

If the SingletonSet is nil, SingletonSet.TryRange is a no-op.

func (*SingletonSet[E]) Union

func (s *SingletonSet[E]) Union(other Set[E]) Set[E]

Union returns a new immutable Set containing a union of the SingletonSet with another Set.

If the SingletonSet and the other Set are both nil, SingletonSet.Union returns nil.

func (*SingletonSet[E]) UnmarshalJSON

func (s *SingletonSet[E]) UnmarshalJSON(data []byte) error

type SortedJoinRuneOption

type SortedJoinRuneOption func(opts *sortedJoinRuneOptions)

SortedJoinRuneOption allows control over the sorting of rune elements when calling SortedJoinRune.

func WithRuneSorting

func WithRuneSorting(less func(x, y rune) bool) SortedJoinRuneOption

WithRuneSorting controls the sorting of rune elements.

By default, rune elements are sorted in ascending order.

func WithRuneSortingAsc

func WithRuneSortingAsc() SortedJoinRuneOption

WithRuneSortingAsc controls the sorting of rune elements to use ascending ordering.

This is the default ordering for rune elements.

func WithRuneSortingDesc

func WithRuneSortingDesc() SortedJoinRuneOption

WithRuneSortingDesc controls the sorting of rune elements to use descending ordering.

By default, rune elements are sorted in ascending order.

type SortedJoinStringOption

type SortedJoinStringOption func(opts *sortedJoinStringOptions)

SortedJoinStringOption allows control over the sorting of string elements when calling SortedJoinString.

func WithStringSorting

func WithStringSorting(less func(x, y string) bool) SortedJoinStringOption

WithStringSorting controls the sorting of string elements.

By default, string elements are sorted in ascending order.

func WithStringSortingAsc

func WithStringSortingAsc() SortedJoinStringOption

WithStringSortingAsc controls the sorting of string elements to use ascending ordering.

This is the default ordering for string elements.

func WithStringSortingDesc

func WithStringSortingDesc() SortedJoinStringOption

WithStringSortingDesc controls the sorting of string elements to use descending ordering.

By default, string elements are sorted in ascending order.

type SyncHashSet

type SyncHashSet[E comparable] struct {
	// contains filtered or unexported fields
}

SyncHashSet is an implementation of MutableSet that contains a unique data set.

While SyncHashSet is mutable it is safe for concurrent use by multiple goroutines without additional locking or coordination due to internal locking. If mutability is not required HashSet is a cheaper alternative.

func SyncHash

func SyncHash[E comparable](elements ...E) *SyncHashSet[E]

SyncHash returns a SyncHashSet struct that implements MutableSet containing each unique element provided.

While SyncHash returns a mutable struct it is safe for concurrent use by multiple goroutines without additional locking or coordination due to internal locking. If mutability is not required Hash provides a cheaper alternative.

func SyncHashFromJSON

func SyncHashFromJSON[E comparable](data []byte) (*SyncHashSet[E], error)

SyncHashFromJSON returns a SyncHashSet struct that implements MutableSet containing each unique element parsed from the JSON-encoded data provided.

While SyncHashFromJSON returns a mutable struct it is safe for concurrent use by multiple goroutines without additional locking or coordination due to internal locking. If mutability is not required HashFromJSON provides a cheaper alternative.

func SyncHashFromSlice

func SyncHashFromSlice[E comparable](elements []E) *SyncHashSet[E]

SyncHashFromSlice returns a SyncHashSet struct that implements MutableSet containing each unique element from the slice provided.

While SyncHashFromSlice returns a mutable struct it is safe for concurrent use by multiple goroutines without additional locking or coordination due to internal locking. If mutability is not required HashFromSlice provides a cheaper alternative.

func (*SyncHashSet[E]) Clear

func (s *SyncHashSet[E]) Clear() MutableSet[E]

Clear removes all elements from the SyncHashSet.

If the SyncHashSet is nil, SyncHashSet.Clear is a no-op.

A reference to the SyncHashSet is returned for method chaining.

func (*SyncHashSet[E]) Clone

func (s *SyncHashSet[E]) Clone() Set[E]

Clone returns a clone of the SyncHashSet.

If the SyncHashSet is nil, SyncHashSet.Clone returns nil.

func (*SyncHashSet[E]) Contains

func (s *SyncHashSet[E]) Contains(element E) bool

Contains returns whether the SyncHashSet contains the element.

If the SyncHashSet is nil, SyncHashSet.Contains returns false.

func (*SyncHashSet[E]) Delete

func (s *SyncHashSet[E]) Delete(element E, elements ...E) MutableSet[E]

Delete removes the element from the SyncHashSet as well as any additional elements specified.

If the SyncHashSet is nil, SyncHashSet.Delete is a no-op.

A reference to the SyncHashSet is returned for method chaining.

func (*SyncHashSet[E]) DeleteAll

func (s *SyncHashSet[E]) DeleteAll(elements Set[E]) MutableSet[E]

DeleteAll removes all elements in the specified Set from the SyncHashSet.

If the SyncHashSet is nil, SyncHashSet.DeleteAll is a no-op.

A reference to the SyncHashSet is returned for method chaining.

func (*SyncHashSet[E]) DeleteSlice

func (s *SyncHashSet[E]) DeleteSlice(elements []E) MutableSet[E]

DeleteSlice removes all elements in the specified slice from the SyncHashSet.

If the SyncHashSet is nil, SyncHashSet.DeleteSlice is a no-op.

A reference to the SyncHashSet is returned for method chaining.

func (*SyncHashSet[E]) DeleteWhere

func (s *SyncHashSet[E]) DeleteWhere(predicate func(element E) bool) MutableSet[E]

DeleteWhere removes all elements that match the predicate function from the SyncHashSet.

If the SyncHashSet is nil, SyncHashSet.DeleteWhere is a no-op.

A reference to the SyncHashSet is returned for method chaining.

func (*SyncHashSet[E]) Diff

func (s *SyncHashSet[E]) Diff(other Set[E]) Set[E]

Diff returns a new SyncHashSet struct containing only elements of the SyncHashSet that do not exist in another Set.

If the SyncHashSet is nil, SyncHashSet.Diff returns nil.

func (*SyncHashSet[E]) DiffSymmetric

func (s *SyncHashSet[E]) DiffSymmetric(other Set[E]) Set[E]

DiffSymmetric returns a new SyncHashSet struct containing elements that exist within the SyncHashSet or another Set, but not both.

If the SyncHashSet is nil, SyncHashSet.DiffSymmetric returns nil.

func (*SyncHashSet[E]) Equal

func (s *SyncHashSet[E]) Equal(other Set[E]) bool

Equal returns whether the SyncHashSet contains the exact same elements as another Set.

If the SyncHashSet is nil it is treated as having no elements and the same logic applies to the other Set. To clarify; this means that a nil Set is equal to a non-nil Set that contains no elements.

func (*SyncHashSet[E]) Every

func (s *SyncHashSet[E]) Every(predicate func(element E) bool) bool

Every returns whether the SyncHashSet contains elements that all match the predicate function.

If the SyncHashSet is nil, SyncHashSet.Every returns false.

func (*SyncHashSet[E]) Filter

func (s *SyncHashSet[E]) Filter(filter func(element E) bool) Set[E]

Filter returns a new SyncHashSet struct containing only elements of the SyncHashSet that match the filter function.

If the SyncHashSet is nil, SyncHashSet.Filter returns nil.

func (*SyncHashSet[E]) Find

func (s *SyncHashSet[E]) Find(search func(element E) bool) (E, bool)

Find returns an element within the SyncHashSet that matches the search function as well as an indication of whether a match was found.

Iteration order is not guaranteed to be consistent so results may vary.

If the SyncHashSet is nil, SyncHashSet.Find returns the zero value for E and false.

func (*SyncHashSet[E]) Immutable

func (s *SyncHashSet[E]) Immutable() Set[E]

Immutable returns an immutable clone of the SyncHashSet.

If the SyncHashSet is nil, SyncHashSet.Immutable returns nil.

func (*SyncHashSet[E]) Intersection

func (s *SyncHashSet[E]) Intersection(other Set[E]) Set[E]

Intersection returns a new SyncHashSet struct containing only elements of the SyncHashSet that also exist in another Set.

If the SyncHashSet is nil, SyncHashSet.Intersection returns nil.

func (*SyncHashSet[E]) IsEmpty

func (s *SyncHashSet[E]) IsEmpty() bool

IsEmpty returns whether the SyncHashSet contains no elements.

If the SyncHashSet is nil, SyncHashSet.IsEmpty returns true.

func (*SyncHashSet[E]) IsMutable

func (s *SyncHashSet[E]) IsMutable() bool

IsMutable always returns true to conform with Set.IsMutable.

func (*SyncHashSet[E]) Join

func (s *SyncHashSet[E]) Join(sep string, convert func(element E) string) string

Join converts the elements within the SyncHashSet to strings which are then concatenated to create a single string, placing sep between the converted elements in the resulting string.

The order of elements within the resulting string is not guaranteed to be consistent. SyncHashSet.SortedJoin should be used instead for such cases where consistent ordering is required.

If the SyncHashSet is nil, SyncHashSet.Join returns an empty string.

func (*SyncHashSet[E]) Len

func (s *SyncHashSet[E]) Len() int

Len returns the number of elements within the SyncHashSet.

If the SyncHashSet is nil, SyncHashSet.Len returns zero.

func (*SyncHashSet[E]) MarshalJSON

func (s *SyncHashSet[E]) MarshalJSON() ([]byte, error)

func (*SyncHashSet[E]) Max

func (s *SyncHashSet[E]) Max(less func(x, y E) bool) (E, bool)

Max returns the maximum element within the SyncHashSet using the provided less function.

If the SyncHashSet is nil, SyncHashSet.Max returns the zero value for E and false.

func (*SyncHashSet[E]) Min

func (s *SyncHashSet[E]) Min(less func(x, y E) bool) (E, bool)

Min returns the minimum element within the SyncHashSet using the provided less function.

If the SyncHashSet is nil, SyncHashSet.Min returns the zero value for E and false.

func (*SyncHashSet[E]) Mutable

func (s *SyncHashSet[E]) Mutable() MutableSet[E]

Mutable returns a reference to itself to conform with Set.Mutable.

If the SyncHashSet is nil, SyncHashSet.Mutable returns nil.

func (*SyncHashSet[E]) None

func (s *SyncHashSet[E]) None(predicate func(element E) bool) bool

None returns whether the SyncHashSet contains no elements that match the predicate function.

If the SyncHashSet is nil, SyncHashSet.None returns true.

func (*SyncHashSet[E]) Put

func (s *SyncHashSet[E]) Put(element E, elements ...E) MutableSet[E]

Put adds the element to the SyncHashSet as well as any additional elements specified. Nothing changes for elements that already exist within the SyncHashSet.

If the SyncHashSet is nil, SyncHashSet.Put is a no-op.

A reference to the SyncHashSet is returned for method chaining.

func (*SyncHashSet[E]) PutAll

func (s *SyncHashSet[E]) PutAll(elements Set[E]) MutableSet[E]

PutAll adds all elements in the specified Set to the SyncHashSet. Nothing changes for elements that already exist within the SyncHashSet.

If the SyncHashSet is nil, SyncHashSet.PutAll is a no-op.

A reference to the SyncHashSet is returned for method chaining.

func (*SyncHashSet[E]) PutSlice

func (s *SyncHashSet[E]) PutSlice(elements []E) MutableSet[E]

PutSlice adds all elements in the specified slice to the SyncHashSet. Nothing changes for elements that already exist within the SyncHashSet.

If the SyncHashSet is nil, SyncHashSet.PutSlice is a no-op.

A reference to the SyncHashSet is returned for method chaining.

func (*SyncHashSet[E]) Range

func (s *SyncHashSet[E]) Range(iter func(element E) bool)

Range calls the iter function with each element within the SyncHashSet but will stop early whenever the iter function returns true.

Iteration order is not guaranteed to be consistent.

If the SyncHashSet is nil, SyncHashSet.Range is a no-op.

func (*SyncHashSet[E]) Retain

func (s *SyncHashSet[E]) Retain(element E, elements ...E) MutableSet[E]

Retain removes all elements from the SyncHashSet except the element(s) specified.

If the SyncHashSet is nil, SyncHashSet.Retain is a no-op.

A reference to the SyncHashSet is returned for method chaining.

func (*SyncHashSet[E]) RetainAll

func (s *SyncHashSet[E]) RetainAll(elements Set[E]) MutableSet[E]

RetainAll removes all elements from the SyncHashSet except those in the specified Set.

If the SyncHashSet is nil, SyncHashSet.RetainAll is a no-op.

A reference to the SyncHashSet is returned for method chaining.

func (*SyncHashSet[E]) RetainSlice

func (s *SyncHashSet[E]) RetainSlice(elements []E) MutableSet[E]

RetainSlice removes all elements from the SyncHashSet except those in the specified slice.

If the SyncHashSet is nil, SyncHashSet.RetainSlice is a no-op.

A reference to the SyncHashSet is returned for method chaining.

func (*SyncHashSet[E]) RetainWhere

func (s *SyncHashSet[E]) RetainWhere(predicate func(element E) bool) MutableSet[E]

RetainWhere removes all elements except those that match the predicate function from the SyncHashSet.

If the SyncHashSet is nil, SyncHashSet.RetainWhere is a no-op.

A reference to the SyncHashSet is returned for method chaining.

func (*SyncHashSet[E]) Slice

func (s *SyncHashSet[E]) Slice() []E

Slice returns a slice containing all elements of the SyncHashSet.

The order of elements within the resulting slice is not guaranteed to be consistent. SyncHashSet.SortedSlice should be used instead for such cases where consistent ordering is required.

If the SyncHashSet is nil, SyncHashSet.Slice returns nil.

func (*SyncHashSet[E]) Some

func (s *SyncHashSet[E]) Some(predicate func(element E) bool) bool

Some returns whether the SyncHashSet contains any element that matches the predicate function.

If the SyncHashSet is nil, SyncHashSet.Some returns false.

func (*SyncHashSet[E]) SortedJoin

func (s *SyncHashSet[E]) SortedJoin(sep string, convert func(element E) string, less func(x, y E) bool) string

SortedJoin sorts the elements within the SyncHashSet using the provided less function and then converts those elements into strings which are then joined using the specified separator to create the resulting string.

If the SyncHashSet is nil, SyncHashSet.SortedJoin returns an empty string.

func (*SyncHashSet[E]) SortedSlice

func (s *SyncHashSet[E]) SortedSlice(less func(x, y E) bool) []E

SortedSlice returns a slice containing all elements of the SyncHashSet sorted using the provided less function.

If the SyncHashSet is nil, SyncHashSet.SortedSlice returns nil.

func (*SyncHashSet[E]) String

func (s *SyncHashSet[E]) String() string

func (*SyncHashSet[E]) TryRange

func (s *SyncHashSet[E]) TryRange(iter func(element E) error) error

TryRange calls the iter function with each element within the SyncHashSet but will stop early whenever the iter function returns an error.

Iteration order is not guaranteed to be consistent.

If the SyncHashSet is nil, SyncHashSet.TryRange is a no-op.

func (*SyncHashSet[E]) Union

func (s *SyncHashSet[E]) Union(other Set[E]) Set[E]

Union returns a new SyncHashSet containing a union of the SyncHashSet with another Set.

If the SyncHashSet and the other Set are both nil, SyncHashSet.Union returns nil.

func (*SyncHashSet[E]) UnmarshalJSON

func (s *SyncHashSet[E]) UnmarshalJSON(data []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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