| var hyperdb = require('hyperdb') | |
| var hypercore = require('hypercore') | |
| var hyperdiscovery = require('hyperdiscovery') | |
| var pages = require('random-access-page-files') | |
| var raf = require('random-access-file') | |
| var ram = require('random-access-memory') | |
| var st = process.argv.indexOf('--ram') > -1 ? ram : storage | |
| var optimized = process.argv.indexOf('--optimized') > -1 | |
| var db = hyperdb([ | |
| hypercore(st, '48e2619899edb24f4d5031b5e0cf16e6caef0cc20710c8c60783428f4e8d2ef3', {valueEncoding: 'json', sparse: true}) | |
| ]) | |
| var word = process.argv[2] || 'hello' | |
| db.ready(function () { | |
| var sw = hyperdiscovery(db, {live: true}) | |
| if (process.argv.indexOf('--sync') > -1) { | |
| db.feeds[0].download({start: 0, end: -1}) | |
| return | |
| } | |
| console.log('Joining swarm ...') | |
| db.feeds[0].get(0, function () { | |
| // haxx to make sure we have a connection lol | |
| var now = Date.now() | |
| db.feeds[0].on('download', function (index) { | |
| console.log('Downloaded block', index) | |
| }) | |
| db.get(word, function (err, nodes) { | |
| console.log('Query took', Date.now() - now, 'ms') | |
| console.log() | |
| if (nodes && nodes[0] && nodes[0].key === word) { | |
| console.log('"' + word + '" is an English word') | |
| } else { | |
| console.log('"' + word + '" is *not* an English word') | |
| } | |
| console.log() | |
| console.log('Shutting down swarm ...') | |
| sw.destroy() | |
| }) | |
| }) | |
| }) | |
| function storage (name) { | |
| if (name === 'data') return pages('words.db/data') | |
| return raf('words.db/' + name) | |
| } | |
| function noop () {} |
| { | |
| "name": "hyperdictionary", | |
| "version": "0.0.0", | |
| "main": "hyperdictionary.js", | |
| "dependencies": { | |
| "hypercore": "^6.3.8", | |
| "hyperdb": "github:mafintosh/hyperdb", | |
| "hyperdiscovery": "^6.0.4", | |
| "random-access-file": "^1.7.3", | |
| "random-access-memory": "^2.4.0", | |
| "random-access-page-files": "^1.0.1" | |
| } | |
| } |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
|
Tested on WebRebels network (--ram forces a cold cache)
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
mafintosh
Jun 2, 2017
> node hyperdictionary.js hello --ram --optimized
Joining swarm ...
Trying optimized query for "hello" (will by dynamic in the future)
Downloaded block 336340
Downloaded block 344938
Downloaded block 353355
Downloaded block 129848
Downloaded block 354983
Downloaded block 354963
Downloaded block 354982
Downloaded block 354882
Downloaded block 354763
Query took 83 ms
"hello" is an English word
Shutting down swarm ...
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
|
hyperdb now supports optimised queries on all keys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tested on WebRebels network (--ram forces a cold cache)