Optimize numberOfPermutations
authorMatthew Daiter <mdaiter8121@gmail.com>
Wed, 22 May 2019 21:14:13 +0000 (17:14 -0400)
committerMatthew Daiter <mdaiter8121@gmail.com>
Wed, 22 May 2019 21:29:50 +0000 (17:29 -0400)
libs/subcircuit/subcircuit.cc

index 7c7236833ae7c53821fd568b842e4c575dbbb912..e8361a67e873d0e8a536c710cfc8f8dd1aab0214 100644 (file)
@@ -320,12 +320,10 @@ class SubCircuit::SolverWorker
 
        static int numberOfPermutations(const std::vector<std::string> &list)
        {
-               int numPermutations = 1;
-               for (int i = 0; i < int(list.size()); i++) {
-                       assert(numPermutations < maxPermutationsLimit);
-                       numPermutations *= i+1;
-               }
-               return numPermutations;
+               constexpr size_t mappedPermutationsSize = 10;
+               constexpr int mappedPermutations[mappedPermutationsSize] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880};
+               assert(list.size() < mappedPermutationsSize);
+               return mappedPermutations[list.size()];
        }
 
        static void permutateVectorToMap(std::map<std::string, std::string> &map, const std::vector<std::string> &list, int idx)