From 6efed770d0eb7f982f94802a2059ceeecdc5c4e6 Mon Sep 17 00:00:00 2001 From: apex Date: Sat, 28 Jun 2025 12:53:01 -0400 Subject: [PATCH] optimized trie and added optional configuration :3 --- gendictionary.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/gendictionary.js b/gendictionary.js index cd237e1..e02f6fe 100644 --- a/gendictionary.js +++ b/gendictionary.js @@ -1,6 +1,9 @@ const fs = require('fs'); const rl = require('readline') +const trie = true; +const trieLevel = 4; //size between cuts for trie ex 4 : "/exam/ple" + const dictPath = "./dictionary/"; const language = "en" @@ -31,11 +34,18 @@ reader.on('line', (line) => { function getPath(word){ let path = ""; - for (let i = 0; i < word.length; i+=2){ - path += word[i] + (word[i+1] ?? ""); - path += "/"; + if (trie){ + for (let i = 0; i < word.length; i+=trieLevel){ + for (let n = 0; n < trieLevel; n++){ + path += word[i+n] ?? ""; + } + path += "/"; + } + } else { + path = word + '/'; } - return path; + + return path.toLowerCase(); } function writeThesaurus(thispath, entry) {