/* disjset.h : Disjoint Set ADT
 *
 * The disjoint set ADT (a.k.a. union/find algorithm) provides an
 * efficient representation of disjoint sets. 
 *
 * Values of type ElementType are set to belong to sets of type SetType.
 * Two basic operations are supported :
 *
 * DS_Find : Returns the identifier of the set to which a value belongs.
 *           Two values will have the same identifier if and only if they
 *           belong to the same set.
 *
 * DS_SetUnion : Will perform a set union operation on its two set parameters.
 *               Following the operation, elements in the two sets will
 *               return the same identifier in DS_Find
 *
 * Administrative functions include DS_Create and DS_Destroy.  DS_Create
 * will create one set for each value.
 */

#ifndef DISJSET_H_INCLUDED
#define DISJSET_H_INCLUDED

typedef int SetType;
typedef int ElementType;

struct Disjoint_Set_Struct;
typedef struct Disjoint_Set_Struct *Disjoint_Set;

/* 
 * Constuctors
 */

/** Creates a new disjoint set which may represent at most MaxNumSets */
Disjoint_Set DS_Create(unsigned int MaxNumSets);

/** Destroys the disjoint set (invalidates pointers) */
void DS_Destroy(Disjoint_Set ds);

/*
 * Accessors
 */

/** Returns the set to which element X belongs */
SetType DS_Find(const Disjoint_Set ds, ElementType X);

/** Dumps the set contents to standard out (for debugging) */
void DS_Print(const Disjoint_Set ds);

/*
 * Modifiers 
 */

/** Performs the set "union" operation on sets Root1, Root2 */
void DS_SetUnion(Disjoint_Set ds, SetType Root1, SetType Root2);

#endif /* ifndef DISJSET_H_INCLUDED */
