Skip to content

Instantly share code, notes, and snippets.

@jdmichaud
Created June 26, 2017 20:00
Show Gist options
  • Save jdmichaud/ca8a664fad95625e5fca5e8647d88fb4 to your computer and use it in GitHub Desktop.
Save jdmichaud/ca8a664fad95625e5fca5e8647d88fb4 to your computer and use it in GitHub Desktop.
Pseudo code
seek enf of file to get the size
define Find message:
if (size of file - current offset) is smaller than size of "From:",
memcopy the last (size of file - current offset) characters at the beginning of the buffer and load
(size of buffer - ((size of file - current offset)) into the buffer
Look at the (current offset + lenght of "From:" - 1)th character in the buffer, if it is :, check previous, if it is m, check previous, etc...
If not, check if
def boyer-moore(str, substr):
lstr - len(str)
lsubstr = len(substr)
current = lsubstr - 1
# As long as our current offset is within the string
while (current < lstr):
# Read the substring backward
offset = 0
while (str[current - offset] == substr[lsubstr - offset] and offset <= lsubstr): ++offset;
if (offset == lsubstr and str[current - offset] == substr[lsubstr - offset]):
# found match
return current - offset
if (offset < lsubstr):
failing_char_index = lsubstr - offset
# Didn't found a match, see if a letter in the substring match the failing letter in the string
--offset
while (str[current - offset] != substr[failing_char_index] and offset <= lsubstr): --offset
if str[current - offset] == substr[failing_char_index]:
# If we found a matching letter in the substring that matches the failing character
# Shift the pattern to match those two together
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment