Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typo in sa_lcp.py #73

Open
projectPythonator opened this issue Aug 6, 2020 · 2 comments
Open

typo in sa_lcp.py #73

projectPythonator opened this issue Aug 6, 2020 · 2 comments

Comments

@projectPythonator
Copy link

in this file it does not seem that we are using globals so in this code m is missing as a parameter (n is also missing but in main its defined as just len of the string)
def longest_common_substring(sa, lcp):
idx = 0
max_lcp = -1
for i in range(1, n):
if (sa[i] < m) != (sa[i-1] < m) and lcp[i] > lcs:
max_lcp = lcp[i]
idx = i
return (max_lcp, idx)

@projectPythonator
Copy link
Author

sorry for the bad formatting idk how to link the file with line https://github.com/stevenhalim/cpbook-code/blob/master/ch6/sa_lcp.py

@howsiwei
Copy link
Collaborator

howsiwei commented Aug 8, 2020

You're right that m is missing as a parameter. Same for n but it can be deduced from len(sa). Also lcs should be changed to max_lcp or vice versa.

To show specific line see https://docs.github.com/en/github/managing-your-work-on-github/creating-a-permanent-link-to-a-code-snippet. In this case it's

https://github.com/stevenhalim/cpbook-code/blob/0ba81b4c31519f1109a147063dbca0a7bfa17c91/ch6/sa_lcp.py#L88-L96

which would be rendered as

# returns a pair (the LCS length and its index)
def longest_common_substring(sa, lcp):
idx = 0
max_lcp = -1
for i in range(1, n):
if (sa[i] < m) != (sa[i-1] < m) and lcp[i] > lcs:
max_lcp = lcp[i]
idx = i
return (max_lcp, idx)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants