Generator/Iterator handling.
- Source:
Methods
-
<static> newResolver(generator, remote, serialize, deserialize)
-
Creates a new resolver.
Parameters:
Name Type Description generator
external:Generator the generator yielding local items. remote
Summarizer summarizer producing summaires of the remote side. serialize
Serial~Serialize the item serializer. deserialize
Serial~Deserialize the item deserializer. - Source:
Example
var remote = ... var items = [{ from: 1, to: 2 }, { from: 2, to: 5}]; function* generator() { var i, l = items.length; for (i = 0; i < l; i++) { yield items[i]; } } function serialize(item) { return new Int32Array([item.from, item.to]).buffer; } function deserialize(buffer) { var arr = new Int32Array(buffer); return { from: arr[0], to: arr[1] }; } var resolver = require('mathsync/generator').newResolver(generator, remote, serialize, deserialize);
-
<static> newSummarizer(generator, serialize, digester, selector)
-
Creates a new summarizer.
Parameters:
Name Type Argument Description generator
external:Generator the generator yielding local items. serialize
Serial~Serialize the item serializer. digester
Digest~Digester <optional>
the digester to use, defaults to SHA-1. selector
BucketSelector~Selector <optional>
how to place items in IBF buckets, uses 3 buckets by default. - Source:
Examples
var items = [{ from: 1, to: 2 }, { from: 2, to: 5}]; function* generator() { var i, l = items.length; for (i = 0; i < l; i++) { yield items[i]; } } function serialize(item) { return new Int32Array([item.from, item.to]).buffer; } var summarizer = require('mathsync/generator').newSummarizer(generator, serialize);
var data = { key1: "value", key2: "other" }; var summarizer = require('mathsync/generator').newSummarizer(function* () { for (var k in data) { if (data.hasOwnProperty(k)) { yield k + ':' + data[k]; } } }, require('mathsync/string').newSerializer());