Index: main.js |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/main.js |
@@ -0,0 +1,36 @@ |
+let readline = require("readline"); |
+ |
+let Module = require("./CompactTrie"); |
+ |
+let rl = readline.createInterface({input: process.stdin, terminal: false}); |
+ |
+let lineNumber = 0; |
+let trie = null; |
+ |
+function printMemoryUsage() |
+{ |
+ let m = process.memoryUsage(); |
+ for (let k in m) |
+ console.log(k + ": " + |
+ String(m[k] / 1024 / 1024).replace(/(\d\.\d\d).*/, "$1")); |
+} |
+ |
+rl.on("line", line => |
+{ |
+ if (!trie) |
+ trie = new Module.CompactTrie(); |
+ |
+ let node = trie.set(new Buffer(line), ++lineNumber); |
+ if (trie.get(new Buffer(line)) != lineNumber) |
+ throw "!"; |
+ console.log(Buffer.from(node.bytes(), "ascii").toString()); |
+}); |
+ |
+rl.on("close", () => |
+{ |
+ global.gc(); |
+ printMemoryUsage(); |
+ |
+ trie.delete(); |
+ trie = null; |
+}); |