Debian Codegraph @

internal/words/search.go

raw symbols SCIP
1 package wordsscip-go gomod github.com/betterleaks/betterleaks . `github.com/betterleaks/betterleaks/internal/words`/
2
3 import (
4 "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/"
5 )
6
7 type Resultscip-go gomod github.com/betterleaks/betterleaks . `github.com/betterleaks/betterleaks/internal/words`/Result# struct {
8 WordCountscip-go gomod github.com/betterleaks/betterleaks . `github.com/betterleaks/betterleaks/internal/words`/Result#WordCount. int
9 UniqueWordsscip-go gomod github.com/betterleaks/betterleaks . `github.com/betterleaks/betterleaks/internal/words`/Result#UniqueWords. []string
10 Matchesscip-go gomod github.com/betterleaks/betterleaks . `github.com/betterleaks/betterleaks/internal/words`/Result#Matches. []Matchscip-go gomod github.com/betterleaks/betterleaks . `github.com/betterleaks/betterleaks/internal/words`/Match#
11 }
12
13 type Matchscip-go gomod github.com/betterleaks/betterleaks . `github.com/betterleaks/betterleaks/internal/words`/Match# struct {
14 Wordscip-go gomod github.com/betterleaks/betterleaks . `github.com/betterleaks/betterleaks/internal/words`/Match#Word. string
15 Lenscip-go gomod github.com/betterleaks/betterleaks . `github.com/betterleaks/betterleaks/internal/words`/Match#Len. int
16 }
17
18 // HasMatchInList finds all dictionary words that appear as substrings of word,
19 // matching Aho-Corasick–style behavior by walking the word: at each starting
20 // position we check every substring length >= minLen. Returns one Result
21 // aggregating all matches, or nil if none.
22 func HasMatchInListscip-go gomod github.com/betterleaks/betterleaks . `github.com/betterleaks/betterleaks/internal/words`/HasMatchInList().(word string, minLen int) []Resultscip-go gomod github.com/betterleaks/betterleaks . `github.com/betterleaks/betterleaks/internal/words`/Result# {
23 // Trigger the lazy load. sync.Once guarantees this is thread-safe and
24 // only executes the decompression once, even with thousands of goroutines.
25 wordsOncescip-go gomod github.com/betterleaks/betterleaks . `github.com/betterleaks/betterleaks/internal/words`/wordsOnce..Doscip-go gomod github.com/golang/go/src go1.25.0 sync/Once#Do().(loadWordsscip-go gomod github.com/betterleaks/betterleaks . `github.com/betterleaks/betterleaks/internal/words`/loadWords().)
26
27 word = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.0 strings/ToLower().(word)
28 if len(word) < minLen {
29 return nil
30 }
31
32 var matches []Matchscip-go gomod github.com/betterleaks/betterleaks . `github.com/betterleaks/betterleaks/internal/words`/Match#
33 seen := make(map[string]struct{})
34
35 // Walk the word: at each start position, try every substring length >= minLen
36 for start := 0; start <= len(word)-minLen; start++ {
37 for length := minLen; start+length <= len(word); length++ {
38 sub := word[start : start+length]
39 if _, exists := nltkWordsscip-go gomod github.com/betterleaks/betterleaks . `github.com/betterleaks/betterleaks/internal/words`/nltkWords.[sub]; exists {
40 if _, ok := seen[sub]; !ok {
41 seen[sub] = struct{}{}
42 }
43 matches = append(matches, Matchscip-go gomod github.com/betterleaks/betterleaks . `github.com/betterleaks/betterleaks/internal/words`/Match#{Wordscip-go gomod github.com/betterleaks/betterleaks . `github.com/betterleaks/betterleaks/internal/words`/Match#Word.: sub, Lenscip-go gomod github.com/betterleaks/betterleaks . `github.com/betterleaks/betterleaks/internal/words`/Match#Len.: length})
44 }
45 }
46 }
47
48 if len(matches) == 0 {
49 return nil
50 }
51
52 uniqueWords := make([]string, 0, len(seen))
53 for w := range seen {
54 uniqueWords = append(uniqueWords, w)
55 }
56
57 return []Resultscip-go gomod github.com/betterleaks/betterleaks . `github.com/betterleaks/betterleaks/internal/words`/Result#{{
58 WordCountscip-go gomod github.com/betterleaks/betterleaks . `github.com/betterleaks/betterleaks/internal/words`/Result#WordCount.: len(matches),
59 UniqueWordsscip-go gomod github.com/betterleaks/betterleaks . `github.com/betterleaks/betterleaks/internal/words`/Result#UniqueWords.: uniqueWords,
60 Matchesscip-go gomod github.com/betterleaks/betterleaks . `github.com/betterleaks/betterleaks/internal/words`/Result#Matches.: matches,
61 }}
62 }