Expand description
§Number Word Parser
This crate provides a solution to the number word problem, which involves parsing a string of digits into all possible corresponding words based on a given mapping (e.g., “1” -> ‘A’, “2” -> ‘B’, …, “26” -> ‘Z’).
It implements three different strategies to solve this problem, each with distinct performance characteristics and algorithmic approaches. This serves as a pedagogical example of optimization in Rust.
§Strategies
- Naive Recursion (
NaiveParser): Directly constructs solutions using functional combinators. Simple to read but slow due to excessive allocation (VecDeque). - Depth-First Search (
DfsParser): Uses a recursive backtracking approach with a single mutable buffer. Highly memory-efficient and fast for small to medium inputs. - Memoized Graph (
MemoizedParser): A hybrid approach using Dynamic Programming. It precomputes the solution graph and solution counts to enable perfect pre-allocation and fast generation. Fastest for large, ambiguous inputs.
Structs§
- DfsParser
- DFS Parser
- Memoized
Parser - Memoized Parser (Compiled Graph)
- Naive
Parser - Naive Parser
Enums§
- Number
Words Error - Errors that can occur during parsing.
Traits§
- Number
Parser - A unified trait for all number parser implementations.
Functions§
- default_
config - Generates the standard configuration mapping 1..26 to A..Z.