2 releases

Uses old Rust 2015

0.1.1 Jul 23, 2016
0.1.0 Jul 23, 2016

#16 in #ngrams

Download history 154/week @ 2024-07-22 279/week @ 2024-07-29 205/week @ 2024-08-05 192/week @ 2024-08-12 142/week @ 2024-08-19 313/week @ 2024-08-26 300/week @ 2024-09-02 361/week @ 2024-09-09 261/week @ 2024-09-16 222/week @ 2024-09-23 282/week @ 2024-09-30 230/week @ 2024-10-07 249/week @ 2024-10-14 157/week @ 2024-10-21 197/week @ 2024-10-28 231/week @ 2024-11-04

850 downloads per month
Used in 3 crates (via gaoya)

MIT license

15KB
278 lines

shingles.rs

License

Shingles implementation in rust

See docs (0.1 / master)

Overview

Shingles is a crate for constructing shingles ("tokenizing") from slices and utf-8 strings. It was primary created to use in fuzzy matching algorithms like minhash or similar.

Examples

extern crate shingles;

use shingles::AsShingles;

fn main() {
    let v = [1, 2, 3, 4];
    let mut num_sh = v.as_shingles(3);
    let mut str_sh = "привет!".as_shingles_with_step(4, 2);
    
    assert_eq!(Some(&v[0..3]), num_sh.next());
    assert_eq!(Some(&v[1..4]), num_sh.next());
    
    assert_eq!(Some("прив"), str_sh.next());
    assert_eq!(Some("ивет"), str_sh.next());
    
    for h in "привет!".as_shingles(4).hashes() {
        // prints hash for each shingle
        println!("{}", h);
    }
}

2D shingle examples

extern crate shingles;

use shingles::AsShingles2D;

fn main() {
    let v: Vec<_> = "abcd\n\
                     efgh\n\
                     ijkl"
        .split_terminator("\n")
        .collect();

    let mut sh_2d = v.as_shingles_2d([3, 3]);

    assert_eq!(
        Some(vec![&v[0][0..3], &v[1][0..3], &v[2][0..3]]),
        sh_2d.next()
    );

    // You can easily get hashes from 2D-shingles
    for h in v.as_shingles_2d([3, 3]).hashes() {
        // print u64 hash value for each 2D-shingle
        println!("{}", h);
    }
}

No runtime deps