Class DisjointSet
Basic representation of a disjoint set data structure.
Inheritance
Implements
Inherited Members
Namespace: GoRogue
Assembly: GoRogue.dll
Syntax
[Serializable]
public class DisjointSet : IReadOnlyDisjointSet
Remarks
For reasons pertaining to optimization, this disjoint set implementation does not use generics, and instead holds integer values, which MUST be exactly all integer values in range [0, num_items_in_set - 1]. Thus, you will need to assign appropriate IDs to objects you intend to add and map them appropriately.
Constructors
| Improve this Doc View SourceDisjointSet(Int32)
Constructor. The disjoint set will contain all values in range [0, size
- 1].
Declaration
public DisjointSet(int size)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | size | (Max) size of the disjoint set. |
Properties
| Improve this Doc View SourceCount
Number of distinct sets.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourceAsReadOnly()
Returns a read-only representation of the disjoint set.
Declaration
public IReadOnlyDisjointSet AsReadOnly()
Returns
Type | Description |
---|---|
IReadOnlyDisjointSet | A read-only representation of the disjoint set. |
Find(Int32)
Returns the parent of the set containing obj
, performing path compression
as the search is completed.
Declaration
public int Find(int obj)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | obj | Object to search for. |
Returns
Type | Description |
---|---|
System.Int32 | The parent of the object given. |
InSameSet(Int32, Int32)
Returns true if the two objects specified are in the same set.
Declaration
public bool InSameSet(int obj1, int obj2)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | obj1 | |
System.Int32 | obj2 |
Returns
Type | Description |
---|---|
System.Boolean | True if the two objects are in the same set, false otherwise. |
MakeUnion(Int32, Int32)
Performs a union of the sets containing the two objects specified. After this operation, every element in the sets containing the two objects specified will be part of one larger set.
Declaration
public void MakeUnion(int obj1, int obj2)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | obj1 | |
System.Int32 | obj2 |
Remarks
If the two elements are already in the same set, nothing is done.
ToString()
Returns a string representation of the DisjointSet, showing parents and all elements in their set.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A string representation of the DisjointSet. |