Class Partition

Class Documentation

class Partition

Implements a partition of a set, i.e. a subdivision of the set into disjoint subsets.

Public Functions

Partition()
Partition(index z)

Create a new partition data structure for z elements.

Parameters:

z[in] maximum index

Partition(index z, index defaultValue)

Create a new partition data structure for z elements. Initialize each entry to the default value. WARNING: this circumvents the standard interface and may leave the object in an inconsistent state. Use only in exceptional cases.

Parameters:
  • z[in] maximum index

  • defaultValue[in]

Partition(const std::vector<index> &data)
inline void reset(index newZ, index defaultValue)
inline index &operator[](index e)

Index operator.

Parameters:

e[in] an element

inline const index &operator[](index e) const

Index operator for const instances of this class.

Parameters:

e[in] an element

inline index subsetOf(index e) const

Get the set (id) in which the element e is contained.

Parameters:

e – Index of element.

Returns:

The index of the set in which e is contained.

inline index extend()

Extend the data structure and create a slot for one more element. Initializes the entry to none and returns the index of the entry.

inline void remove(index e)

Removes the entry for the given element by setting it to none.

inline void addToSubset(index s, index e)

Add a (previously unassigned) element e to the set s.

Parameters:
  • s – The index of the subset.

  • e – The element to add.

inline void moveToSubset(index s, index e)

Move the (previously assigned) element e to the set s.

Parameters:
  • s – The index of the subset.

  • e – The element to move.

inline void toSingleton(index e)

Creates a singleton set containing the element e.

Parameters:

e – The index of the element.

void allToSingletons()

Assigns every element to a singleton set. Set id is equal to element id.

void allToOnePartition()

Assigns every element to the same subset. Set id is equal to zero.

index mergeSubsets(index s, index t)

Assigns the elements from both sets to a new set and returns the id of it.

Parameters:
  • s – Set to merge.

  • t – Set to merge.

Returns:

Id of newly created set.

inline void setUpperBound(index upper)

Sets an upper bound for the subset ids that CAN be assigned.

Parameters:

upper[in] highest assigned subset ID + 1

inline index upperBound() const

Return an upper bound for the subset ids that have been assigned. (This is the maximum id + 1.)

Returns:

The upper bound.

inline index lowerBound() const

Get a lower bound for the subset ids that have been assigned.

Returns:

The lower bound.

void compact(bool useTurbo = false)

Change subset IDs to be consecutive, starting at 0.

Parameters:

useTurbo – Default: false. If set to true, a vector instead of a map to assign new ids which results in a shorter running time but possibly a large space overhead.

inline bool contains(index e) const

Check if partition assigns a valid subset to the element e.

Parameters:

e – The element.

Returns:

true if the assigned subset is valid, false otherwise.

inline bool inSameSubset(index e1, index e2) const

Check if two elements e1 and e2 belong to the same subset.

Parameters:
  • e1 – Element.

  • e2 – Element.

Returns:

true if e1 and e2 belong to same subset, false otherwise.

std::vector<count> subsetSizes() const

Get a list of subset sizes. Indices do not necessarily correspond to subset ids.

Returns:

A vector of subset sizes.

std::map<index, count> subsetSizeMap() const

Get a map from subset id to size of the subset.

Returns:

A map from subset id to size of the subset.

std::set<index> getMembers(index s) const

Get the members of the subset s.

Parameters:

s – The subset.

Returns:

A set containing the members of s.

inline count numberOfElements() const
Returns:

number of elements in the partition.

count numberOfSubsets() const

Get the current number of sets in this partition.

Returns:

The current number of sets.

const std::vector<index> &getVector() const

Get the actual vector representing the partition data structure.

Returns:

vector containing information about partitions.

std::set<std::set<index>> getSubsets() const
Returns:

the subsets of the partition as a set of sets.

std::set<index> getSubsetIds() const

Get the ids of nonempty subsets.

Returns:

A set of ids of nonempty subsets.

inline void setName(std::string name)

Set a human-readable identifier name for the instance.

Parameters:

name – The name.

inline std::string getName() const

Get the human-readable identifier.

Returns:

The name of this partition.

template<typename Callback>
inline void forEntries(Callback func) const

Iterate over all entries (node, cluster id) and execute callback function func (lambda closure).

Parameters:

func – Takes parameters (node, index)

template<typename Callback>
inline void parallelForEntries(Callback handle) const

Iterate over all entries (node, cluster id) in parallel and execute callback function handle (lambda closure).

Parameters:

handle – Takes parameters (node, index)