/// <summary> /// Construct a enumerator with the parent object. /// </summary> /// <param name="source">The source Permutations object.</param> public Enumerator(Permutations <T> source) { myParent = source; myLexicographicalOrders = new int[source.myLexicographicOrders.Length]; source.myLexicographicOrders.CopyTo(myLexicographicalOrders, 0); Reset(); }
/// <summary> /// Initialize the combinations by settings a copy of the values from the /// </summary> /// <param name="values">List of values to select combinations from.</param> /// <param name="lowerIndex">The size of each combination set to return.</param> /// <param name="type">The type of Combinations set to generate.</param> /// <remarks> /// Copies the array and parameters and then creates a map of booleans that will /// be used by a permutations object to refence the subset. This map is slightly /// different based on whether the type is with or without repetition. /// /// When the type is WithoutRepetition, then a map of upper index elements is /// created with lower index false's. /// E.g. 8 choose 3 generates: /// Map: {1 1 1 1 1 0 0 0} /// Note: For sorting reasons, false denotes inclusion in output. /// /// When the type is WithRepetition, then a map of upper index - 1 + lower index /// elements is created with the falses indicating that the 'current' element should /// be included and the trues meaning to advance the 'current' element by one. /// E.g. 8 choose 3 generates: /// Map: {1 1 1 1 1 1 1 1 0 0 0} (7 trues, 3 falses). /// </remarks> private void Initialize(IList <T> values, int lowerIndex, GenerateOption type) { myMetaCollectionType = type; myLowerIndex = lowerIndex; myValues = new List <T>(); myValues.AddRange(values); var myMap = new List <bool>(); if (type == GenerateOption.WithoutRepetition) { for (var i = 0; i < myValues.Count; ++i) { if (i >= myValues.Count - myLowerIndex) { myMap.Add(false); } else { myMap.Add(true); } } } else { for (var i = 0; i < values.Count - 1; ++i) { myMap.Add(true); } for (var i = 0; i < myLowerIndex; ++i) { myMap.Add(false); } } myPermutations = new Permutations <bool>(myMap); }
/// <summary> /// Initialize the variations for constructors. /// </summary> /// <param name="values">List of values to select variations from.</param> /// <param name="lowerIndex">The size of each variation set to return.</param> /// <param name="type">The type of variations set to generate.</param> private void Initialize(IList <T> values, int lowerIndex, GenerateOption type) { myMetaCollectionType = type; myLowerIndex = lowerIndex; myValues = new List <T>(); myValues.AddRange(values); if (type == GenerateOption.WithoutRepetition) { var myMap = new List <int>(); var index = 0; for (var i = 0; i < myValues.Count; ++i) { if (i >= myValues.Count - myLowerIndex) { myMap.Add(index++); } else { myMap.Add(Int32.MaxValue); } } myPermutations = new Permutations <int>(myMap); } else { ; // myPermutations isn't used. } }