Skip to main content

Crate keyhammer

Crate keyhammer 

Source
Expand description

§keyhammer

Typo-tolerant top-k search over a compact trie, with keyboard-aware edit costs. This crate is no_std (it needs alloc), forbids unsafe and has no runtime dependencies.

Status: M0 prototype. Queries and terms are compared per Unicode code point, as given; the text module folds case and diacritics when asked to.

§Example

use keyhammer::cost::CostModel;
use keyhammer::search::{SearchConfig, Searcher};
use keyhammer::trie::Trie;

let trie = Trie::build(&[
    ("javascript", 10),
    ("typescript", 10),
    ("python", 10),
    ("rust", 10),
    ("java", 10),
])
.unwrap();
let costs = CostModel::qwerty();
let mut searcher = Searcher::new();

// "javasript" skips the 'c' of "javascript".
let out = searcher
    .search(&trie, &costs, b"javasript", &SearchConfig::default())
    .unwrap();
let best = &out.hits[0];
assert_eq!(trie.term(best.id), "javascript");
assert_eq!(best.cost, 16);

Modules§

cost
Fixed-point edit costs (unit = 16) and keyboard-layout adjacency.
highlight
Match highlighting: which characters of a hit the user typed.
search
Exact best-first top-k search over a Trie with weighted edit costs.
text
Text normalisation: case folding and diacritic folding with tables of our own, and the offset utilities needed to report ranges in the caller’s text.
trie
A flat, breadth-first trie stored as parallel arrays.