Last active
August 29, 2015 14:03
-
-
Save lotem/3aad0a2f77f990278cad to your computer and use it in GitHub Desktop.
Test Trie.reverse_lookup() and Trie.map() features.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var marisa = require('./index.js'); | |
var keyset = marisa.createKeyset(); | |
keyset.push_back("a"); | |
keyset.push_back("app"); | |
keyset.push_back("apple"); | |
var trie = marisa.createTrie(); | |
trie.build(keyset); | |
var agent = marisa.createAgent(); | |
agent.set_query("apple"); | |
while (trie.common_prefix_search(agent)) { | |
var key = agent.key(); | |
console.log(key.ptr().substring(0, key.length())); | |
} | |
trie.save('test.bin'); | |
fs = require('fs'); | |
fs.readFile('test.bin', function (err, data) { | |
if (err) { | |
console.error(err); | |
return; | |
} | |
trie = marisa.createTrie(); | |
trie.map(data); | |
for (var i = 0; i < 3; ++i) { | |
var agent = marisa.createAgent(); | |
agent.set_query(i); | |
trie.reverse_lookup(agent); | |
var key = agent.key(); | |
console.log(i + ": " + key.ptr().substring(0, key.length())); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment