项目作者: fbonhomm

项目描述 :
[EN] Implementation of the Knuth-Morris-Pratt algorithm / [FR] Implémentation de l'algorithme Knuth-Morris-Pratt
高级语言: Go
项目地址: git://github.com/fbonhomm/knuth-morris-pratt.git
创建时间: 2019-09-28T13:08:58Z
项目社区:https://github.com/fbonhomm/knuth-morris-pratt

开源协议:MIT License

下载


License: MIT
CI

Knuth-Morris-Pratt Algorithm

[EN]
Implementation of the Knuth-Morris-Pratt algorithm or KMP algorithm in GO.

Knuth-Morris-Pratt is a substring search algorithm.

[FR]
Implémentation de l’algorithme de Knuth-Morris-Pratt ou l’algorithme KMP en Go.

Knuth-Morris-Pratt est un algorithme de recherche de sous-chaîne.

Technology

Usage

CLI:

  1. go test -v test/

CODE:

  1. import kmp "github.com/fbonhomm/knuth-morris-pratt/source"
  2. var index, length int
  3. var buffer = []byte("abc abcdab abcdabcdabde")
  4. var pattern = []byte("abcdabd") // 7
  5. var pattern1 = []byte("abcdabdr") // 8
  6. index = kmp.Search(buffer, pattern) // 15
  7. index = kmp.Search(buffer, pattern1) // -1

Explanations

https://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm
https://dev.to/girish3/string-matching-kmp-algorithm-cie
https://www.geeksforgeeks.org/kmp-algorithm-for-pattern-searching/