Product Class |
Namespace: Kaos.Combinatorics
public class Product : IComparable, IEnumerable, IComparable<Product>, IEquatable<Product>, IEnumerable<int>
The Product type exposes the following members.
Name | Description | |
---|---|---|
Product | Initializes an empty product instance. | |
Product(Int32) | Initializes a new product of Rank 0 with the supplied sizes of columns. | |
Product(Product) | Initializes a new instance that is copied from the supplied product. | |
Product(Int32, Int32) | Initializes a new product of the supplied values with the supplied sizes of columns. | |
Product(Int32, Int64) | Initializes a new product of the supplied rankwith the supplied sizes of columns. |
Name | Description | |
---|---|---|
Item | Get an element of the Product at the supplied column. | |
Rank | Row index of the join in the lexicographically ordered Product table. | |
RowCount | Count of distinct joins in the Product table. | |
Width | Number of columns in the Product. |
Name | Description | |
---|---|---|
CompareTo(Object) | Compare two Products. | |
CompareTo(Product) | Compare two Products. | |
CopyTo | Copy the entire sequence to the supplied destination. | |
Equals(Object) | Indicate whether two Products have the same value. (Overrides ObjectEquals(Object).) | |
Equals(Product) | Indicate whether two Products have the same value. | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetEnumerator | Enumerate all elements of a Product. | |
GetHashCode | Get the hash oode of the Product. (Overrides ObjectGetHashCode.) | |
GetRows | Iterate thru all rows of the Product table for every Rank ascending. | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
PermuteT | Apply a Product sequence to select from the supplied lists or arrays. | |
Size | Get the size of a column. | |
ToString | Provide readable form of the Product row. (Overrides ObjectToString.) |
Name | Description | |
---|---|---|
Equality | Indicate whether 2 Products are equal. | |
GreaterThan | Indicate whether the left Product is greater than
the right Product. | |
GreaterThanOrEqual | Indicate whether the left Product is greater than
or equal to the right Product. | |
Inequality | Indicate whether 2 Products are not equal. | |
LessThan | Indicate whether the left Product is less than
the right Product. | |
LessThanOrEqual | Indicate whether the left Product is less than or equal to
the right Product. |
A cartesian product is a set of sets where each subset is constructed by picking one element from each of a given number of sets. This process of joining elements to form new sets is repeated until all possible distinct joins are made.
The Product class uses an array of integers as input where each integer is the size of each of the composing sets. The joined sets are represented as rows in a table where each element is a value in the range of these supplied sizes. Rows are constructed by looping thru the rightmost ranges fastest so that the resulting table is lexicographically ordered.
Use the Width property to get the number of joined elements. Use the RowCount property to get the number of distinct joins in the Product table. Use the indexer to get an element of the row. Use the default enumerator to iterate thru the elements of a Product row. Use the Permute method to rearrange a supplied list based on the values in a row.
Use the Rank property to get or set the row index in the ordered Product table of joins. Use GetRows to iterate thru all possible joins of theProduct ordered by Rank.
The default appearance of a Product row is a list of integers (starting at 0) enclosed in braces. The appearance may be tailored 3 ways:
For more information about cartesian products, see:
https://en.wikipedia.org/wiki/Cartesian_product
Iterating thru new Product (new int[] { 2, 3, 2 }).GetRows() produces:
{ 0, 0, 0 }
{ 0, 0, 1 }
{ 0, 1, 0 }
{ 0, 1, 1 }
{ 0, 2, 0 }
{ 0, 2, 1 }
{ 1, 0, 0 }
{ 1, 0, 1 }
{ 1, 1, 0 }
{ 1, 1, 1 }
{ 1, 2, 0 }
{ 1, 2, 1 }