Skip to content
/ kmp Public

KMP (Knuth–Morris–Pratt algorithm) implement and related string function `Strstr` and `Strchr` in Golang

License

Notifications You must be signed in to change notification settings

kkdai/kmp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KMP

GitHub license GoDoc Build Status

This is a KMP(Knuth–Morris–Pratt algorithm) implement and related string function Strstr and Strchr which using KMP feature inside.

In computer science, the Knuth–Morris–Pratt string searching algorithm (or KMP algorithm) searches for occurrences of a "word" W within a main "text string" S by employing the observation that when a mismatch occurs, the word itself embodies sufficient information to determine where the next match could begin, thus bypassing re-examination of previously matched characters.

A chinese version How KMP work note is here

Install

go get github.com/kkdai/kmp

Usage

package main

import (
	"fmt"
	
	"github.com/kkdai/kmp"
)

func main() {
	
	//Using KMP
	fmt.Println(KMP("co", "cocacola"))
	//0, 4
	
	//Using Strstr
	fmt.Println(Strstr("cocacola", "co"))
	//0
	
	//Using Strchr
	fmt.Println(Strstr("cocacola", "co"))
	//4
}	

Inspired

Project52

It is one of my project 52.

License

This package is licensed under MIT license. See LICENSE for details.

About

KMP (Knuth–Morris–Pratt algorithm) implement and related string function `Strstr` and `Strchr` in Golang

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages