synopsis

0.10.0 • Public • Published

synposis

build status

Synopsis is a tool computing the effective deltas between two updates in a sequence of updates.

The approach I'm taking is to take a granularity N, and then precompute skip deltas of size N, N2, N3, etc.

Simple Counting Example:

// Uber simple Synopsis example that just calculates a running
// total of a sum of integers with granularity of 5
var async = require('async');
var _ = require('lodash');
 
var s = new Synopsis({
  start: 0,
  granularity: 5,
  patcher: function(prev, patch) {
    return prev + patch;
  },
  differ: function(before, after) {
    return after - before;
  }
});
 
async.eachSeries(_.range(1, 1001), function(n, cb) {
  s.patch(1, cb);
}, function(err) {
  s.sum(function(err, s) {
    console.log(s); // Outputs 1000
  });
 
  s.sum(500, function(err, s) {
    console.log(s);  // Outputs 500
  });
 
  s.delta(0, 10, function(err, d) {
    console.log(d); // Outputs 10
  });
 
  s.delta(5, 7, function(err, d) {
    console.log(d); // Outputs 2  
  });
});
 

Configuration

Supports specifying a custom store implementation, defaults to memory store if none is provided.

By doing so, the state of the Synopsis instance can be retained across restarts and none of the delta merging will need to be recomputed.

example:

var s = new Synopsis({
  store: {
    // get the value of the key in the store, or undefined if it isn't
    get: function(key, callback) { ... },
    
    // associate the value to the key in the store, undefined value is effectively a delete operation
    put: function(key, value, callback) { ... },
 
    // optionally define the following if the store provider has a batch operation for them.
    // getAll: function(keys, callback) { ... batch get hash ... }
    // putAll: function(obj, callback) { ... like setAll, but undefined values are deleted ... }
  }
});

Readme

Keywords

none

Package Sidebar

Install

npm i synopsis

Weekly Downloads

4

Version

0.10.0

License

ISC

Last publish

Collaborators

  • allain