{"id":15599690,"url":"https://github.com/tanvir002700/kmp","last_synced_at":"2026-04-29T18:33:50.739Z","repository":{"id":56880257,"uuid":"119430789","full_name":"tanvir002700/kmp","owner":"tanvir002700","description":"A string matching algorithm wants to find the starting index m in string S, that matches the search word W.","archived":false,"fork":false,"pushed_at":"2018-02-20T13:15:11.000Z","size":793,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-13T09:55:11.730Z","etag":null,"topics":["c","c-extension","kmp","knuth-morris-pratt","ruby"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/kmp","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tanvir002700.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-29T19:31:09.000Z","updated_at":"2018-02-26T18:12:06.000Z","dependencies_parsed_at":"2022-08-20T22:31:25.289Z","dependency_job_id":null,"html_url":"https://github.com/tanvir002700/kmp","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanvir002700%2Fkmp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanvir002700%2Fkmp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanvir002700%2Fkmp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanvir002700%2Fkmp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tanvir002700","download_url":"https://codeload.github.com/tanvir002700/kmp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246180922,"owners_count":20736460,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","c-extension","kmp","knuth-morris-pratt","ruby"],"created_at":"2024-10-03T02:00:38.417Z","updated_at":"2026-04-29T18:33:45.717Z","avatar_url":"https://github.com/tanvir002700.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kmp\n[![Build Status](https://travis-ci.org/tanvir002700/kmp.svg?branch=master)](https://travis-ci.org/tanvir002700/kmp)\n[![Maintainability](https://api.codeclimate.com/v1/badges/69f40101eeb294c05163/maintainability)](https://codeclimate.com/github/tanvir002700/kmp/maintainability)\n[![Coverage Status](https://coveralls.io/repos/github/tanvir002700/kmp/badge.svg?branch=master)](https://coveralls.io/github/tanvir002700/kmp?branch=master)\n[![Gem Version](https://badge.fury.io/rb/kmp.svg)](https://badge.fury.io/rb/kmp)\n[![Downloads](https://img.shields.io/gem/dt/kmp.svg)](https://rubygems.org/gems/kmp)\n[![GitHub last commit (branch)](https://img.shields.io/github/last-commit/tanvir002700/kmp/master.svg)](https://github.com/tanvir002700/kmp)\n[![license](https://img.shields.io/github/license/tanvir002700/kmp.svg)](https://github.com/tanvir002700/kmp/blob/master/LICENSE)\n\nThis gem is KMP (Knuth–Morris–Pratt algorithm) implemantation with c Extension.\nA super first substring find technique in a big string.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'kmp'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install kmp\n\n## Usage\n\n``` ruby\nrequire 'kmp'\nk = Kmp::String.new 'abcdeab'\nk.match 'ab' #=\u003e [0, 5]\n\nk.length #=\u003e 7\n\nk.replace 'ab', 'X' #=\u003e 'XcdeX'\n```\n\n## Complexity\n\n- match function complexity O(N+M), N original text string length, M match string length\n- replace function complexity O(N+M)\n- length complexity O(1)\n\n## Benchmark\nThis benchmark between kmp implementation in c-extenstion vs pure ruby. [Benchmark](http://ruby-doc.org/stdlib-2.0.0/libdoc/benchmark/rdoc/Benchmark.html) module use for comparison.\n\n```\nlenght of string: 500\nRehearsal -----------------------------------------------\nc-extension   0.000000   0.000000   0.000000 (  0.000028)\nruby          0.000000   0.000000   0.000000 (  0.001067)\n-------------------------------------- total: 0.000000sec\n\n                  user     system      total        real\nc-extension   0.000000   0.000000   0.000000 (  0.000019)\nruby          0.000000   0.000000   0.000000 (  0.000731)\n\nlenght of string: 5000\nRehearsal -----------------------------------------------\nc-extension   0.000000   0.000000   0.000000 (  0.000074)\nruby          0.000000   0.000000   0.000000 (  0.006990)\n-------------------------------------- total: 0.000000sec\n\n                  user     system      total        real\nc-extension   0.000000   0.000000   0.000000 (  0.000059)\nruby          0.000000   0.000000   0.000000 (  0.003058)\n\nlenght of string: 50000\nRehearsal -----------------------------------------------\nc-extension   0.000000   0.000000   0.000000 (  0.000276)\nruby          0.030000   0.000000   0.030000 (  0.022061)\n-------------------------------------- total: 0.030000sec\n\n                  user     system      total        real\nc-extension   0.000000   0.000000   0.000000 (  0.000117)\nruby          0.010000   0.000000   0.010000 (  0.014624)\n\nlenght of string: 500000\nRehearsal -----------------------------------------------\nc-extension   0.000000   0.000000   0.000000 (  0.001346)\nruby          0.140000   0.000000   0.140000 (  0.147500)\n-------------------------------------- total: 0.140000sec\n\n                  user     system      total        real\nc-extension   0.000000   0.000000   0.000000 (  0.001188)\nruby          0.140000   0.000000   0.140000 (  0.146642)\n\nlenght of string: 5000000\nRehearsal -----------------------------------------------\nc-extension   0.010000   0.000000   0.010000 (  0.013171)\nruby          1.480000   0.010000   1.490000 (  1.482893)\n-------------------------------------- total: 1.500000sec\n\n                  user     system      total        real\nc-extension   0.010000   0.000000   0.010000 (  0.013098)\nruby          1.510000   0.000000   1.510000 (  1.508361)\n\nlenght of string: 50000000\nRehearsal -----------------------------------------------\nc-extension   0.120000   0.020000   0.140000 (  0.143160)\nruby         16.320000   0.020000  16.340000 ( 16.356332)\n------------------------------------- total: 16.480000sec\n\n                  user     system      total        real\nc-extension   0.120000   0.010000   0.130000 (  0.143203)\nruby         15.130000   0.050000  15.180000 ( 15.191924)\n\nlenght of string: 500000000\nRehearsal -----------------------------------------------\nc-extension   1.190000   0.200000   1.390000 (  1.491211)\nruby        159.510000   0.210000 159.720000 (159.723059)\n------------------------------------ total: 161.110000sec\n\n                  user     system      total        real\nc-extension   1.270000   0.200000   1.470000 (  1.568321)\nruby        161.190000   0.250000 161.440000 (161.449839)\n\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. For compile c extension run `rake compile`.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/tanvir002700/kmp. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Kmp project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/tanvir002700/kmp/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanvir002700%2Fkmp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftanvir002700%2Fkmp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanvir002700%2Fkmp/lists"}