OLD | NEW |
(Empty) | |
| 1 let readline = require("readline"); |
| 2 |
| 3 let Module = require("./CompactTrie"); |
| 4 |
| 5 let rl = readline.createInterface({input: process.stdin, terminal: false}); |
| 6 |
| 7 let lineNumber = 0; |
| 8 let trie = null; |
| 9 |
| 10 function printMemoryUsage() |
| 11 { |
| 12 let m = process.memoryUsage(); |
| 13 for (let k in m) |
| 14 console.log(k + ": " + |
| 15 String(m[k] / 1024 / 1024).replace(/(\d\.\d\d).*/, "$1")); |
| 16 } |
| 17 |
| 18 rl.on("line", line => |
| 19 { |
| 20 if (!trie) |
| 21 trie = new Module.CompactTrie(); |
| 22 |
| 23 let node = trie.set(new Buffer(line), ++lineNumber); |
| 24 if (trie.get(new Buffer(line)) != lineNumber) |
| 25 throw "!"; |
| 26 console.log(Buffer.from(node.bytes(), "ascii").toString()); |
| 27 }); |
| 28 |
| 29 rl.on("close", () => |
| 30 { |
| 31 global.gc(); |
| 32 printMemoryUsage(); |
| 33 |
| 34 trie.delete(); |
| 35 trie = null; |
| 36 }); |
OLD | NEW |