🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| dist | ||
| src | ||
| .eslintrc.cjs | ||
| COMMIT_HISTORY.md | ||
| package.json | ||
| package.json.tmp | ||
| README.md | ||
| tsconfig.json | ||
| tsup.config.ts | ||
| vitest.config.ts | ||
@uwuapps/algorithms
High-performance algorithms for text processing and data structures.
Installation
npm install @uwuapps/algorithms
Features
Distance Algorithms
- Levenshtein Distance: Classic edit distance algorithm
- Optimized Levenshtein: Space-optimized O(min(n,m)) implementation
- Damerau-Levenshtein: Includes transpositions for better typo detection
Phonetic Algorithms
- Soundex: Classic phonetic encoding
- Metaphone: Improved English pronunciation rules
- Double Metaphone: Handles multiple pronunciations
Data Structures
- Trie: Efficient prefix tree with frequency tracking
Usage
Distance Algorithms
import { LevenshteinDistance, DamerauLevenshtein } from '@uwuapps/algorithms/distance';
const levenshtein = new LevenshteinDistance();
const distance = levenshtein.calculate('hello', 'hallo'); // 1
const similarity = levenshtein.similarity('hello', 'hallo'); // 0.8
const damerau = new DamerauLevenshtein();
const typoDistance = damerau.calculate('teh', 'the'); // 1 (transposition)
Phonetic Algorithms
import { Soundex, Metaphone } from '@uwuapps/algorithms/phonetic';
const soundex = new Soundex();
const code = soundex.encode('Smith'); // S530
const soundsLike = soundex.soundsLike('Smith', 'Smythe'); // true
const metaphone = new Metaphone();
const phoneticCode = metaphone.encode('phone'); // FN
Data Structures
import { Trie } from '@uwuapps/algorithms/data-structures';
const trie = new Trie();
trie.insert('hello', 10);
trie.insert('help', 5);
const suggestions = trie.getSuggestions('hel'); // ['hello', 'help']
const exists = trie.search('hello'); // true
Performance
All algorithms are optimized for performance:
- Caching for repeated calculations
- Early termination with max distance
- Space-optimized implementations
- Efficient data structures
License
MIT