DescriptionUpdate: See https://codereview.adblockplus.org/29798570/
The compact trie data structure fits large amounts of filter text in less memory.
Whereas in the standard trie the strings "foobar", "food", and "foist" would result in 10 nodes ("f", "o", "o", "b", "a", "r", "d", "i", "s", and "t"), in the compact trie it results in only 5 nodes ("fo", "o", "bar", "d", "ist"). Insertion and lookup is expected to be significantly slower (not tested), but this can be improved by changing the list of child nodes from a linked list to a hash table.
To add a string to the CompactTrie object:
let trie = new CompactTrie();
let node = trie.set(new Buffer(filterText), lineNumber); // UTF-8
To look up the value associated with a string:
let lineNumber = true.get(filterText);
To retrieve the original string:
let filterText = Buffer.from(node.bytes(), "ascii").toString();
How to test it:
emcc -s TOTAL_MEMORY=16MB --bind -O3 -o CompactTrie.js CompactTrie.cpp
node --expose-gc main.js < easylist.txt
Patch Set 1 #
Total comments: 5
MessagesTotal messages: 3
|