@autorest/powershell
Version:
AutoRest PowerShell Cmdlet Generator
45 lines • 1.58 kB
JavaScript
/* eslint-disable prefer-const */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.TrieNode = void 0;
class TrieNode {
constructor(value) {
this.value = value;
this.children = new Map();
this.isEnd = false;
}
addChild(child) {
if (typeof child === 'string' && !this.children.has(child)) {
this.children.set(child, new TrieNode(child));
}
else if (child instanceof TrieNode && !this.children.has(child.value)) {
this.children.set(child.value, child);
}
else {
throw new Error('invalid trie node or trie node value.');
}
}
hasChild(child) {
let value;
if (typeof child === 'string') {
value = child;
}
else if (child instanceof TrieNode) {
value = child.value;
}
else {
throw new Error('invalid trie node or trie node value.');
}
return this.children.has(value);
}
getChild(key) {
return this.children.get(key);
}
}
exports.TrieNode = TrieNode;
//# sourceMappingURL=TrieNode.js.map
;