smallset

package
v0.0.0-...-a142011 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set[T cmp.Ordered] struct {
	// contains filtered or unexported fields
}

Set is an immutable set optimized for *small number of items*. For general purposes, Sets is likely better

*Set construction*: sets is roughly 1kb allocations per 250 items. smallsets is 0. *Contains* sets is O(1). smallsets is O(logn). smallsets is typically faster up to about 5 elements.

At 1000 items, it is roughly 5x slower (30ns vs 5ns).

func New

func New[T cmp.Ordered](items ...T) Set[T]

New creates a new Set with the given items. Duplicates are removed

func NewPresorted

func NewPresorted[T cmp.Ordered](items ...T) Set[T]

NewPresorted creates a new Set with the given items. If items is not sorted or contains duplicates, this gives undefined behavior; use New instead.

func (Set[T]) Contains

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

Contains returns whether the given item is in the set.

func (Set[T]) CopyAndInsert

func (s Set[T]) CopyAndInsert(items ...T) Set[T]

CopyAndInsert builds a *new* with all the current items plus new items

func (Set[T]) IsEmpty

func (s Set[T]) IsEmpty() bool

IsEmpty indicates whether the set is the empty set.

func (Set[T]) IsNil

func (s Set[T]) IsNil() bool

IsNil indicates whether the set is nil. This is different from an empty set. 'var smallset.Set': nil smallset.New(): nil smallset.New(emptyList...): not nil

func (Set[T]) Len

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

Len returns the number of elements in this Set.

func (Set[T]) List

func (s Set[T]) List() []T

List returns the underlying slice. Must not be modified

func (Set[T]) String

func (s Set[T]) String() string

String returns a string representation of the set. Use it only for debugging and logging.

Jump to

Keyboard shortcuts

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