• Stars
    star
    240
  • Rank 162,576 (Top 4 %)
  • Language
    Rust
  • License
    MIT License
  • Created about 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fuzzy Matching Library for Rust

Crates.io

Fuzzy Matcher

Fuzzy matching algorithm(s) in Rust!

Usage

In your Cargo.toml add the following:

[dependencies]
fuzzy-matcher = "*"

Here are some code example:

use fuzzy_matcher::FuzzyMatcher;
use fuzzy_matcher::skim::SkimMatcherV2;

let matcher = SkimMatcherV2::default();
assert_eq!(None, matcher.fuzzy_match("abc", "abx"));
assert!(matcher.fuzzy_match("axbycz", "abc").is_some());
assert!(matcher.fuzzy_match("axbycz", "xyz").is_some());

let (score, indices) = matcher.fuzzy_indices("axbycz", "abc").unwrap();
assert_eq!(indices, [0, 2, 4]);
  • fuzzy_match only return scores while fuzzy_indices returns the matching indices as well.
  • Both function return None if the pattern won't match.
  • The score is the higher the better.

More example

echo "axbycz" | cargo run --example fz "abc" and check what happens.

About the Algorithm

Skim

The skim is currently used by skim, a fuzzy finder.

Skim V2

  • Just like fzf v2, the algorithm is based on Smith-Waterman algorithm which is normally used in DNA sequence alignment
  • Also checkout https://www.cs.cmu.edu/~ckingsf/bioinfo-lectures/gaps.pdf for more details
  • The time complexity is O(mn) where m, n are the length of the pattern and input line.
  • Space complexity is O(mn) for fuzzy_indices and O(2n) for fuzzy_match which will compress the table for dynamic programming.
  • V2 matcher has an option to set the max element of the score matrix, if m*n exceeded the limit, it will fallback to a linear search.

Skim V1

Clangd

  • The algorithm is based on clangd's FuzzyMatch.cpp.
  • Also checkout lewang/flx#98 for some variants.
  • The algorithm is O(mn) where m, n are the length of the pattern and input line.
  • Space complexity is O(mn) for fuzzy_indices and O(2n) for fuzzy_match which will compress the table for dynamic programming.

More Repositories

1

skim

Fuzzy Finder in rust!
Rust
4,856
star
2

write-a-C-interpreter

Write a simple interpreter of C. Inspired by c4 and largely based on it.
C
3,825
star
3

rargs

xargs + awk with pattern matching support. `ls *.bak | rargs -p '(.*)\.bak' mv {0} {1}`
Rust
462
star
4

Let-s-build-a-compiler

A C & x86 version of the "Let's Build a Compiler" by Jack Crenshaw
C
455
star
5

very-simple

A very simple theme for hexo
SCSS
149
star
6

skim.vim

vim support for skim
Vim Script
133
star
7

tuikit

Tool kit for writing TUI applications in Rust.
Rust
103
star
8

hexo-theme-noise

A hexo theme
Less
100
star
9

CodeGenerator

Intellij IDEA Plugin for creating customized code generators like the builtin toString, equals, etc.
Java
49
star
10

spring-security-example

REST authentication apis & token based authentication, etc.
Java
32
star
11

transformer-playground

Annotation processor @Transform for creating transformers for classes.
Java
16
star
12

pymustache

Mustache template engine from scratch in Python.
Python
16
star
13

static-wiki

CSS
14
star
14

SlackGuide-cn

A chinese guide for slackware based on SlackBook.
11
star
15

dotfiles

Manage the resource files under home folder
Emacs Lisp
8
star
16

lotabout.github.io

My personal blog. (source at source branch)
C++
8
star
17

buddy-system

Simple implementation of a buddy system for memory management.
C
8
star
18

orgwiki

personal wiki generated by org-mode
CSS
8
star
19

compiler-design-in-c

Codes for book <compiler design in C>
C
6
star
20

ywvim

a fork of ywvim. http://www.vim.org/scripts/script.php?script_id=2662
Vim Script
6
star
21

vimwiki-tpl

template for vimwiki
CSS
5
star
22

project-euler-racket

Project Euler in racket.
Racket
5
star
23

axe

Handy utilities for racket
Racket
5
star
24

simple-template-engine

A simple template engine written in python
Python
5
star
25

mdbook-fix-cjk-spacing

mdbook preprocessor that removes extra space rendered for Chinese lines.
Rust
4
star
26

c-interfaces

codes for book "C Interfaces and Implementation Techniques".
C
4
star
27

underscore-comment

Read and Comment on source code of underscore.js
JavaScript
3
star
28

hexo-filter-fix-cjk-spacing

Join continuous CJK lines in markdown in Hexo.
JavaScript
3
star
29

simple-framework

A simple python web framework from scratch
Python
3
star
30

jasypt-online

Jasypt 在线加解密工具
HTML
2
star
31

nikola-bnw

A nikola theme.
CSS
2
star
32

zzz

theme for nikola
CSS
2
star
33

ideas

log for new ideas and the execution of ideas
2
star
34

cup

A small web framework for racket
Racket
2
star
35

learn-c-the-hard-way

code & exercise reading book <Learn C the hard way>
C
2
star
36

curtail

pipe stdin to a fixed-size log file
Rust
2
star
37

build-your-own-pytorch

Understand deep learning framework(like torch) by implementing the essentials
Python
2
star
38

zlex

A lexical analyzer generator.
C
2
star
39

pymkd

Markdown in python
Python
1
star
40

cljs-douban

douban.fm in CLJS+Electron
Clojure
1
star
41

lemon

Lemon parser generator (http://www.hwaci.com/sw/lemon/). Submit for code review for study purpose.
C
1
star
42

code-snippets

collection of useful code snippets.
C
1
star
43

my-time

A time management web application written in clojure with luminus.
Clojure
1
star
44

cljs-douban-reframe

douban.fm in CLJS+Electron+Re-frame
Clojure
1
star
45

my-slackbuilds

My slackware build scripts
Shell
1
star
46

pscat

socat in one python file
Python
1
star
47

orgmark.vim

Vim Script
1
star
48

docker-slackware

Build slackware images for docker
1
star
49

LiSP

Codes for book "Lisp in Small Pieces"
Scheme
1
star
50

java-spi-playground

A simple expression interpreter that use SPI to load user-customized functions
Java
1
star
51

dragon-book-notes

Notes reading the Dragon Book.
C
1
star
52

dwm

My own customization of dwm, starting with dwm-6.0.
C
1
star