コード例 #1
0
ファイル: Combinations.cs プロジェクト: vnmone/vvvv-sdk
        /// <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);
            List <bool> myMap = new List <bool>();

            if (type == GenerateOption.WithoutRepetition)
            {
                for (int i = 0; i < myValues.Count; ++i)
                {
                    if (i >= myValues.Count - myLowerIndex)
                    {
                        myMap.Add(false);
                    }
                    else
                    {
                        myMap.Add(true);
                    }
                }
            }
            else
            {
                for (int i = 0; i < values.Count - 1; ++i)
                {
                    myMap.Add(true);
                }
                for (int i = 0; i < myLowerIndex; ++i)
                {
                    myMap.Add(false);
                }
            }
            myPermutations = new Permutations <bool>(myMap);
        }
コード例 #2
0
 /// <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)
     {
         List <int> myMap = new List <int>();
         int        index = 0;
         for (int 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.
     }
 }
コード例 #3
0
 /// <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();
 }
コード例 #4
0
ファイル: Combinations.cs プロジェクト: GarryBob/codekatas
        /// <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(IEnumerable <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)
            {
                myMap.AddRange(_myValues.Select((t, i) => i < _myValues.Count - _myLowerIndex));
            }
            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);
        }
コード例 #5
0
 /// <summary>
 /// Construct a enumerator with the parent object.
 /// </summary>
 /// <param name="source">The source Permutations object.</param>
 public Enumerator(Permutations <T> source)
 {
     _         = source ?? throw new ArgumentNullException(nameof(source));
     _myParent = source;
     _myLexicographicalOrders = new int[source._myLexicographicOrders.Length];
     _myValues = new List <T>(source._myValues.Count);
     source._myLexicographicOrders.CopyTo(_myLexicographicalOrders, 0);
     _myPosition = Position.BeforeFirst;
 }
コード例 #6
0
        /// <summary>
        /// Create a combination set from the provided list of values.
        /// The upper index is calculated as values.Count, the lower index is specified.
        /// </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>
        public Combinations(IEnumerable <T> values, int lowerIndex, GenerateOption type)
        {
            _ = values ?? throw new ArgumentNullException(nameof(values));

            // Copy the array and parameters and then create 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'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).

            Type       = type;
            LowerIndex = lowerIndex;
            _myValues  = values.ToList();
            List <bool> myMap;

            if (type == GenerateOption.WithoutRepetition)
            {
                myMap = new List <bool>(_myValues.Count);
                myMap.AddRange(_myValues.Select((t, i) => i < _myValues.Count - LowerIndex));
            }
            else
            {
                myMap = new List <bool>(_myValues.Count + LowerIndex - 1);
                for (var i = 0; i < _myValues.Count - 1; ++i)
                {
                    myMap.Add(true);
                }
                for (var i = 0; i < LowerIndex; ++i)
                {
                    myMap.Add(false);
                }
            }

            _myPermutations = new Permutations <bool>(myMap);
        }
コード例 #7
0
        /// <summary>
        /// Create a variation set from the indicated list of values.
        /// The upper index is calculated as values.Count, the lower index is specified.
        /// </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">Type indicates whether to use repetition in set generation.</param>
        public Variations(IEnumerable <T> values, int lowerIndex, GenerateOption type)
        {
            Type       = type;
            LowerIndex = lowerIndex;
            _myValues  = values.ToList();

            if (type != GenerateOption.WithoutRepetition)
            {
                return;
            }

            var myMap = new List <int>(_myValues.Count);
            var index = 0;

            for (var i = 0; i < _myValues.Count; ++i)
            {
                myMap.Add(i >= _myValues.Count - LowerIndex ? index++ : int.MaxValue);
            }

            _myPermutations = new Permutations <int>(myMap);
        }
コード例 #8
0
ファイル: Variations.cs プロジェクト: berktoprakci/appveyor
        /// <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(IEnumerable <T> values, int lowerIndex, GenerateOption type)
        {
            Type       = type;
            LowerIndex = lowerIndex;
            _myValues  = new List <T>();
            _myValues.AddRange(values);

            if (type != GenerateOption.WithoutRepetition)
            {
                return;
            }

            var myMap = new List <int>();
            var index = 0;

            for (var i = 0; i < _myValues.Count; ++i)
            {
                myMap.Add(i >= _myValues.Count - LowerIndex ? index++ : int.MaxValue);
            }

            _myPermutations = new Permutations <int>(myMap);
        }