Skip to content

Commit

Permalink
adding sequential, reverse and fanout funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
symonk committed Jul 22, 2024
1 parent 283d1f1 commit f8e2a1c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/analyser/analyser.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (f *FileAnalyser) Analyse() (<-chan []string, error) {
}

for _, file := range loadedFiles {
work <- func() []string { return seqScanStrategyFn(file) }
work <- func() []string { return sequentialFunc(file) }
}

go func() {
Expand Down
33 changes: 29 additions & 4 deletions internal/analyser/modes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,25 @@ import (
"github.com/symonk/log-analyse/internal/re"
)

var strategyMap = map[string]func(loadedFile LoadedFile) []string{
"sequential": seqScanStrategyFn,
type Strategy string

const (
// keys for various strategy functions
Sequential Strategy = "sequential"
Reverse Strategy = "reverse"
FanOut Strategy = "fanout"
)

var strategyMap = map[Strategy]func(loadedFile LoadedFile) []string{
Sequential: sequentialFunc,
Reverse: reverseFunc,
FanOut: fanOutFunc,
}

// seqScanStrategyFn processes a file sequentially
// sequentialFunc processes a file sequentially
// using a single thread and reports matches against
// any of it's patterns
func seqScanStrategyFn(loadedFile LoadedFile) []string {
func sequentialFunc(loadedFile LoadedFile) []string {
lines := make([]string, 0)
scanner := bufio.NewScanner(loadedFile.File)
patterns, _ := re.CompileSlice(loadedFile.Options.Patterns)
Expand All @@ -29,3 +40,17 @@ func seqScanStrategyFn(loadedFile LoadedFile) []string {
}
return lines
}

// reverseFunc traverses the file from the tail end backwards
// this is useful for finding later matches quicker.
func reverseFunc(loadedFile LoadedFile) []string {
return nil
}

// fanOutFunc takes the current lines of the file, splits it
// into chunks and spawns multiple goroutines responsible for
// a smaller subset of the file and joins all matches back
// together.
func fanOutFunc(loadedFile LoadedFile) []string {
return nil
}

0 comments on commit f8e2a1c

Please sign in to comment.