rabinkarp

package module
v0.0.0-...-79fb77d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2015 License: MIT Imports: 0 Imported by: 0

README

A golang implementation of Rabin-Karp algorithm.

Provides searching multiple patterns with an average O(n+m) time complexity (where n is the length of text and m is the combined length of pattern strings).

Installation

$ go get github.com/glkz/rabinkarp

Usage

import "github.com/glkz/rabinkarp"

func main() {
  rabinkarp.Search("the text you want to search in", []string{"the", "keywords"})
  // returns []string{"the"}
}

See GoDoc

Documentation

Overview

Package rabinkarp implements Rabin-Karp* string search algorithm.

Provides searching multiple patterns with an average O(n+m) time complexity (where n is the length of text and m is the combined length of pattern strings).

* https://en.wikipedia.org/wiki/Rabin%E2%80%93Karp_algorithm

Example
package main

import (
	"fmt"

	"github.com/glkz/rabinkarp"
)

func main() {
	txt := "a man a plan a canal panama"
	patterns := []string{"man", "boat", "plan", "ana", "banana"}
	matches := rabinkarp.Search(txt, patterns)

	fmt.Println(matches)

}
Output:

[man plan ana]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Search(txt string, patterns []string) []string

Search searches given patterns in txt and returns the matched ones. Returns empty string slice if there is no match.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL