5 releases (2 stable)

1.1.0 Nov 5, 2020
1.0.0 Aug 7, 2020
0.2.0 Jun 25, 2020
0.1.1 Jun 9, 2020
0.1.0 Jun 9, 2020

#119 in Command-line interface

Download history 20/week @ 2020-08-07 12/week @ 2020-08-14 15/week @ 2020-08-21 8/week @ 2020-08-28 22/week @ 2020-09-04 8/week @ 2020-09-11 6/week @ 2020-09-18 45/week @ 2020-09-25 32/week @ 2020-10-02 75/week @ 2020-10-09 75/week @ 2020-10-16 39/week @ 2020-10-23 90/week @ 2020-10-30 32/week @ 2020-11-06 19/week @ 2020-11-13 11/week @ 2020-11-20

137 downloads per month

MIT license

19KB
262 lines

Rust Clippy check Security audit Docs Coverage Status Crates.io

rs-complete

rs-completion is a library to use when you want to implement tab-completion (or similar) in your project.

rs-completion is mainly built for memory efficiency. Completions are stored in binary trees where each node holds a number of characters. The characters in turn link to new nodes. Similar words will thusly share memory.

Visual example

//                          'c' - 'a' - 'v' - 'e'
//                         /
//    root - 'b' - 'a' - 't' - 'm' - 'a' - 'n'
//                               \
//                                'o' - 'b' - 'i' - 'l' - 'e'

This means that a worst case scenario you could have 25^25 nodes in memory where 25 is the size of your alphabet. But this would mean that you are holding every thinkable combination of characters in memory with no regards for consonant or verb rules. If this is what you need then you don't need a library for it.

I can't argue if this solution is fast or efficient. It has worked to solve the problem I intended to solve when I created the library. If you have ideas for extensions or improvements I'm happy to see them.

Example

extern crate rs_completion;
use rs_completion::CompletionTree;

let mut completions = CompletionTree::default();

completions.insert("large bunch of words that bungalow we want to be bundesliga able to complete");
assert_eq!(
    completions.complete("bun"),
    Some(vec!["bunch", "bundesliga", "bungalow"].iter().map(|s| s.to_string()).collect()));

Dependencies

~72KB