Expand description
§iword-rs
High-speed keyword search using a rolling hash scan — Rust implementation.
Based on iWord by imos / 0xkaz.
§Core concept
Builds a hash table from a word list, then scans text in O(N) time (N = text length), finding all matching words regardless of how many words are in the dictionary.
§Dictionary format
Tab-separated word list (compatible with the original iWord format):
apple # key 9 (default)
spam_word\t2 # key 2
adult_word\t1 # key 1
hidden\t0 # key 0Keys 0-4 are “forbidden” (returned only when Mode::FORBID is set).
Keys 5-254 are returned unconditionally.
§Quick start
use iword::{Dictionary, Mode};
let dict = Dictionary::builder()
.add("spam", 2)
.add("adult_word", 1)
.add("apple", 9)
.build();
assert_eq!(dict.seek("spam"), Some(2));
assert_eq!(dict.seek("notaword"), None);
let matches = dict.scan("buy spam now", Mode::FORBID);
assert!(!matches.is_empty());
assert_eq!(matches[0].key, 2);
let clean = dict.filter("buy spam now", Mode::FORBID);
assert!(!clean.contains("spam"));Modules§
- key
- Category key constants — action-oriented, suited for edge filtering and log collection.
Structs§
- Classify
Result - Result of
Dictionary::classify(). - Dictionary
- Compiled keyword dictionary. Built via
Dictionary::builder()orDictionary::from_file(). - Dictionary
Builder - Flexible builder — add words programmatically or load from files/strings.
- Match
- A single keyword match found in text.
- Mode
- Scan mode flags (combinable with
|).