tethys.backend/resources/js/Components/SimplePasswordMeter/logic/Trie.ts

31 lines
717 B
TypeScript
Raw Normal View History

import TrieNode from './TieNode';
export default class Trie {
private root: TrieNode;
constructor() {
this.root = new TrieNode();
}
insert(word: string) {
let node: TrieNode = this.root;
for (let char of word) {
if (!node.children[char]) {
node.children[char] = new TrieNode();
}
node = node.children[char];
}
node.isEndOfWord = true;
}
search(word: string) {
let node = this.root;
for (let char of word) {
if (!node.children[char]) {
return false;
}
node = node.children[char];
}
return node.isEndOfWord;
}
}