bitset

package
v0.0.0-...-6dfbae8 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package bitset contains the implementation of a set backed by a bit array.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

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

Set is an implementation of a set ADT backed by a bit array. It can store elements in the range [0..math.MaxUint64]. Default value represents an empty set and is ready to use.

func From

func From(s []uint) *Set

From creates a new set with elements from s.

func New

func New(length uint) *Set

New creates a new set with a hint that at least length bits are required. If length is 0, returns an empty set.

func (*Set) Add

func (s *Set) Add(e uint)

Add adds element e to the set. Specifically, sets bit at index e to 1.

func (*Set) AsBits

func (b *Set) AsBits() string

AsBits returns the contents of a set as a string of bits.

func (*Set) Clone

func (s *Set) Clone() *Set

Clone clones this set.

func (*Set) Contains

func (s *Set) Contains(e uint) bool

Contains returns true if this set contains the specified element. Specifically, it returns true if the bit at index e is set to 1. If e is larger than [Set.Len] returns false.

func (*Set) Difference

func (s *Set) Difference(other *Set) *Set

Difference returns the difference of two sets. Specifically, the bit in the resulting set is set to 1 if it is set to 1 in this set and set to 0 in other set.

func (*Set) Equal

func (s *Set) Equal(other *Set) bool

Equal returns true if the provided set and this set contain the same elements. Namely, the lengths of the sets can be different.

func (*Set) Remove

func (s *Set) Remove(e uint)

Remove removes the element e from the set. Specifically, it sets the bit at index e to 0. If e is larger than [Set.Len] set is left unchanged.

func (*Set) RemoveAll

func (s *Set) RemoveAll()

RemoveAll removes all the elements from the set. Specifically, it sets all the bits to 0.

func (*Set) Size

func (s *Set) Size() int

Size returns the number of the elements in the set. Specifically, it returns the number of bits set to 1 in a bitset (population count).

func (*Set) Union

func (s *Set) Union(other *Set) *Set

Union returns the union of two sets. Specifically, resulting in a set where any bit set to 1 in either of the original sets is set to 1 in the returned set.

func (*Set) Values

func (b *Set) Values() []uint

Values returns all the elements in the set.

Jump to

Keyboard shortcuts

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