Class: Summary

Summary

new Summary()

Represents summarized data.

A summary is an immutable data structure, new instances are returned by method but do not modify inner state

Source:

Methods

minus(item) → {Summary}

Removes an item from the summary.

When both summaries can be viewed as a difference:

  • if the item is in the added set of that summary, it is in none of the resulting summary difference sets
  • if the item is in none of the difference sets of that summary, it is in the removed set of the resulting difference
  • if the item is in the removed set of that summary, the resulting summary may be impossible to decipher

Parameters:
Name Type Description
item external:ArrayBuffer the serialized item.
Source:
Returns:
a new summary instance excluding this item.
Type
Summary

minusMany(updater) → {external:Promise.<Summary>}

Removes several items to the summary.

Equivalent to repeatedly calling Summary#minus for each element reported in the updater, but this method can do optimizations for batch updates.

The promise returned by this method resolves once the updater reports finishing its work, or rejects if the updater reports an issue.

Parameters:
Name Type Description
updater Summary~SummaryBatchUpdater an updater which will report items to remove.
Source:
Returns:
a promise which will resolve to a summary.
Type
external:Promise.<Summary>

plus(item) → {Summary}

Adds an item to the summary.

When both summaries can be viewed as a difference:

  • if the item is in the removed set of that summary, it is in none of the resulting summary difference sets
  • if the item is in none of the difference sets of that summary, it is in the added set of the resulting difference
  • if the item is in the added set of that summary, the resulting summary may be impossible to decipher

Parameters:
Name Type Description
item external:ArrayBuffer the serialized item.
Source:
Returns:
a new summary instance including this item.
Type
Summary

plusMany(updater) → {external:Promise.<Summary>}

Adds several items to the summary.

Equivalent to repeatedly calling Summary#plus for each element reported in the updater, but this method can do optimizations for batch updates.

The promise returned by this method resolves once the updater reports finishing its work, or rejects if the updater reports an issue.

Parameters:
Name Type Description
updater Summary~SummaryBatchUpdater an updater which will report items to add.
Source:
Returns:
a promise which will resolve to a summary.
Type
external:Promise.<Summary>

toDifference() → {Difference.<external:ArrayBuffer>}

Retrieves a view of the summary as a difference.
Source:
Returns:
a difference view of the summary or null if it cannot be resolved with the information it contains.
Type
Difference.<external:ArrayBuffer>

toJSON() → {Object}

Retrieves a JSON view of the summary.
Source:
Returns:
a JSON view of the summary.
Type
Object

<inner> SummaryBatchUpdater(item, done, fail)

Adds/removes multiple items to a summary.

This function is provided to the summary and called by it with appropriate parameters. The function is then responsible for calling item function repeatedly with a single argument being the buffer representing the item to add or remove. Once all items have been, the done method has to be called to notify the summary batch update is finished. If any issue occurs, call fail function with an error object.

Parameters:
Name Type Description
item function a function to call on each item to add/remove from the summary.
done function a function to call once all items have been added/removed from the summary.
fail function a function to call if any issue occurs.
Source:
Examples

Synchronously add items to the summary

var promise = summary.plusMany(function(item, done) {
 item(new Int8Array([1, 2, 3]).buffer);
 item(new Int8Array([4, 5, 6]).buffer);
 done();
});

Asynchronously add items to the summary, with possible failure

var promise = summary.plusMany(function(item, done, fail) {
 readLines('file.csv', function (err, lines) {
   if (err) {
     return fail(err);
   }
   lines.forEach(function (line) {
     var buffer = ...
     item(line);
   });
   done();
 });
});