SkillAgentSearch skills...

Kmp

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

Install / Use

/learn @kkdai/Kmp
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

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.

View on GitHub
GitHub Stars15
CategoryDevelopment
Updated1y ago
Forks4

Languages

Go

Security Score

75/100

Audited on Dec 4, 2024

No findings