diff --git a/2.01_BoyerMoore.ipynb b/2.01_BoyerMoore.ipynb index 440e6dd..f7647e4 100644 --- a/2.01_BoyerMoore.ipynb +++ b/2.01_BoyerMoore.ipynb @@ -23,18 +23,15 @@ " \"\"\" Use Z algorithm (Gusfield theorem 1.4.1) to preprocess s \"\"\"\n", " assert len(s) > 1\n", " z = [len(s)] + [0] * (len(s)-1)\n", - "\n", " # Initial comparison of s[1:] with prefix\n", " for i in range(1, len(s)):\n", " if s[i] == s[i-1]:\n", " z[1] += 1\n", " else:\n", " break\n", - " \n", " r, l = 0, 0\n", " if z[1] > 0:\n", " r, l = z[1], 1\n", - " \n", " for k in range(2, len(s)):\n", " assert z[k] == 0\n", " if k > r:\n", @@ -79,7 +76,6 @@ " i = len(p) - n[j]\n", " if i < len(p):\n", " lp[i] = j + 1\n", - "\n", " return lp\n", "\n", "\n", @@ -151,25 +147,22 @@ " def __init__(self, p, alphabet='ACGT'):\n", " self.p = p\n", " self.alphabet = alphabet\n", - "\n", " # Create map from alphabet characters to integers\n", " self.amap = {}\n", " for i in range(len(self.alphabet)):\n", " self.amap[self.alphabet[i]] = i\n", - "\n", " # Make bad character rule table\n", " self.bad_char = dense_bad_char_tab(p, self.amap)\n", - "\n", " # Create good suffix rule table\n", " _, self.big_l, self.small_l_prime = good_suffix_table(p)\n", - "\n", + " \n", " def bad_character_rule(self, i, c):\n", " \"\"\" Return # skips given by bad character rule at offset i \"\"\"\n", " assert c in self.amap\n", " ci = self.amap[c]\n", " assert i > (self.bad_char[i][ci]-1)\n", " return i - (self.bad_char[i][ci]-1)\n", - "\n", + " \n", " def good_suffix_rule(self, i):\n", " \"\"\" Given a mismatch at offset i, return amount to shift\n", " as determined by (weak) good suffix rule. \"\"\"\n", @@ -181,7 +174,7 @@ " if self.big_l[i] > 0:\n", " return length - self.big_l[i]\n", " return length - self.small_l_prime[i]\n", - "\n", + " \n", " def match_skip(self):\n", " \"\"\" Return amount to shift in case where P matches T \"\"\"\n", " return len(self.small_l_prime) - self.small_l_prime[1]"