Esempio n. 1
0
        public static OptimalType GetLeastTypeForAllSubcases(int numItems, int groupSize)
        {
            // This method returns the least type that will be able to handle all subcases without overflowing.
            //
            // n choose (n / 2) is the worst subcase that generates the most combinations.
            // So, if numItems is twice or more groupSize, then there is no subcase that will increase the number of combos.
            //
            BigInteger  numCombos;
            OptimalType returnValue;

            if (numItems >= groupSize + groupSize)
            {
                numCombos = Combination.GetNumCombos(numItems, groupSize);
            }
            else
            {
                numCombos = Combination.GetNumCombosBigInt(numItems, numItems / 2);
            }
            // If overflowed ulong, then only big int will work with all subtypes.
            if (numCombos > ulong.MaxValue)
            {
                returnValue = OptimalType.BigInt;
            }
            else if (numCombos <= uint.MaxValue)
            {
                returnValue = OptimalType.UnsignedInt;
            }
            else
            {
                returnValue = OptimalType.UnsignedLong;
            }
            return(returnValue);
        }
Esempio n. 2
0
        public static OptimalType GetLeastTypeForCase(int numItems, int groupSize)
        {
            // This method returns the least type that can handle all ranks for the case of numItems choose groupSize.
            //
            OptimalType returnValue;
            BigInteger  numCombos = Combination.GetNumCombosBigInt(numItems, groupSize);

            // If overflowed ulong, then only big int will work with this case.
            if (numCombos > ulong.MaxValue)
            {
                returnValue = OptimalType.BigInt;
            }
            else if (numCombos <= uint.MaxValue)
            {
                returnValue = OptimalType.UnsignedInt;
            }
            else
            {
                returnValue = OptimalType.UnsignedLong;
            }
            return(returnValue);
        }