Liking cljdoc? Tell your friends :D

Examples & Tutorials

This directory holds the numbered tutorial series for liblevenshtein — a guided path from a first spell checker to a complete phonetic spellcheck application — plus an index of every runnable example in examples/. Each tutorial is grounded in a real, compiling example, so every snippet you read is copied or condensed from code you can run.

New to the library? Start with the main README for the conceptual overview (Levenshtein automata, the dictionary family, feature flags), then follow the tutorials below in order.


Tutorial series

A progressive, eight-part walkthrough. Each part explains one concept, walks through its backing example in a few annotated snippets, gives the exact cargo run command, and embeds the relevant architecture diagrams.

#TutorialYou'll learnBacking example
01Getting StartedBuild a spell checker from a dictionary + algorithm + transducer; query vs query_with_distancespell_checker.rs
02DictionariesPick a backend for your access pattern; mutate a DynamicDawg at runtime; serialize to diskdynamic_dictionary.rs, serialization.rs
03Algorithms & OrderingStandard / Transposition / MergeAndSplit; distance-first ordered results and lazy top-$k$ordered_query_demo.rs
04Queries & UnicodeUnicode matching and zero-cost custom substitutions (diacritics, case-folding, kana)unicode_diacritics.rs
05Values & Fuzzy MapsAttach values to terms; filter, prioritize, and prune by value during traversalfuzzy_maps_code_completion.rs
06Contextual CompletionIncremental drafts, checkpoints/undo, and hierarchical scope visibilitycontextual_completion.rs
07Performance & ConcurrencyBenchmark on a real 124k-word dictionary; backend trade-offs; the lock-free read modelreal_world_benchmark.rs
08Real-World: Phonetic SpellcheckA complete app: phonetic normalization × edit distance, dual-index dictionary, formally verified rulesphonetic_spellcheck/

All runnable examples

The full set of programs under examples/, grouped by theme. Run any of them with cargo run --example <name>; entries that need Cargo features list them in the Features column (omit the column when none are required). A handful are standalone Cargo packages or analysis harnesses rather than library demos — noted in their purpose.

crates.io note. Examples requiring pathmap-backend use a git dependency and must be built from source (they are unavailable from a plain crates.io install).

Getting started

ExamplePurposeFeatures
spell_checker.rsMinimal fuzzy spell checker: dictionary + transducer, query and query_with_distance, Standard vs Transposition
builder_demo.rsThe TransducerBuilder API for fluent transducer construction
batch_operations.rsBulk insert / contains / remove operations on a DynamicDawg

Dictionaries & backends

ExamplePurposeFeatures
dynamic_dictionary.rsRuntime insert/remove on a DynamicDawg with a live, shared transducer (incl. concurrent reads)
dynamic_dawg_demo.rsOnline modifications of a DynamicDawg (byte alphabet)
dynamic_dawg_unicode.rsDynamicDawgChar with full Unicode (char) support
suffix_automaton_demo.rsSubstring matching with a SuffixAutomaton
substring_search.rsComprehensive approximate substring search over suffix automata
test_backend_comparison.rsSide-by-side contains behavior across dictionary backends
custom_sync_strategy.rsA custom backend declaring its own SyncStrategy for the transducerpathmap-backend

Queries, algorithms & substitutions

ExamplePurposeFeatures
ordered_query_demo.rsquery_ordered: distance-first, lexicographic results; lazy top-$k$ and distance-bounded queries
ordered_query_benchmark.rsMicro-benchmark: ordered vs unordered query iterators
unicode_diacritics.rsSubstitutionSetChar presets (Latin diacritics, Greek/Cyrillic case-fold, kana) + custom sets
custom_substitutions.rsBuild and combine byte-level SubstitutionSets for domain-specific matching
phonetic_matching.rsRestricted substitutions for sound-alike matching (no rules feature needed)
code_completion_demo.rsCode completion via prefix matching and result filtering
position_skip_test.rsCorrectness check that automaton position-skipping preserves results
trace_za_query.rsManual, step-by-step trace of automaton states for a tiny query ("za")

Values, fuzzy maps & caching

ExamplePurposeFeatures
fuzzy_maps_code_completion.rsTerms→scope-ID fuzzy map; filter, prioritize, and prune matches by valuepathmap-backend
fuzzy_cache_basic.rsWrapping a dictionary in a cache-eviction decoratorpathmap-backend
mork_fuzzy_query.rsZero-plumbing fuzzy queries over a bare, borrowed PathMap (MORK-style)pathmap-backend

Contextual completion

ExamplePurposeFeatures
contextual_completion.rsDynamicContextualCompletionEngine: drafts, checkpoints/undo, hierarchical scope visibilitypathmap-backend
hierarchical_scope_completion.rsLexical-scope completion built on fuzzy mapspathmap-backend
advanced_contextual_filtering.rsBitmap-based node masking for fast contextual filtering
contextual_filtering_optimization.rsEfficient contextual filtering via sub-trie construction

Phonetic matching

ExamplePurposeFeatures
phonetic_spellcheck/Standalone project: PhoneticNormalizedDictionary over ~124k words (fuzzy, regex, pattern expansion)phonetic-rules, pathmap-backend, embedded-rules
phonetic_fuzzy_matching.rsComprehensive phonetic rewrite × Levenshtein fuzzy matchingphonetic-rules
phonetic_rewrite.rsApply .llev phonetic rewrite rules to transform textphonetic-rules
phonetic_iteration_analysis.rsMeasure iteration counts inside apply_rules_seq()phonetic-rules
phonetic_slice_analysis.rsProfile slice-copying overhead in phonetic rewriting

Performance & profiling

ExamplePurposeFeatures
real_world_benchmark.rsBenchmark backends on a real English dictionary: build, contains, fuzzy query
profile.rsRepresentative workload for flame-graph profiling / regression hunting
profile_workload.rsMixed-operation workload for flamegraph capture
scientific_eval.rsInstrumented evaluation harness (custom allocator + PriorityQueryIterator) for metrics
simd_prototype.rsPrototype illustrating the SIMD acceleration concepts
parallel_workspace_indexing.rsParallel per-document dictionary construction with binary-tree reduction
msm_experiment.rsDeterministic Move–Split–Merge (time-series) optimization harness

Serialization

ExamplePurposeFeatures
serialization.rsSave/load a DoubleArrayTrie via compact bincode and verify fuzzy queries round-tripserialization
operation_set_persistence.rsRound-trip a complete generalized edit grammar through bincode and protobufprotobuf

← Documentation Index

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close