entities
Version:
Encode & decode XML and HTML entities with ease & speed
38 lines • 2.07 kB
TypeScript
/**
* Decode a dictionary-encoded trie string back into its Uint16Array.
*
* Stream layout (consumed in this order):
* 1. dict1 atoms — `dict1AtomCount` uint16 values, delta+RLE encoded.
* 2. dict2 atoms — `atomCount - dict1AtomCount` values, delta+RLE.
* 3. dict2 ngrams — `ngramCount - (dictSize - dict1AtomCount)` entries,
* each a pair of slot codes that resolve to earlier slots.
* 4. dict1 ngrams — `dictSize - dict1AtomCount` entries, same shape.
* 5. data — slot codes, each expanding to one or more uint16 values.
*
* Codes use a 91-char base (printable ASCII minus `"`, `$`, `\`):
* - char1 < dictSize → 1-char code, slot = char1
* - char1 ≥ dictSize → 2-char code, slot = dictSize + (char1 - dictSize)*91 + char2
*
* Slot index → token kind:
* [0, A) dict1 atoms (1-char codes)
* [A, dictSize) dict1 ngrams (1-char codes)
* [dictSize, dictSize+D) dict2 atoms (2-char codes)
* [dictSize+D, end) dict2 ngrams (2-char codes)
*
* Both atom dicts decode before any ngram, and dict2 ngrams decode before
* dict1 ngrams. So every ngram entry references slots whose contents are
* already filled — no forward references to handle.
*
* This runs on library import. Flat typed arrays store each slot as either
* a plain value (`single`, covering every atom) or a range in a shared
* `pool` (ngrams).
* @param input Packed trie string.
* @param resultLength Expected number of uint16 values in the output.
* @param atomCount Total number of distinct uint16 values in the trie.
* @param dict1AtomCount Atoms in the 1-char range (`A` above).
* @param ngramCount Total number of ngram entries (dict1 + dict2).
* @param dictSize Number of 1-char code slots; the rest of `BASE - dictSize`
* first-byte values are 2-char codes.
*/
export declare function decodeTrieDict(input: string, resultLength: number, atomCount: number, dict1AtomCount: number, ngramCount: number, dictSize: number): Uint16Array;
//# sourceMappingURL=decode-shared.d.ts.map