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

Aho corasick #1395

Merged
merged 13 commits into from May 28, 2019
Merged

Aho corasick #1395

merged 13 commits into from May 28, 2019

Conversation

archi14
Copy link
Contributor

@archi14 archi14 commented May 25, 2019

Fixes #624

Checklist:

  • 4 space indentation.
  • Coding conventions are followed.
  • Input is taken dynamically.
  • Sample Input / Output is added at the end of file.
  • Logic Documentation (Comments).
  • File names are correct.

Changes proposed in this pull request:

  • Aho-Corasick Algorithm

Languages Used:

  • C++

Files Added:

  • Aho-Corasick c++ code

@archi14 archi14 closed this May 25, 2019
@archi14 archi14 reopened this May 25, 2019
Copy link
Contributor

@manbirmarwah manbirmarwah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes to be done then we are good to go...

Aho-Corasick/Aho-Corasick.cpp Show resolved Hide resolved
of a finite set of strings (the "dictionary") within an input text.
It matches all strings simultaneously.*/

const int MAXSTATETATE = 6 * 50 + 10;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAXSTATETATE sounds confusing/misspelled. Can you use something else in this place?

memset(out, 0, sizeof out); //intializing out with 0s
memset(fail, -1, sizeof fail); //intializing fail with -1s
memset(g, -1, sizeof g); //intializing g with -1s
int states = 1; // Initially, we just have the 0 state
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use unified indentation for comments throughout the code.

int currentState = 0;
for (int j = 0; j < keyword.size(); j++)
{
int c = keyword[j] - lowestChar;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix indentation.

{
int c = keyword[j] - lowestChar;
if (g[currentState][c] == -1)
{ // Allocate a new node
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put comment in newline.

vector<string> keywords;
cout<<"Enter the number of keywords you want to enter";
int n;
for(int i = 0; i < n; i++)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add space after for.

{
string temp;
cin >> temp;
keywords.push_back(temp);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix indentation in above 3 lines.

}
cout << "Enter text";
string text;
cin >> text;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to add space input (>>) and output (<<) operators in cin and cout statements.

if (out[currentState] == 0)
{
continue; // Nothing new, moving on to the next character.
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix indentation in above 3 lines.

for (int j = 0; j < keywords.size(); j++)
{
if (out[currentState] & (1 << j))
{ // Matched keywords[j]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put comment in newline.

@archi14
Copy link
Contributor Author

archi14 commented May 26, 2019

@marwahmanbir made the changes.

@jainaman224 jainaman224 merged commit 7b55979 into jainaman224:master May 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Aho-Corasick Algorithm in C++
3 participants