Crate set_partitions

Source
Expand description

The set-partition crate provides ways to represent, enumerate and count all the possible partitions of a set of a given finite size into subsets.

You can use the set_partitions function to get the number of partitions of a set with n elements, and you can use the SetPartition struct and its increment() function to enumerate them (as well as its more generic variants).

Set partitions are represented as sequences of values, with one value for each element of the partitioned set, such that if two elements are in the same subset, the sequence will have the same values at the corresponding indices.

Among all the possible sequences, the one which is lexicographically minimal, and uses values starting from Default::default() and incrementing with increment(), is chosen as the representative.

See http://www-cs-faculty.stanford.edu/~uno/fasc3b.ps.gz page 27 for more information and a description of the algorithm used here.

§How to use

For fixed size set partitions, use SetPartition#; use GenSetPartition# if you want to use something other than u8 as the data type. For variable size set partitions up to 16 elements (more than 16 result in more than 2^32 partitions), use SmallSetPartition or GenSetPartition, For medium sized variable size set partitions, use ArrayVecSetPartition. For arbitrary sized set partitions, use VecSetPartition.

If you don’t care about getting the subset contents, pass () or omit the type parameter. Otherwise, use SmallSubsets or GenSmallSubsets to represent subsets using ArrayVecs without memory allocation, for set partitions of size 16 or less. For subsets in other data structures, you can use ArrayVecSubsets, VecSubsets,HashSubsets or BTreeSubsets.

To enumerate set partitions, call increment() until it returns false, and use get(), num_subsets() or subsets().subsets() to examine the set partition.

Modules§

traits
Module for the Incrementable trait

Structs§

ArrayVecSetPartition
Represents a set partition stored in an ArrayVec.
ArrayVecSubsets
Maintains subsets of a set partition using ArrayVecs
BTreeSubsets
Maintains subsets of a set partition using BTreeSets
GenSetPartition0
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition1
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition2
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition3
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition4
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition5
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition6
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition7
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition8
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition9
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition10
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition11
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition12
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition13
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition14
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition15
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition16
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition17
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition18
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition19
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition20
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition21
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition22
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition23
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition24
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition25
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition26
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition27
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition28
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition29
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition30
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition31
Represents a fixed size set partition stored in a fixed-size array
GenSetPartition32
Represents a fixed size set partition stored in a fixed-size array
HashSubsets
Maintains subsets of a set partition using HashSets
SetPartition0
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition1
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition2
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition3
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition4
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition5
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition6
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition7
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition8
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition9
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition10
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition11
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition12
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition13
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition14
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition15
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition16
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition17
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition18
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition19
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition20
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition21
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition22
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition23
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition24
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition25
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition26
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition27
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition28
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition29
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition30
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition31
Represents a fixed size set partition stored in a fixed-size u8 array
SetPartition32
Represents a fixed size set partition stored in a fixed-size u8 array
VecSetPartition
Represents a set partition stored in a Vec
VecSubsets
Maintains subsets of a set partition using Vecs

Traits§

Subsets
Trait used by SetPartition structs to notify the subsets structure of changes.

Functions§

set_partitions
Number of partitions of a set of n elements.

Type Aliases§

GenSmallSetPartition
Represents a set partition stored in a 16-entry ArrayVec.
GenSmallSubsets
Maintains subsets of a set partition using 16-entry ArrayVecs
SmallSetPartition
Represents a set partition stored in a 16-entry ArrayVec.
SmallSubsets
Maintains subsets of a set partition using 16-entry ArrayVecs