/// <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();
 }
Beispiel #2
0
        /// <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 reference 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 values.
        /// 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 false values 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 true, 3 false).
        /// </remarks>
        private void Initialize(ICollection <T> values, int lowerIndex, GenerateOption type)
        {
            Type         = 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);
        }