C Everything
This is a C repository containing a curated set of generic data structures and algorithm.
disjoint_set.c File Reference

Contains definitions of routines supported by disjoint_set. More...

#include "disjoint_set.h"

Go to the source code of this file.

Functions

void destroy_disjoint_set (t_gen d)
 
Destroy the instance of disjoint set data struct More...
 
void disjoint_set_make (t_gen d)
 
The MakeSet operation adds a new element More...
 
int disjoint_set_find (t_gen d, int x)
 
Find the set the node belongs to the method defined follows path halving More...
 
int disjoint_set_merge (t_gen d, int x, int y)
 
Merge the given two subsets More...
 
void disjoint_set_print (t_gen d)
 
Print the elem of the disjoint set More...
 
t_gen create_disjoint_set (char *name, int size)
 
Create an instance of disjoint set data struct More...
 

Detailed Description

Contains definitions of routines supported by disjoint_set.

Definition in file disjoint_set.c.

Function Documentation

◆ create_disjoint_set()

t_gen create_disjoint_set ( char *  name,
int  size 
)


Create an instance of disjoint set data struct

Parameters
name- Name of disjoint set instance
size- size of the disjoin set
Returns
- Pointer to instance of disjoint set

Definition at line 20 of file disjoint_set.c.

◆ destroy_disjoint_set()

void destroy_disjoint_set ( t_gen  d)


Destroy the instance of disjoint set data struct

Parameters
d- Pointer to instance of disjoint set
Returns
- NA

Definition at line 43 of file disjoint_set.c.

◆ disjoint_set_find()

int disjoint_set_find ( t_gen  d,
int  x 
)


Find the set the node belongs to the method defined follows path halving

See also
https://en.wikipedia.org/wiki/Disjoint-set_data_structure
Parameters
d- Pointer to instance of disjoint set
x- idx of node
Returns
- return the root element of the disjoint set

Definition at line 74 of file disjoint_set.c.

◆ disjoint_set_make()

void disjoint_set_make ( t_gen  d)


The MakeSet operation adds a new element

Parameters
d- Pointer to instance of disjoint set
Returns
- NA

Definition at line 56 of file disjoint_set.c.

◆ disjoint_set_merge()

int disjoint_set_merge ( t_gen  d,
int  x,
int  y 
)


Merge the given two subsets

See also
https://en.wikipedia.org/wiki/Disjoint-set_data_structure
Parameters
d- Pointer to instance of disjoint set
x- idx of first node
y- idx of second node
Returns
- if nodes already merged return -1 else 0 on merge

Definition at line 95 of file disjoint_set.c.

◆ disjoint_set_print()

void disjoint_set_print ( t_gen  d)


Print the elem of the disjoint set

Parameters
d- Pointer to instance of link list
Returns
- NA

Definition at line 123 of file disjoint_set.c.