disjoint_set

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DSU

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

DSU represents a Disjoint Set Union data structure

func NewDSU

func NewDSU() *DSU

NewDSU creates a new DSU with the given size.

func (*DSU) Add

func (d *DSU) Add(label string) int

Add adds a new group to the DSU. Returns the index of the new group.

func (*DSU) Connected

func (d *DSU) Connected(x int, y int) bool

Connected checks if two elements are in the same set

func (*DSU) CountSets

func (d *DSU) CountSets() int

CountSets returns the number of unique sets in the DSU

func (*DSU) FindLabel

func (d *DSU) FindLabel(idx int) string

FindLabel finds the label by a root index or empty string if not found

func (*DSU) FindOrCreate

func (d *DSU) FindOrCreate(label string) int

FindOrCreate finds the root of the set by label, or adds it if it doesn't exist

func (*DSU) Labels

func (d *DSU) Labels() []string

Labels returns all labels in the DSU

func (*DSU) MarshalJSON

func (d *DSU) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface

func (*DSU) Size

func (d *DSU) Size() int

Size returns the number of elements in the DSU

func (*DSU) Union

func (d *DSU) Union(x int, y int)

Union merges two sets

func (*DSU) UnmarshalJSON

func (d *DSU) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface

Jump to

Keyboard shortcuts

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