{
type: "user",
id : 42,
version : 5,
firstName : "John",
lastName : "Smith"
/* more */
}
[
{ id: 42, version: 5 }
/* more */
]
function(doc, req) {
return (doc.type && doc.type == "foo")
}
var server, i, diff;
i = 0;
while (!diff) {
server = getFromServer(Math.pow(2, i));
diff = localStore.computeDifference(server);
i++;
}
local.applyDifference(diff);
var ibf = emptyBuckets(n);
// ibf: [{ hash: [], content: [], items: 0 }, ... ]
items.forEach(function(item) {
var bytes = serialize(item);
buckets(bytes).forEach(function (id) {
var bucket = ibf[id % n];
bucket.items++;
bucket.content = xor(bucket.content, bytes);
bucket.hash = xor(bucket.hash, hash(bytes));
});
});
var data = [/* ... */];
function serialize(item) {
var buffer = new Buffer(item.key + ':' + item.value, 'utf-8');
return new Uint8Array(buffer).buffer;
}
var summarizer = require('mathsync').summarizer.fromItems(data, serialize);
app.use(route.get('/summary/:level', function* (level) {
this.body = yield summarizer(level | 0);
}));
var ms = require('mathsync');
var data = [/* ... */];
// local items
function serialize(item) { /* ... */ }
var local = ms.summarizer.fromItems(data, serialize);
// server items
function fetchSummary(level) {
return http.getJson('/summary/' + level);
}
var remote = summarizer.fromJSON(fetchSummary);
// delta
function deserialize(buffer) {
var arr = new Buffer(new Uint8Array(buffer)).toString('utf-8').split(':');
return { key: arr[0], value: arr[1] };
}
var resolve = ms.resolver.fromSummarizers(local, remote, deserialize);
resolve().then(function (difference) { /* ... */ });