sets

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package sets contains set data structures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hash added in v0.18.0

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

A Hash is a set implemented via a map.

func NewHash added in v0.18.0

func NewHash[T comparable](initialValues ...T) *Hash[T]

NewHash creates a new Hash set.

func (*Hash[T]) Add added in v0.18.0

func (s *Hash[T]) Add(elements ...T)

Add adds a value to the set.

func (*Hash[T]) Has added in v0.18.0

func (s *Hash[T]) Has(element T) bool

Has returns true if the element is in the set.

func (*Hash[T]) Size added in v0.18.0

func (s *Hash[T]) Size() int

Size returns the size of the set.

type SizeLimited added in v0.19.0

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

A SizeLimited is a Set which is limited to a given size. Once the capacity is reached an element will be removed at random.

func NewSizeLimited added in v0.19.0

func NewSizeLimited[T comparable](capacity int) *SizeLimited[T]

NewSizeLimited create a new SizeLimited.

func (*SizeLimited[T]) Add added in v0.19.0

func (s *SizeLimited[T]) Add(element T)

Add adds an element to the set.

func (*SizeLimited[T]) ForEach added in v0.19.0

func (s *SizeLimited[T]) ForEach(callback func(element T) bool)

ForEach iterates over all the elements in the set.

type Sorted added in v0.19.0

type Sorted[T any] struct {
	// contains filtered or unexported fields
}

A Sorted is a set with sorted iteration.

func NewSorted added in v0.19.0

func NewSorted[T constraints.Ordered]() *Sorted[T]

NewSorted creates a new sorted string set.

func (*Sorted[T]) Add added in v0.19.0

func (s *Sorted[T]) Add(elements ...T)

Add adds a string to the set.

func (*Sorted[T]) Clear added in v0.19.0

func (s *Sorted[T]) Clear()

Clear clears the set.

func (*Sorted[T]) Delete added in v0.19.0

func (s *Sorted[T]) Delete(element T)

Delete deletes an element from the set.

func (*Sorted[T]) ForEach added in v0.19.0

func (s *Sorted[T]) ForEach(callback func(element T) bool)

ForEach iterates over the set in ascending order.

func (*Sorted[T]) Has added in v0.19.0

func (s *Sorted[T]) Has(element T) bool

Has returns true if the element is in the set.

func (*Sorted[T]) Size added in v0.19.0

func (s *Sorted[T]) Size() int

Size returns the size of the set.

func (*Sorted[T]) ToSlice added in v0.19.0

func (s *Sorted[T]) ToSlice() []T

ToSlice returns a slice of all the elements in the set.

Jump to

Keyboard shortcuts

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