Skip to content

Raaaaaaaay86/ahocorasick

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ahocorasick

A Go implementation of the Aho-Corasick multiple pattern string search algorithm.

Features

  • Supports searching for multiple keywords simultaneously
  • Trie structure with automatic fail link construction
  • Find all matches or the longest match
  • Unicode support

Installation

go get github.com/raaaaaaaay86/ahocorasick

Usage Example

package main

import (
	"fmt"
	"github.com/raaaaaaaay86/ahocorasick"
)

func main() {
	dictionary := []string{"hello", "world", "hell", "helloworld", "hellow"}
	trie := ahocorasick.NewTrie(dictionary)
	matches := trie.FindAllMatches("helloworld")
	for _, m := range matches {
		fmt.Println(m)
	}
}

Testing

go test -v

File Structure

  • trie.go: Main trie structure and construction logic
  • node.go: Trie node and matching logic
  • trie_test.go: Unit tests

Reference

About

Aho–Corasick algorithm implemented in Go.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages