From ec268c111968a43e31b95fd6e6990c7687641e44 Mon Sep 17 00:00:00 2001 From: David Moncada Date: Sun, 9 Jul 2023 16:08:48 -0700 Subject: [PATCH] Inline sources. --- lib/BaseTrie.js.map | 2 +- lib/BinaryString.js.map | 2 +- lib/PackedTrie.js.map | 2 +- lib/Trie.js.map | 2 +- lib/base64.js.map | 2 +- lib/constants.js.map | 2 +- lib/floor_log2.js.map | 2 +- lib/index.js.map | 2 +- tsconfig.json | 1 + 9 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/BaseTrie.js.map b/lib/BaseTrie.js.map index 9247b3f..2ab5aca 100644 --- a/lib/BaseTrie.js.map +++ b/lib/BaseTrie.js.map @@ -1 +1 @@ -{"version":3,"file":"BaseTrie.js","sourceRoot":"","sources":["../src/BaseTrie.ts"],"names":[],"mappings":""} \ No newline at end of file +{"version":3,"file":"BaseTrie.js","sourceRoot":"","sources":["../src/BaseTrie.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Options to refine membership test queries.\n */\nexport interface ITestOpts {\n wildcard?: string;\n prefix?: boolean;\n}\n\n/**\n * Options to refine search queries.\n */\nexport interface ISearchOpts {\n wildcard?: string;\n prefix?: boolean;\n first?: boolean;\n}\n\n/**\n * Base Trie interface that supports testing and searching.\n */\nexport interface ITrie {\n /**\n * Test that a string exists in a trie.\n * @param {string} s\n * @param {ITestOpts} opts\n * @returns {boolean}\n */\n test: (s: string, opts?: ITestOpts) => boolean;\n\n /**\n * Query a trie for membership of a string, optionally using wildcards and/or prefix matching.\n * @param {string} s\n * @param {ISearchOpts} opts\n * @returns {string | string[]}\n */\n search: (s: string, opts?: ISearchOpts) => string | string[];\n}"]} \ No newline at end of file diff --git a/lib/BinaryString.js.map b/lib/BinaryString.js.map index 710e7ed..46ef4ec 100644 --- a/lib/BinaryString.js.map +++ b/lib/BinaryString.js.map @@ -1 +1 @@ -{"version":3,"file":"BinaryString.js","sourceRoot":"","sources":["../src/BinaryString.ts"],"names":[],"mappings":";;AAKA,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OAAO,EAAE,CAAC;IACnB,CAAC;IAMD,KAAK;QACD,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QACzB,IAAI,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAE3B,OAAO,OAAO,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;YAC5B,MAAM,KAAK,CAAC,CAAC;YACb,OAAO,IAAI,CAAC,CAAC;QACjB,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IAOD,OAAO;QACH,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAWD,OAAO;QACH,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QACzB,IAAI,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC3B,IAAI,OAAO,GAAG,EAAE,CAAC;QACjB,OAAO,OAAO,IAAI,CAAC,EAAE,CAAC;YAClB,IAAI,SAAS,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;YAC9B,IAAI,IAAI,GAAG,MAAM,IAAI,SAAS,CAAC;YAC/B,MAAM,GAAG,MAAM,GAAG,CAAC,IAAI,IAAI,SAAS,CAAC,CAAC;YACtC,OAAO,GAAG,SAAS,CAAC;YACpB,OAAO,IAAI,2BAAkB,CAAC,IAAI,CAAC,CAAC;QACxC,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC;IACzB,CAAC;CAEJ;AAlGD,oCAkGC","sourcesContent":["/**\n * @file Provide an interface for writing binary data into a Base64-encoded\n * string.\n */\n\nimport {floor_log2} from './floor_log2';\nimport {BASE64_INT_TO_CHAR} from './base64';\n\n/**\n * Interface for writing binary data into a Base64-encoded string\n * @class\n */\nexport class BinaryString {\n\n /**\n * Data buffer\n * @type {Number?}\n */\n private buffer = 0;\n\n /**\n * Word pointer for buffer. With every entry into the buffer, the\n * pointer gets incremented by the entry's width. Every six characters\n * may be encoded, so when the pointer exceeds 6, the buffer can be\n * emptied until the pointer is back under 6.\n * @type {Number}\n */\n private pointer = 0;\n\n /**\n * Encoded data as a string of base64 characters\n * @type {String}\n */\n private data = '';\n\n /**\n * Write a value to the binary string. This value should be thought of as\n * an integer representing the binary data to write.\n * @param {Integer} val - data to write\n * @param {Integer} [width] - optionally specify a width for this data.\n * if none is given, width will be inferred\n * automatically. An error will be thrown if\n * the width is too small to contain the data.\n */\n write(val: number, width: number = null) {\n let buf = this.buffer;\n let len = width || floor_log2(val) + 1;\n\n if (width && val >= (0x1 << width)) {\n throw new Error(`Can't write ${val} in only ${width} bits`);\n }\n\n this.buffer = (buf << len) | val;\n this.pointer += len;\n\n this._digest();\n }\n\n /**\n * Encode the remaining items in the buffer. Use this when the input stream\n * is finished to ensure that all data has been encoded.\n */\n flush() {\n let buffer = this.buffer;\n let pointer = this.pointer;\n // NB if pointer is at 0, there's nothing to flush.\n while (pointer && pointer < 6) {\n buffer <<= 1;\n pointer += 1;\n }\n this.pointer = pointer;\n this.buffer = buffer;\n this._digest();\n }\n\n /**\n * Get the binary data as base64. This output does not include padding\n * characters. This procedure flushes the buffer.\n * @return {String}\n */\n getData() {\n this.flush();\n return this.data;\n }\n\n /**\n * Write values from the buffer into the binary encoded string until the\n * pointer is below 6. Use @link BinaryString#flush to print out all values\n * regardless of whether they are complete and return the pointer to 0.\n *\n * This method is used internally during writes and does not need to be\n * called explicitly.\n * @private\n */\n _digest() {\n let buffer = this.buffer;\n let pointer = this.pointer;\n let newData = '';\n while (pointer >= 6) {\n let remainder = (pointer - 6);\n let code = buffer >> remainder;\n buffer = buffer ^ (code << remainder);\n pointer = remainder;\n newData += BASE64_INT_TO_CHAR[code];\n }\n this.pointer = pointer;\n this.buffer = buffer;\n this.data += newData;\n }\n\n}\n"]} \ No newline at end of file diff --git a/lib/PackedTrie.js.map b/lib/PackedTrie.js.map index 8160479..6f21b34 100644 --- a/lib/PackedTrie.js.map +++ b/lib/PackedTrie.js.map @@ -1 +1 @@ -{"version":3,"file":"PackedTrie.js","sourceRoot":"","sources":["../src/PackedTrie.ts"],"names":[],"mappings":";;AAQA,qCAA4C;AAC5C,2CASqB;AASrB,kBAAkB,MAAc,EAAE,KAAa,EAAE,GAAW;IACxD,MAAM,SAAS,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IAChC,MAAM,cAAc,GAAG,KAAK,GAAG,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,cAAc,GAAG,GAAG,CAAC;IACpC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACtC,MAAM,IAAI,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC;QAC/B,KAAK,KAAK,CAAC,CAAC;QACZ,KAAK,IAAI,2BAAkB,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC;IACvD,CAAC;IAED,IAAI,YAAY,GAAG,MAAM,GAAG,CAAC,CAAC;IAC9B,EAAE,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;QACf,KAAK,KAAK,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC;IACjC,CAAC;IAED,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC;AACxB,CAAC;AASD;IAuEI,YAAY,MAAc;QAjClB,aAAQ,GAAG,GAAG,CAAC;QAYf,iBAAY,GAAG,CAAC,CAAC;QAsBrB,IAAI,GAAG,GAAG,CAAC,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tD,MAAM,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;oBAEtC,EAAE,CAAC,CAAC,MAAM,IAAI,OAAO,KAAK,oBAAQ,CAAC,CAAC,CAAC;wBAEjC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;4BACR,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;wBACrB,CAAC;wBAED,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;wBAGxB,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;4BACV,KAAK,CAAC;wBACV,CAAC;oBACL,CAAC;oBAGD,EAAE,CAAC,CAAC,OAAO,KAAK,oBAAQ,CAAC,CAAC,CAAC;wBACvB,KAAK,CAAC,IAAI,CAAC;4BACP,OAAO,EAAE,WAAW,GAAG,MAAM,GAAG,OAAO;4BACvC,KAAK,EAAE,IAAI,CAAC,KAAK,GAAG,CAAC;4BACrB,IAAI,EAAE,IAAI,CAAC,IAAI,GAAG,OAAO;yBAC5B,CAAC,CAAC;oBACP,CAAC;gBACL,CAAC;gBAID,MAAM,IAAI,GAAG,KAAK,GAAG,QAAQ,CAAC;gBAG9B,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;oBACP,KAAK,CAAC;gBACV,CAAC;gBAED,IAAI,CAAC,CAAC;oBACF,WAAW,IAAI,CAAC,CAAC;gBACrB,CAAC;YACL,CAAC;QACL,CAAC;QAID,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;IAClC,CAAC;CAEJ;AA5QD,gCA4QC","sourcesContent":["/**\n * @file Small class for querying a binary-encoded Trie\n *\n * TODO - rewrite as a native class. Babel adds a lot of overhead. This class\n * should be tiny and transparent.\n */\n\nimport {ITrie, ISearchOpts, ITestOpts} from './BaseTrie';\nimport {BASE64_CHAR_TO_INT} from './base64';\nimport {\n TERMINAL,\n VERSION,\n HEADER_WIDTH_FIELD,\n VERSION_FIELD,\n OFFSET_SIGN_FIELD,\n OFFSET_VAL_FIELD,\n CHAR_WIDTH_FIELD,\n POINTER_WIDTH_FIELD\n} from './constants';\n\n/**\n * Extract a window of bits from a Base64 encoded sequence\n * @param {String} binary - base64 encoded sequence\n * @param {Number} start - first bit to read\n * @param {Number} len - number of bits to read\n * @return {Number} - bits from string, as number\n */\nfunction readBits(binary: string, start: number, len: number) {\n const startChar = ~~(start / 6);\n const startBitOffset = start % 6;\n const endBit = startBitOffset + len;\n const charLen = Math.ceil(endBit / 6);\n const mask = (0x1 << len) - 1;\n let chunk = 0;\n\n for (let i = 0; i < charLen; i++) {\n chunk <<= 6;\n chunk |= BASE64_CHAR_TO_INT[binary[startChar + i]];\n }\n\n let rightPadding = endBit % 6;\n if (rightPadding) {\n chunk >>= (6 - rightPadding);\n }\n\n return chunk & mask;\n}\n\n/**\n * Class for interacting with an encoded trie. The class performs lookups\n * virtually just as fast as a regular trie. The binary data never actually\n * have to be processed as a whole, so instantiation time and memory usage are\n * phenomenally low.\n * @class\n */\nexport class PackedTrie implements ITrie {\n\n /**\n * Binary string encoded as Base64 representing Trie\n * @type {String}\n */\n public data: string;\n\n /**\n * Pointer offset. Add this to every pointer read from every word in\n * the trie to obtain the true value of the pointer. This offset is\n * used to avoid signed integers in the word.\n * @type {Number}\n */\n private offset: number;\n\n /**\n * Character table, mapping character to an integer ID\n * @type {Object}\n */\n private table: {[key: string]: number};\n\n /**\n * Inverse of character table, mapping integer ID to character.\n * @type {Array}\n */\n private inverseTable: {[key: number]: string};\n\n /**\n * Number of bits in one word\n * @type {Number}\n */\n private wordWidth: number;\n\n /**\n * Mask for reading the \"last block\" flag in a word\n * @type {Number}\n */\n private lastMask = 0x1;\n\n /**\n * Mask for reading the pointer value from a word\n * @type {Number}\n */\n private pointerMask: number;\n\n /**\n * Offset of pointer field in a word\n * @type {Number}\n */\n private pointerShift = 1;\n\n /**\n * Mask for reading the charTable index in a word\n * @type {Number}\n */\n private charMask: number;\n\n /**\n * Offset of charTable index field in a word\n * @type {Number}\n */\n private charShift: number;\n\n /**\n * Instantiate a packed binary trie, parsing its headers to configure the\n * instance for queries.\n * @constructor\n * @param {String} binary - binary string from {@link Trie#encode}\n * @return {PackedTrie}\n */\n constructor(binary: string) {\n let ptr = 0;\n\n // Split binary into header and content by checking first field\n const headerCharCount = readBits(binary, ptr, HEADER_WIDTH_FIELD);\n ptr += HEADER_WIDTH_FIELD;\n const header = binary.substr(0, headerCharCount);\n\n const version = readBits(binary, ptr, VERSION_FIELD);\n ptr += VERSION_FIELD;\n\n if (version !== VERSION) {\n throw new Error(`Version mismatch! Binary: ${version}, Reader: ${VERSION}`);\n }\n\n // Main trie data\n this.data = binary.substr(headerCharCount);\n\n // compute pointer offset\n const offsetSign = readBits(header, ptr, OFFSET_SIGN_FIELD);\n ptr += OFFSET_SIGN_FIELD;\n let offset = readBits(header, ptr, OFFSET_VAL_FIELD);\n ptr += OFFSET_VAL_FIELD;\n\n if (offsetSign) {\n offset = -offset;\n }\n\n // Pointer offset\n this.offset = offset;\n\n // interpret the field width within each word\n let charWidth = readBits(header, ptr, CHAR_WIDTH_FIELD);\n ptr += CHAR_WIDTH_FIELD;\n\n let pointerWidth = readBits(header, ptr, POINTER_WIDTH_FIELD);\n ptr += POINTER_WIDTH_FIELD;\n\n // Interpret the rest of the header as the charTable\n let headerFieldChars = Math.ceil(ptr / 6);\n let charTable = header.substr(headerFieldChars);\n\n this.table = charTable.split('').reduce((agg, char, i) => {\n agg[char] = i + 1;\n return agg;\n }, { [TERMINAL]: 0 } as {[key: string]: number});\n\n // Construct inverse table\n this.inverseTable = [TERMINAL].concat(charTable.split(''));\n\n // Number of bits in a word\n this.wordWidth = charWidth + pointerWidth + 1;\n\n // Mask for reading pointer\n this.pointerMask = (0x1 << pointerWidth) - 1;\n\n // Mask for reading characters\n this.charMask = (0x1 << charWidth) - 1;\n\n // Offset of charTable\n this.charShift = 1 + pointerWidth;\n }\n\n /**\n * Test membership in the trie.\n * @param {String} str - Search query\n * @param {String?} opts.wildcard - See PackedTrie#search wildcard doc\n * @param {Boolean?} opts.prefix - See PackedTrie#search prefix doc\n * @return {Boolean}\n */\n test(str: string, {wildcard, prefix}: ITestOpts = {wildcard: null, prefix: false}) {\n // Delegate to #search with early exit. Could write an optimized path,\n // especially for the prefix search case.\n return this.search(str, {wildcard, prefix, first: true}) !== null;\n }\n\n /**\n * Query for matching words in the trie.\n * @param {String} str - Search query\n * @param {String?} opts.wildcard - Wildcard to use for fuzzy matching.\n * Default is no wildcard; only match\n * literal query.\n * @param {Boolean?} opts.prefix - Perform prefix search (returns true if\n * any word exists in the trie starts with\n * the search query). Default is false;\n * only match the full query.\n * @param {Boolean} opts.first - Return only first match that is found,\n * short-circuiting the search. Default is\n * false; return all matches.\n * @return {String?|String[]} - Return an optional string result when in\n * first-only mode; otherwise return a list\n * of strings that match the query.\n */\n search(str: string, {wildcard, prefix, first}: ISearchOpts = {wildcard: null, prefix: false, first: false}) {\n if (wildcard && wildcard.length !== 1) {\n throw new Error(`Wilcard must be a single character; got ${wildcard}`);\n }\n\n const {\n data,\n offset,\n table,\n inverseTable,\n wordWidth,\n lastMask,\n pointerShift,\n pointerMask,\n charShift,\n charMask\n } = this;\n\n // List of matches found in the search.\n const matches = [];\n\n // Search queue.\n const queue = [{pointer: 0, memo: '', depth: 0}];\n const lastDepth = str.length;\n\n // Do a BFS over nodes for the search query.\n while (queue.length) {\n const node = queue.shift();\n const isLast = node.depth >= lastDepth;\n const token = isLast ? TERMINAL : str[node.depth];\n // Flag for matching anything. Note that the overflow beyond the\n // length of the query in a prefix search behaves as a wildcard.\n const isWild = token === wildcard || (prefix && isLast);\n // We're committed to an O(N) scan over the entire node even in\n // the simple literal-search case, since our structure doesn't\n // currently guarantee any child ordering.\n // TODO(joen) ordering is a potential future format optimization.\n let wordPointer = node.pointer;\n while (true) {\n // Optimization: Exit immediately if the char was not found in\n // the table (meaning there can't be any children in the trie\n // with this character). Exception is wildcards.\n if (!isWild && !table.hasOwnProperty(token)) {\n break;\n }\n\n const bits = wordPointer * wordWidth;\n const chunk = readBits(data, bits, wordWidth);\n\n // Read the character index\n const charIdx = (chunk >> charShift) & charMask;\n\n // If this character is matched, jump to the pointer given in\n // this node.\n if (isWild || charIdx === table[token]) {\n const pointer = (chunk >> pointerShift) & pointerMask;\n // Find the next char with an inverse map, since we might\n // be using a wildcard search.\n const newChar = inverseTable[charIdx];\n // Stopping condition: searching last block and we hit a terminal\n if (isLast && newChar === TERMINAL) {\n // Optimization: early exit if we only need first match.\n if (first) {\n return node.memo;\n }\n // Store this match.\n matches.push(node.memo);\n // If we're not matching everything, break out of the\n // inner loop.\n if (!isWild) {\n break;\n }\n }\n\n // Push next node for search, if it's non-terminal.\n if (newChar !== TERMINAL) {\n queue.push({\n pointer: wordPointer + offset + pointer,\n depth: node.depth + 1,\n memo: node.memo + newChar,\n });\n }\n }\n\n // If this wasn't a match, check if this was the last key in\n // the block.\n const last = chunk & lastMask;\n\n // If this was the last node, the word was not found.\n if (last) {\n break;\n }\n // Otherwise increment the pointer to the next sibling key\n else {\n wordPointer += 1;\n }\n }\n }\n\n // If first was requested it should have returned by now. Otherwise\n // return the matches list, which may be empty.\n return first ? null : matches;\n }\n\n}\n"]} \ No newline at end of file diff --git a/lib/Trie.js.map b/lib/Trie.js.map index 383cc5a..24631cf 100644 --- a/lib/Trie.js.map +++ b/lib/Trie.js.map @@ -1 +1 @@ -{"version":3,"file":"Trie.js","sourceRoot":"","sources":["../src/Trie.ts"],"names":[],"mappings":";;AAKA,6CAAwC;AACxC,iDAA4C;AAC5C,2CAUqB;AAsCrB;IAcI,YAAY,OAAc,EAAE;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACxB,CAAC;IASD,MAAM,CAAC,GAAW;QAGd,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;YACd,MAAM,IAAI,WAAW,CA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AAM,CAAC,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;CAEJ;AA/bD,oBA+bC","sourcesContent":["/**\n * @file Provides the Trie class\n */\n\nimport {ITrie, ITestOpts, ISearchOpts} from './BaseTrie';\nimport {floor_log2} from './floor_log2';\nimport {BinaryString} from './BinaryString';\nimport {\n TERMINAL,\n TERMINUS,\n VERSION,\n HEADER_WIDTH_FIELD,\n VERSION_FIELD,\n OFFSET_SIGN_FIELD,\n OFFSET_VAL_FIELD,\n CHAR_WIDTH_FIELD,\n POINTER_WIDTH_FIELD\n} from './constants';\n\n/**\n * Trie node.\n */\nexport interface INode {\n [key: string]: INode;\n}\n\n/**\n * Metadata used to process trie.\n */\ninterface INodeMeta {\n __visited__: number;\n __willVisit__: number;\n __idx__: number;\n __parents__: IChunk[];\n}\n\n/**\n * Interface of a node as it is being processed in the trie.\n */\ntype IInternalNode = INode & INodeMeta;\n\n/**\n * Long-form information to be encoded in binary format.\n */\ninterface IChunk {\n char: string;\n idx: number;\n offset: number;\n last: boolean;\n}\n\n/**\n * A structure to provide efficient membership tests for a set of strings\n * @class\n */\nexport class Trie implements ITrie {\n\n public root: INode;\n\n public frozen: boolean;\n\n /**\n * Typically no arguments are needed, but it's possible to instantiate a\n * Trie from a JSON object that represents it (@see Trie#toJSON).\n * @constructor\n * @param {Object} tree - a trie given as a vanilla JS tree. This will be\n * used as the root node.\n * @return {Trie}\n */\n constructor(tree: INode = {}) {\n this.root = tree;\n this.frozen = false;\n }\n\n /**\n * Insert a word into the trie. Insertions into a frozen trie will throw\n * an error. The\n * @param {String} str - string to insert. Note the \\u0000 character is\n * disallowed.\n * @return {Trie} - this\n */\n insert(str: string) {\n // This trie insert algorithm can't guarantee safe inserts on the DAWG\n // produced by freezing.\n if (this.frozen) {\n throw new SyntaxError(`Can't insert into frozen Trie`);\n }\n\n const lastNode = str.split('').reduce((node, char) => {\n if (char === TERMINAL) {\n throw new TypeError(`Illegal string character ${TERMINAL}`);\n }\n let nextNode = node.hasOwnProperty(char) ?\n node[char] :\n (node[char] = {});\n return nextNode;\n }, this.root);\n\n // Terminate the string. Using a constant terminus is not necessary\n // (and is not be possible in cloned tries), but it uses slightly less\n // memory and could make certain bugs more obvious.\n lastNode[TERMINAL] = TERMINUS;\n\n return this;\n }\n\n /**\n * Test membership in the trie.\n * @param {String} str - Search query\n * @param {String?} opts.wildcard - See Trie#search wildcard doc\n * @param {Boolean?} opts.prefix - See Trie#search prefix doc\n * @return {Boolean}\n */\n test(str: string, {wildcard, prefix}: ITestOpts = {wildcard: null, prefix: false}) {\n // When there are no wildcards we can use an optimized search.\n if (!wildcard) {\n let node = this.root;\n const match = str.split('').every(char => !!(node = node[char]));\n return !!match && (prefix || node.hasOwnProperty(TERMINAL));\n }\n\n // Unoptimized path: delegate to #search with short-circuiting.\n return !!this.search(str, {wildcard, prefix, first: true});\n }\n\n /**\n * Query for matching words in the trie.\n * @param {String} str - Search query\n * @param {String?} opts.wildcard - Wildcard to use for fuzzy matching.\n * Default is no wildcard; only match\n * literal query.\n * @param {Boolean?} opts.prefix - Perform prefix search (returns true if\n * any word exists in the trie starts with\n * the search query). Default is false;\n * only match the full query.\n * @param {Boolean} opts.first - Return only first match that is found,\n * short-circuiting the search. Default is\n * false; return all matches.\n * @return {String?|String[]} - Return an optional string result when in\n * first-only mode; otherwise return a list\n * of strings that match the query.\n */\n search(str: string, {wildcard, prefix, first}: ISearchOpts = {wildcard: null, prefix: false, first: false}) {\n // Validate wildcard matching.\n if (wildcard && wildcard.length !== 1) {\n throw new Error(`Wildcard length must be 1; got ${wildcard.length}`);\n }\n\n // List of search hits. Note: not used in `first` mode.\n const matches = [];\n\n // Do a BFS over nodes to with fuzzy-matching on the wildcard.\n const queue = [{data: this.root, depth: 0, memo: ''}];\n const lastDepth = str.length;\n\n while (queue.length) {\n const node = queue.shift();\n // The search is a hit if we've reached the proper depth and the\n // node is terminal. The search can break if the query was for\n // first-only.\n if (node.depth >= lastDepth) {\n if (node.data.hasOwnProperty(TERMINAL)) {\n if (first) {\n return node.memo;\n }\n // Otherwise store this result and continue searching.\n matches.push(node.memo);\n }\n // Discard the node and move on if we can; prefix matches need\n // to traverse everything.\n if (!prefix) {\n continue;\n }\n }\n // Special case: prefix searches overflow the length of the search\n // queries. Treat these overflowing chars as wildcards.\n const isPfXOverflow = prefix && node.depth >= lastDepth;\n // Add any candidate children nodes to the search queue.\n const token = str[node.depth];\n // Wildcard could be any child (except terminal).\n if (token === wildcard || isPfXOverflow) {\n Object.keys(node.data).forEach(n => {\n if (n !== TERMINAL) {\n queue.push({\n data: node.data[n],\n depth: node.depth + 1,\n memo: node.memo + n,\n });\n }\n });\n } else {\n if (node.data.hasOwnProperty(token)) {\n queue.push({\n data: node.data[token],\n depth: node.depth + 1,\n memo: node.memo + token,\n });\n }\n }\n }\n\n // A `first` search will have broken out and returned a literal by now;\n // other searches just return whatever is in matches.\n return first ? null : matches;\n }\n\n /**\n * Clone a Trie. This will unfreeze a frozen trie.\n * @return {Trie}\n */\n clone() {\n return new Trie(this.toJSON());\n }\n\n /**\n * Freeze the Trie, deduping suffixes. Given the assumption that there will\n * not be new entries into a trie, redundant suffix branches can be merged.\n * @return {Trie} - This trie (freezing modifies it in place)\n */\n freeze() {\n // Freezing is idempotent\n if (this.frozen) {\n return this;\n }\n\n // Create a store for fast lookup of matching suffixes during walk\n const suffixTree: {[key: string]: INode[]} = {};\n\n // Walk the entire trie depth first, de-duping suffixes\n let node = this.root;\n let stack: {current: INode, char: string, parent: INode}[] = [];\n let depthStack = [node];\n\n // Iterate over tree nodes, pushing children onto the depthStack so\n // that the items pushed on to the main `stack` are in the correct\n // order for a second traversal.\n while (depthStack.length) {\n node = depthStack.pop();\n\n Object.keys(node).forEach(char => {\n if (char[1] === '_') {\n return;\n }\n let current = node[char];\n stack.push({\n current: current,\n char: char,\n parent: node\n });\n depthStack.push(current);\n });\n }\n\n // Now do node processing, joining / deduping suffix lines.\n while (stack.length) {\n let { char, parent, current } = stack.pop();\n\n // Find potential suffix duplicates with a char lookup\n if (suffixTree.hasOwnProperty(char)) {\n let suffixMeta = suffixTree[char];\n\n // Find a matching suffix by comparing children. Since\n // deduping is depth-first, comparing children by identity\n // is a valid way to check if this node is a duplicate.\n let match = suffixMeta.find(other => {\n let oKeys = Object.keys(other);\n let cKeys = Object.keys(current);\n return (\n oKeys.length === cKeys.length &&\n oKeys.every(key => other[key] === current[key])\n );\n });\n\n // If this node is a dupe, update its parent reference to\n // point to the cached match.\n if (match) {\n parent[char] = match;\n }\n // If the node is novel, cache it for future checks.\n else {\n suffixMeta.push(current);\n }\n }\n // If this char is novel, create a new suffixMeta entry\n else {\n suffixTree[char] = [current];\n }\n }\n\n // Flag the tree as frozen\n this.frozen = true;\n\n return this;\n }\n\n /**\n * Encode the Trie in a binary format. This format stores the trie or DAWG\n * efficiently and still allows for fast queries.\n * @return {Object}\n */\n encode() {\n const chunks: IChunk[] = [];\n const queue = [this.root];\n const charTable = new Set();\n const visitCode = Date.now();\n let offsetMin = Infinity;\n let offsetMax = -Infinity;\n\n // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n // Encode trie\n // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n while (queue.length) {\n let node = queue.shift() as IInternalNode;\n let keys = Object.keys(node).filter(k => k[1] !== '_');\n let n = keys.length;\n\n node.__visited__ = visitCode;\n let nodeChunkIndex = node.__idx__ = chunks.length;\n\n // Fill in the parent chunks that are waiting to find out what\n // index this chunk gets assigned\n if (node.__parents__) {\n node.__parents__.forEach(chunk => {\n let offset = chunk.offset = nodeChunkIndex - chunk.idx;\n if (offset < offsetMin) {\n offsetMin = offset;\n }\n if (offset > offsetMax) {\n offsetMax = offset;\n }\n });\n }\n\n keys.forEach((char, i) => {\n let child = node[char] as IInternalNode;\n let chunkIdx = chunks.length;\n let lastInLevel = i === n - 1;\n\n let newChunk: IChunk = {\n char: char,\n idx: chunkIdx,\n offset: null,\n last: lastInLevel\n };\n\n // If the child has been visited, jump directly to that node\n // instead of creating a new entry.\n if (child.__visited__ === visitCode) {\n let idx = child.__idx__;\n let offset = newChunk.offset = idx - chunkIdx;\n if (offset < offsetMin) {\n offsetMin = offset;\n }\n if (offset > offsetMax) {\n offsetMax = offset;\n }\n }\n // If child is novel, add it to the process queue and add an\n // instruction to jump there.\n else {\n if (child.__willVisit__ === visitCode) {\n child.__parents__.push(newChunk);\n } else {\n child.__willVisit__ = visitCode;\n child.__parents__ = [newChunk];\n }\n queue.push(child);\n }\n\n // Add a new chunk to the array\n chunks.push(newChunk);\n\n // Ensure that the char is in the chartable\n charTable.add(char);\n });\n }\n\n // Assign a unique integer ID to each character. The actual ID is\n // arbitrary. For the convenience of not having to serialize the \\0\n // character, the TERMINAL is always encoded at the 0 index, and it is\n // not included in the charTable.\n const charTableAsArray = Array.from(charTable)\n .filter(char => char !== TERMINAL);\n const charMap = charTableAsArray.reduce((agg, char, i) => {\n agg[char] = i + 1;\n return agg;\n }, { [TERMINAL]: 0 });\n // Determine the number of bits that can index the entire charTable.\n const charEncodingWidth = floor_log2(charTableAsArray.length) + 1;\n\n const pointerRange = offsetMax - offsetMin;\n const pointerEncodingWidth = floor_log2(pointerRange) + 1;\n\n // The binary with of node encodings is variable. There are three parts\n // that get encoded:\n //\n // 1) character index (corresponding to character table),\n // 2) pointer (as offset from start of word to next node),\n // 3) last (flag to indicate whether this is the last block in this\n // subtree)\n //\n // The width of the first two items are determined as the binary width\n // of the unsigned integer representing the maximum in the range. The\n // width of the third is a constant 1 binary digit.\n //\n // E.g., if the charTable is 28 characters in length, then the binary\n // digit representing 27 (the last item in the array) is:\n //\n // 1 1011\n //\n // So the width is determined to be 5. If the pointer range has a\n // maximum of 250, represented in binary as:\n //\n // 1111 1010\n //\n // Giving a width of 8. With these specifications, a node such as:\n //\n // charIndex: 8, pointer: 100, last: false\n //\n // Would be encoded as:\n //\n // --A---|----B-----|C|XXXXX\n // 0100 0|011 0010 0|1|00 00\n //\n // Which can be represented in Base64 as:\n //\n // QyQ==\n //\n // TODO could be more clever and combine the first two fields.\n\n const encodedTrie = new BinaryString();\n\n chunks.forEach(chunk => {\n let { char, offset, last } = chunk;\n encodedTrie.write(charMap[char], charEncodingWidth);\n encodedTrie.write(offset - offsetMin, pointerEncodingWidth);\n encodedTrie.write(+last, 1);\n });\n\n encodedTrie.flush();\n\n // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n // Encode header\n // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n const headerString = new BinaryString();\n // TODO encode unicode\n const outputCharTable = charTableAsArray.join('');\n\n // Header width designates the ASCII-character count at the beginning\n // of the file that encodes the header.\n const headerWidth = Math.ceil((\n HEADER_WIDTH_FIELD +\n VERSION_FIELD +\n OFFSET_SIGN_FIELD +\n OFFSET_VAL_FIELD +\n CHAR_WIDTH_FIELD +\n POINTER_WIDTH_FIELD\n ) / 6) + outputCharTable.length;\n // Mark the offset as positive or negative\n const offsetSign = +(offsetMin < 0);\n\n headerString.write(headerWidth, HEADER_WIDTH_FIELD);\n headerString.write(VERSION, VERSION_FIELD);\n headerString.write(offsetSign, OFFSET_SIGN_FIELD);\n headerString.write(offsetSign ? -offsetMin : offsetMin, OFFSET_VAL_FIELD);\n headerString.write(charEncodingWidth, CHAR_WIDTH_FIELD);\n headerString.write(pointerEncodingWidth, POINTER_WIDTH_FIELD);\n headerString.flush();\n\n // Concat the header, charTable, and trie\n return `${headerString.getData()}${outputCharTable}${encodedTrie.getData()}`;\n }\n\n /**\n * Implement JSON API for serialization. Tries can be serialized and\n * restored using JSON and the constructor. Note that tries (even frozen\n * ones) *do not serialize efficiently in JSON*. For memory-efficient\n * tries, @see Trie#encode.\n *\n * @example\n * > trie = new Trie();\n * > ['foo', 'fudge', 'nudge'].forEach(s => trie.insert(s));\n * > let jsonStr = JSON.stringify(trie);\n * > let restored = new Trie(JSON.parse(jsonStr));\n * > ['foo', 'fudge', 'nudge'].every(s => restored.test(s));\n * // -> true\n *\n * @return {Object} Vanilla JS object\n */\n toJSON() {\n // Remove any private fields on serialization, e.g. __visited__\n let str = JSON.stringify(this.root, (k, v) => {\n if (k[1] === '_') {\n return undefined;\n }\n return v;\n });\n return JSON.parse(str);\n }\n\n}\n"]} \ No newline at end of file diff --git a/lib/base64.js.map b/lib/base64.js.map index 38d7880..2bcbf1b 100644 --- a/lib/base64.js.map +++ b/lib/base64.js.map @@ -1 +1 @@ -{"version":3,"file":"base64.js","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":";;AASa,QAAA,kBAAkB,GAAG;;;;;CAKjC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAOC,QAAA,kBAAkB,GAAG,0BAAkB,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE;IACzE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACd,MAAM,CAAC,GAAG,CAAC;AACf,CAAC,EAAE,EAA6B,CAAC,CAAC"} \ No newline at end of file +{"version":3,"file":"base64.js","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":";;AASa,QAAA,kBAAkB,GAAG;;;;;CAKjC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAOC,QAAA,kBAAkB,GAAG,0BAAkB,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE;IACzE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACd,MAAM,CAAC,GAAG,CAAC;AACf,CAAC,EAAE,EAA6B,CAAC,CAAC","sourcesContent":["/**\n * @file Lookup tables for Base64 conversions\n */\n\n/**\n * Lookup table for transforming a 6-bit binary integer into a Base-64 ASCII\n * character.\n * @constant {String[]}\n */\nexport const BASE64_INT_TO_CHAR = `\\\nABCDEFGHIJKLMNOPQRSTUVWXYZ\\\nabcdefghijklmnopqrstuvwxyz\\\n0123456789\\\n+/\\\n`.split('');\n\n/**\n * Inverse lookup table for transformating a Base-64 ASCII character into the\n * corresponding integer value.\n * @constant {Object}\n */\nexport const BASE64_CHAR_TO_INT = BASE64_INT_TO_CHAR.reduce((agg, char, i) => {\n agg[char] = i;\n return agg;\n}, {} as {[key: string]: number});\n"]} \ No newline at end of file diff --git a/lib/constants.js.map b/lib/constants.js.map index 3ab3a56..c6fc2e2 100644 --- a/lib/constants.js.map +++ b/lib/constants.js.map @@ -1 +1 @@ -{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;AAQa,QAAA,QAAQ,GAAG,IAAI,CAAC;AAMhB,QAAA,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAM/B,QAAA,OAAO,GAAG,CAAC,CAAC;AAOZ,QAAA,kBAAkB,GAAG,EAAE,CAAC;AAMxB,QAAA,aAAa,GAAG,EAAE,CAAC;AAMnB,QAAA,iBAAiB,GAAG,CAAC,CAAC;AAMtB,QAAA,gBAAgB,GAAG,EAAE,CAAC;AAMtB,QAAA,gBAAgB,GAAG,CAAC,CAAC;AAMrB,QAAA,mBAAmB,GAAG,CAAC,CAAC"} \ No newline at end of file +{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;AAQa,QAAA,QAAQ,GAAG,IAAI,CAAC;AAMhB,QAAA,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAM/B,QAAA,OAAO,GAAG,CAAC,CAAC;AAOZ,QAAA,kBAAkB,GAAG,EAAE,CAAC;AAMxB,QAAA,aAAa,GAAG,EAAE,CAAC;AAMnB,QAAA,iBAAiB,GAAG,CAAC,CAAC;AAMtB,QAAA,gBAAgB,GAAG,EAAE,CAAC;AAMtB,QAAA,gBAAgB,GAAG,CAAC,CAAC;AAMrB,QAAA,mBAAmB,GAAG,CAAC,CAAC","sourcesContent":["/**\n * @file Parameters used for encoding\n */\n\n/**\n * String terminal character\n * @constant {String}\n */\nexport const TERMINAL = '\\0';\n\n/**\n * Terminal edge\n * @constant {Object}\n */\nexport const TERMINUS = Object.create(null);\n\n/**\n * Encoding version. Bump when breaking encoding changes are introduced.\n * @constant {Number}\n */\nexport const VERSION = 0;\n\n/**\n * Width of header field storing entire header width (including char table).\n * Value is given in Base64 characters (i.e., every six bits)\n * @constant {Number}\n */\nexport const HEADER_WIDTH_FIELD = 10;\n\n/**\n * Width of version field\n * @type {Number}\n */\nexport const VERSION_FIELD = 10;\n\n/**\n * Width of header field representing sign of offset\n * @constant {Number}\n */\nexport const OFFSET_SIGN_FIELD = 1;\n\n/**\n * Width of header field representing unsigned value of offset\n * @constant {Number}\n */\nexport const OFFSET_VAL_FIELD = 21;\n\n/**\n * Width of header field representing the width of the char index in a word\n * @constant {Number}\n */\nexport const CHAR_WIDTH_FIELD = 8;\n\n/**\n * Width of header field representing the width of the offset pointer in a word\n * @constant {Number}\n */\nexport const POINTER_WIDTH_FIELD = 8;\n"]} \ No newline at end of file diff --git a/lib/floor_log2.js.map b/lib/floor_log2.js.map index 0123277..da07388 100644 --- a/lib/floor_log2.js.map +++ b/lib/floor_log2.js.map @@ -1 +1 @@ -{"version":3,"file":"floor_log2.js","sourceRoot":"","sources":["../src/floor_log2.ts"],"names":[],"mappings":";;AASA,oBAA2B,CAAS;IAChC,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACb,CAAC,EAAE,CAAC;IACR,CAAC;IACD,MAAM,CAAC,CAAC,CAAC;AACb,CAAC;AAND,gCAMC"} \ No newline at end of file +{"version":3,"file":"floor_log2.js","sourceRoot":"","sources":["../src/floor_log2.ts"],"names":[],"mappings":";;AASA,oBAA2B,CAAS;IAChC,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACb,CAAC,EAAE,CAAC;IACR,CAAC;IACD,MAAM,CAAC,CAAC,CAAC;AACb,CAAC;AAND,gCAMC","sourcesContent":["/**\n * @file Provides a fast floor_log2 function\n */\n\n/**\n * Fast floor(log2(x)) operation\n * @param {Number} x\n * @return {Number}\n */\nexport function floor_log2(x: number) {\n let n = 0;\n while (x >>= 1) {\n n++;\n }\n return n;\n}\n"]} \ No newline at end of file diff --git a/lib/index.js.map b/lib/index.js.map index 0f0400c..bf8d8be 100644 --- a/lib/index.js.map +++ b/lib/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAIA,iCAA4B;AAC5B,+BAA4B;AAApB,sBAAA,IAAI,CAAA;AAOZ,oBAA2B,OAAiB;IACxC,MAAM,IAAI,GAAG,IAAI,WAAI,EAAE,CAAC;IAExB,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAErC,MAAM,CAAC,IAAI,CAAC;AAChB,CAAC;AAND,gCAMC;AAOD,0BAAiC,KAAe;IAC5C,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;AACtC,CAAC;AAFD,4CAEC"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAIA,iCAA4B;AAC5B,+BAA4B;AAApB,sBAAA,IAAI,CAAA;AAOZ,oBAA2B,OAAiB;IACxC,MAAM,IAAI,GAAG,IAAI,WAAI,EAAE,CAAC;IAExB,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAErC,MAAM,CAAC,IAAI,CAAC;AAChB,CAAC;AAND,gCAMC;AAOD,0BAAiC,KAAe;IAC5C,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;AACtC,CAAC;AAFD,4CAEC","sourcesContent":["/**\n * @file Convenient functional tools for creating Tries from arrays\n */\n\nimport {Trie} from './Trie';\nexport {Trie} from './Trie';\n\n/**\n * Synchronously construct a new Trie out of the given strings.\n * @param {String[]} words\n * @return {Trie}\n */\nexport function createSync(strings: string[]) {\n const trie = new Trie();\n\n strings.forEach(s => trie.insert(s));\n\n return trie;\n}\n\n/**\n * Create a frozen Trie out of given words\n * @param {String[]} words\n * @return {Trie}\n */\nexport function createFrozenSync(words: string[]) {\n return createSync(words).freeze();\n}\n"]} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 4fd41f5..84116d9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,7 @@ "noImplicitAny": true, "removeComments": true, "preserveConstEnums": true, + "inlineSources": true, "sourceMap": true }, "include": ["src/**/*"],