Commits

Alexander Plavin  committed 54c377d

Futher optimized for one-char symbols (more than 160 M/s), 2 tests added

  • Participants
  • Parent commits 6caab71
  • Branches words-in-alphabet

Comments (0)

Files changed (2)

 
     ////////////////////////////////////////
     // fill all but last places with symbols - they will remain the same
+% if all(all(len(s) == 1 for s in alph.symbols) for alph in alphabet):
+    for (pos = 0; pos < ${len(alphabet) - 1}; pos++)
+    {
+        word_ind = n % ${alphabet[0].num if all_nums_equal else 'nums[pos]'};
+        s[pos] = ALPHABET(pos, word_ind)[0];
+        n /= ${alphabet[0].num if all_nums_equal else 'nums[pos]'};
+    }
+    len = ${len(alphabet) - 1};
+% else:
     for (pos = 0; pos < ${len(alphabet) - 1}; pos++)
     {
         word_ind = n % ${alphabet[0].num if all_nums_equal else 'nums[pos]'};
         }
         n /= ${alphabet[0].num if all_nums_equal else 'nums[pos]'};
     }
+% endif
     ////////////////////////////////////////
     lenNoLast = len;
 
     ////////////////////////////////////////
     // copy initial symbol at last position
+% if all(len(s) == 1 for s in alphabet[-1].symbols):
+    s[len] = ALPHABET_L(0)[0];
+    len++;
+% else:
     word_len = WORD_LEN_L(0);
     for (i = 0; i < word_len; i++, len++)
     {
         s[len] = ALPHABET_L(0)[i];
     }
+% endif
     ////////////////////////////////////////
 
     s[len] = 0x80;
         s[len] = 0;
 % endif
 
+% if all(len(s) == 1 for s in alphabet[-1].symbols):
+        s[len - 1] = ALPHABET_L(j + 1)[0];
+% else:
 		len = lenNoLast;
         word_len = WORD_LEN_L(j + 1);
         for (i = 0; i < word_len; i++, len++)
         {
             s[len] = ALPHABET_L(j + 1)[i];
         }
+% endif
 
 % if not last_lengths_equal:
         s[len] = 0x80;

File test_main.py

 
     def test_04(self):
         self._test('''
+        2-8
+        2-8
+        2-8
+        2-8
+        2-8
+        2-8
+        ''')
+
+    def test_05(self):
+        self._test('''
+        2-8
+        1-6
+        0-4
+        0-6
+        5-9
+        a-x
+        ''')
+
+    def test_06(self):
+        self._test('''
         04
         04
         04
         04
         ''')
 
-    def test_05(self):
+    def test_07(self):
         self._test('''
         0-6
         0-6
         0-6
         ''')
 
-    def test_06(self):
+    def test_08(self):
         self._test('''
         0-6
         0-6
         0-6
         ''')
 
-    def test_07(self):
+    def test_09(self):
         self._test('''
         0-6
         0-6
         567
         ''')
 
-    def test_08(self):
+    def test_10(self):
         self._test('''
         aa,bb,
         aa,bb,
         aa,bb,
         ''')
 
-    def test_09(self):
+    def test_11(self):
         self._test('''
         aa,bb,
         aa,bb,cc
         aa,bb,cc,dd
         ''')
 
-    def test_10(self):
+    def test_12(self):
         self._test('''
         xx,link,Link,ololo
         ed,,
         in,,
         ''')
 
-    def test_11(self):
+    def test_13(self):
         self._test(r'''
         F:\\Alexander\\pass dictionaries\\passwords\\500-worst-passwords.txt
         ''')
 
-    def test_12(self):
+    def test_14(self):
         self._test(r'''
         F:\\Alexander\\pass dictionaries\\passwords\\500-worst-passwords.txt
         F:\\Alexander\\pass dictionaries\\passwords\\500-worst-passwords.txt