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

Add Contains() function #5

Closed
wants to merge 1 commit into from
Closed

Add Contains() function #5

wants to merge 1 commit into from

Conversation

allenluce
Copy link
Contributor

This function shortcuts the normal process of finding strings, exiting early on the first string match. This can give a practical speed-up in cases where only existence of any string matters.

@allenluce allenluce mentioned this pull request Mar 9, 2017
@client9
Copy link

client9 commented Mar 9, 2017

Hi @allenluce the only change i would make is to make the comment more "go doc/golint" friendly.

ahocorasick.go:259:1: exported method Matcher.Contains should have comment or be unexported

i.e..

// Contains returns true if any string matches.  It can be faster if you
// do not need to know which words matched.
func (m *Matcher) Contains(in []byte) bool {

I'll see if I can track down the repo owner.

@client9
Copy link

client9 commented Mar 9, 2017

Hi again @allenluce , he's on twitter with the same name @jgrahamc if you want to ping him. Github notifications aren't so great and easy for things to get lost.

@client9
Copy link

client9 commented Mar 9, 2017

FWIW: since I'm paranoid, I added a Contains check to every other existing test case, and it passed. Good work @allenluce

@allenluce
Copy link
Contributor Author

Yup. I'd done the same thing myself.

@client9
Copy link

client9 commented Mar 10, 2017

That last change might have been too aggressive @allenluce

on my box this fails:

func TestContains(t *testing.T) {
        m := NewStringMatcher([]string{"SupermanX", "per"})
        ok := m.Contains([]byte("The Man Of Steel: Superman"))
        assert(t, ok == true)
}

@client9
Copy link

client9 commented Mar 10, 2017

This function shortcuts the normal process of finding strings, exiting
early on the first string match.  This can give a practical speed-up in
cases where only existence of any string matters.

The go1.8 gofmt flattens the import statement.
@allenluce
Copy link
Contributor Author

OK. I pulled that back and squashed commits.

@allenluce
Copy link
Contributor Author

Is this something that might be merged in?

@nanmu42
Copy link

nanmu42 commented Dec 6, 2019

Hi, I find this feature very useful, I wonder what is the latest status of this PR?

@client9
Copy link

client9 commented Dec 9, 2019

hi @nanmu42 see https://github.com/signalsciences/ac the Match and MatchString does the "contains"

@jgrahamc jgrahamc closed this Apr 2, 2021
@allenluce
Copy link
Contributor Author

Is there a replacement or substitute for this?

@jgrahamc
Copy link
Contributor

jgrahamc commented Apr 2, 2021

If someone could fix the pull request to merge I'd look at it.

@allenluce allenluce mentioned this pull request Apr 2, 2021
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

Successfully merging this pull request may close these issues.

None yet

4 participants