Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: main.js

Issue 29794564: [proof-of-concept] Compact trie (Closed)
Patch Set: Created May 30, 2018, 11:12 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« CompactTrie.cpp ('K') | « CompactTrie.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
+});
« CompactTrie.cpp ('K') | « CompactTrie.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld