Giter Site home page Giter Site logo

cpp-string-matching's Introduction

String Matching in C++

Introduction

This is a very simple string matching algorithm written in C++ that uses a finite state machine and a trie to do the matching. Furthermore this is only a weekend project that I hacked on some time ago and never published it, until now.

String Matching Algorithm

This implementation is based on the original paper published on 1975.

I am using the BFS (Breadth First Search) strategy when building the failures for the string matching index, so I am visiting the neighbours before visiting the child nodes using a queue as presented in the original paper.

How the string matching is being performed is best represented in the diagram below taken from the slides by Pekka Kilpeläinen

aho-corasick

Trie

You'll find the simplest Trie implementation.

Trie has an ordered tree data structure so in our case it will keep adding characters until it reaches the end of the string that we passed. In the end our tree will look like the diagram below for strings like corvo, hey, his and hers, that's my goal for now but I will keep changing it. You can check the usage in the main.cpp file.

Trie diagram is taken from the same slides as the Aho Corasick diagram.

trie

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.