Data Structures Lerax  1.1.0
Opinionated Data Structures & Algorithms
Loading...
Searching...
No Matches
set-disjoint.h File Reference

Go to the source code of this file.

Typedefs

typedef struct DisjointSet DisjointSet
 A disjoint-set data structure.

Functions

DisjointSetset_disjoint_create (int n)
 Creates a new disjoint-set data structure with n elements.
void set_disjoint_free (DisjointSet *ds)
 Free a disjoint-set data structure.
int set_disjoint_find (DisjointSet *ds, int i)
 Finds the representative of the set containing element i.
void set_disjoint_union (DisjointSet *ds, int i, int j)
 Merges the sets containing elements i and j.

Typedef Documentation

◆ DisjointSet

typedef struct DisjointSet DisjointSet

A disjoint-set data structure.

See also
https://en.wikipedia.org/wiki/Disjoint-set_data_structure

Function Documentation

◆ set_disjoint_create()

DisjointSet * set_disjoint_create ( int n)

Creates a new disjoint-set data structure with n elements.

Parameters
[in]nThe number of elements.
Returns
A pointer to the new disjoint-set.

◆ set_disjoint_find()

int set_disjoint_find ( DisjointSet * ds,
int i )

Finds the representative of the set containing element i.

Parameters
[in]dsThe disjoint-set.
[in]iThe element to find.
Returns
The representative of the set containing i.

◆ set_disjoint_free()

void set_disjoint_free ( DisjointSet * ds)

Free a disjoint-set data structure.

Parameters
[in,out]dsA pointer to a pointer to the disjoint-set.

◆ set_disjoint_union()

void set_disjoint_union ( DisjointSet * ds,
int i,
int j )

Merges the sets containing elements i and j.

Parameters
[in,out]dsThe disjoint-set.
[in]iThe first element.
[in]jThe second element.