bitset

package
v0.0.0-...-11eb462 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

bitset contains an efficient implementation of a set of unsigned numbers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BitSet

type BitSet struct {
	// contains filtered or unexported fields
}

BitSet is a set of (almost) arbitrary-sized integers.

The zero value (`&BitSet{}`) is a BitSet containing no elements.

The representation uses big.Int to check whether a number is included in the set, so a map-based set may be a better use-case for sparse sets without any upper-bound.

Even tough most operations accept `int` as an argument, those functions will panic if the provided number is negative.

See also Small - a more efficient implementation if elements are known to be in range [0, 63] inclusive - and which can be used as a key in a map (by fulfilling the comparable protocol).

func Of

func Of(is ...int) *BitSet

Of returns a BitSet containing all the provided elements

func (*BitSet) Add

func (s *BitSet) Add(i int)

Add ensures that the provided number is in the set.

func (*BitSet) Clear

func (s *BitSet) Clear()

Clear ensures that no numbers are present in the set.

func (*BitSet) Clone

func (s *BitSet) Clone() *BitSet

Clone returns a new set with the same elements.

func (*BitSet) Difference

func (s1 *BitSet) Difference(s2 *BitSet)

Difference ensures s1 does not contain any elements from s1.

func (*BitSet) Equal

func (s1 *BitSet) Equal(s2 *BitSet) bool

Equal returns true if s1 contains the same elements as s2.

func (*BitSet) Has

func (s *BitSet) Has(i int) bool

Has returns true if the provided number is in the set.

func (*BitSet) Intersection

func (s1 *BitSet) Intersection(s2 *BitSet)

Intersection ensures s1 only contains elements that are present in both s1 and s2.

func (*BitSet) IsDisjoint

func (s1 *BitSet) IsDisjoint(s2 *BitSet) bool

IsDisjoint returns true if s1 and s2 have no elements in common.

func (*BitSet) IsSubset

func (s1 *BitSet) IsSubset(s2 *BitSet) bool

IsSubset returns true if every element of s1 is also present in s2.

func (*BitSet) IsSuperset

func (s1 *BitSet) IsSuperset(s2 *BitSet) bool

IsSuperset returns true if every element of s2 is also present in s1.

func (*BitSet) Iter

func (s *BitSet) Iter() iter.Iterator[int]

func (*BitSet) Len

func (s *BitSet) Len() int

Len returns the number of elements in the set.

func (*BitSet) Remove

func (s *BitSet) Remove(i int)

Remove ensures that the provided number is not in the set.

func (*BitSet) Union

func (s1 *BitSet) Union(s2 *BitSet)

Union ensures s1 contains all elements from s2.

type Small

type Small uint64

Small is a set of integers between 0 and 63 (inclusive), which also fulfills the `comparable` interface and can be used e.g. as a map key.

The zero value (`Small(0)`) is a set containing no elements.

The representation is a simple wrapper around uint64.

Trying to provide elements outside of the <0, 63> range is undefined behavior.

See also BitSet - an implementation for (almost) arbitrary sized elements.

func SmallOf

func SmallOf(is ...int) Small

SmallOf returns a bitset containing the provided numbers.

func (*Small) Add

func (s *Small) Add(i int)

Add ensures that the provided number is in the set.

func (*Small) Clear

func (s *Small) Clear()

Clear ensures that no numbers are present in the set.

func (Small) Clone

func (s Small) Clone() Small

Clone returns a new set with the same elements.

func (*Small) Difference

func (s1 *Small) Difference(s2 Small)

Difference ensures b1 does not contain any elements from b2.

func (Small) Equal

func (s1 Small) Equal(s2 Small) bool

Equal returns true if b1 contains the same elements as b2.

func (Small) Has

func (s Small) Has(i int) bool

Has returns true if the provided number is in the set.

func (*Small) Intersection

func (s1 *Small) Intersection(s2 Small)

Intersection ensures b1 only contains elements that are present in both b1 and b2.

func (Small) IsDisjoint

func (s1 Small) IsDisjoint(s2 Small) bool

IsDisjoint returns true if s1 and s2 have no elements in common.

func (Small) IsSubset

func (s1 Small) IsSubset(s2 Small) bool

IsSubset returns true if every element of s1 is also present in s2.

func (Small) IsSuperset

func (s1 Small) IsSuperset(s2 Small) bool

IsSuperset returns true if every element of s2 is also present in s1.

func (Small) Iter

func (s Small) Iter() iter.Iterator[int]

Iter returns an iterator over the elements in the set.

Any changes made during iteration are not reflected in the iterator; iteration is actually performed on a copy of the set.

func (Small) Len

func (s Small) Len() int

Len returns the number of elements in the set.

func (*Small) Remove

func (s *Small) Remove(i int)

Remove ensures that the provided number is not in the set.

func (*Small) Union

func (s1 *Small) Union(s2 Small)

Union ensures b1 contains all elements from b2.

Jump to

Keyboard shortcuts

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