Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
Set is the universal implementation of a disjoint set. It's designed for sparse cases or non-integer types. If you are dealing with continuous integers, you should use SimpleIntSet to avoid the cost of a hash map. We hash the original value to an integer index and then apply the core disjoint set algorithm. Time complexity: the union operation has an inverse Ackermann function time complexity, which is very close to O(1).
func (*Set[T]) InSameGroup ¶
InSameGroup checks whether a and b are in the same group.
type SimpleIntSet ¶
type SimpleIntSet struct {
// contains filtered or unexported fields
}
SimpleIntSet is the int disjoint set. It's not designed for sparse case. You should use it when the elements are continuous. Time complexity: the union operation is inverse ackermann function, which is very close to O(1).
func (*SimpleIntSet) FindRoot ¶
func (m *SimpleIntSet) FindRoot(a int) int
FindRoot finds the representative element of the set that `a` belongs to.
func (*SimpleIntSet) Union ¶
func (m *SimpleIntSet) Union(a int, b int)
Union unions two sets in int disjoint set.