anna-the-gram
v1.0.5
Published
Anagram and dictionary utility backed by a C++ radix trie (Seshat) via N-API.
Readme
Anna and Seshat
Anna provides an anagram and dictionary utility. Validation uses Seshat, a radix trie implemented in C++ and exposed with N-API.
npm install
npm i anna-the-gramBuild
npm ci
npm run buildThe native module is built at build/Release/seshat.node.
Use in Node.js
The package exports the native classes via the ESM entry.
import { Seshat, Anna } from "cppintegrations";
// Seshat: trie operations
const trie = new Seshat();
trie.insertBatch(["cat", "dog", "catalog"]);
trie.search("dog");
trie.startsWith("cat");
trie.wordsWithPrefix("cat");
// Anna: anagram finder
const anna = new Anna();
anna.loadWords(["cat", "act", "tac", "dog"]);
anna.isValid("cat");
anna.findAnagrams("tac");During local development, you can also load the native binary directly:
const addon = require("./build/Release/seshat.node");
const { Seshat, Anna } = addon;Loading a word list file
Seshat supports bulk loading from a newline-delimited file:
const t = new Seshat();
const loaded = t.insertFromFile("./enable1.txt", 1024 * 1024);
console.log(loaded, t.size());Tests
npm testTest suites:
test/native.test.jscovers Seshat and Anna basicstest/enable.test.jsoptionally runs with the ENABLE word list
The ENABLE test checks for a file before running. Provide it with one of:
- Set
ENABLE_WORD_LIST=/path/to/enable1.txt - Place
enable1.txtin the project root
CI
GitHub Actions builds and runs tests on Linux, macOS, and Windows for Node 20 and 22. It attempts to download the ENABLE list for the optional tests.
