diff --git a/package.json b/package.json index 44f734b..5a6ef84 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "universe", - "version": "0.5.0", + "version": "0.5.1", "description": "The fastest way to query and explore multivariate datasets", "main": "src/universe.js", "directories": { diff --git a/src/reductioAggregators.js b/src/reductioAggregators.js index b7e0453..b7b2bad 100644 --- a/src/reductioAggregators.js +++ b/src/reductioAggregators.js @@ -66,7 +66,7 @@ function $valueList(reducer, value) { } function $dataList(reducer, value) { - return reducer.dataList(value) + return reducer.dataList(true) } // TODO histograms diff --git a/test/query.spec.js b/test/query.spec.js index 2bdc49a..ad46517 100644 --- a/test/query.spec.js +++ b/test/query.spec.js @@ -346,7 +346,7 @@ describe('universe query', function() { return u.query({ groupBy: 'type', select: { - $dataList: 'total', + $dataList: true, } }) }) diff --git a/universe.js b/universe.js index a0fcbe6..3966599 100644 --- a/universe.js +++ b/universe.js @@ -8539,7 +8539,7 @@ function $valueList(reducer, value) { } function $dataList(reducer, value) { - return reducer.dataList(value) + return reducer.dataList(true) } // TODO histograms @@ -8679,4 +8679,4 @@ function universe(data, options) { },{"./clear":35,"./column":36,"./crossfilter":37,"./filters":40,"./lodash":41,"./q.serial":42,"./query":43,"q":5}]},{},[46])(46) }); -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJub2RlX21vZHVsZXMvYnJvd3NlcmlmeS9ub2RlX21vZHVsZXMvcHJvY2Vzcy9icm93c2VyLmpzIiwibm9kZV9tb2R1bGVzL2Nyb3NzZmlsdGVyMi9jcm9zc2ZpbHRlci5qcyIsIm5vZGVfbW9kdWxlcy9jcm9zc2ZpbHRlcjIvaW5kZXguanMiLCJub2RlX21vZHVsZXMvamF2YXNjcmlwdC1uYXR1cmFsLXNvcnQvbmF0dXJhbFNvcn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aW5nKSB7XG4gICAgICAgIHJldHVybjtcbiAgICB9XG4gICAgdmFyIHRpbWVvdXQgPSBzZXRUaW1lb3V0KGNsZWFuVXBOZXh0VGljayk7XG4gICAgZHJhaW5pbmcgPSB0cnVlO1xuXG4gICAgdmFyIGxlbiA9IHF1ZXVlLmxlbmd0aDtcbiAgICB3aGlsZShsZW4pIHtcbiAgICAgICAgY3VycmVudFF1ZXVlID0gcXVldWU7XG4gICAgICAgIHF1ZXVlID0gW107XG4gICAgICAgIHdoaWxlICgrK3F1ZXVlSW5kZXggPCBsZW4pIHtcbiAgICAgICAgICAgIGlmIChjdXJyZW50UXVldWUpIHtcbiAgICAgICAgICAgICAgICBjdXJyZW50UXVldWVbcXVldWVJbmRleF0ucnVuKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgcXVldWVJbmRleCA9IC0xO1xuICAgICAgICBsZW4gPSBxdWV1ZS5sZW5ndGg7XG4gICAgfVxuICAgIGN1cnJlbnRRdWV1ZSA9IG51bGw7XG4gICAgZHJhaW5pbmcgPSBmYWxzZTtcbiAgICBjbGVhclRpbWVvdXQodGltZW91dCk7XG59XG5cbnByb2Nlc3MubmV4dFRpY2sgPSBmdW5jdGlvbiAoZnVuKSB7XG4gICAgdmFyIGFyZ3MgPSBuZXcgQXJyYXkoYXJndW1lbnRzLmxlbmd0aCAtIDEpO1xuICAgIGlmIChhcmd1bWVudHMubGVuZ3RoID4gMSkge1xuICAgICAgICBmb3IgKHZhciBpID0gMTsgaSA8IGFyZ3VtZW50cy5sZW5ndGg7IGkrKykge1xuICAgICAgICAgICAgYXJnc1tpIC0gMV0gPSBhcmd1bWVudHNbaV07XG4gICAgICAgIH1cbiAgICB9XG4gICAgcXVldWUucHVzaChuZXcgSXRlbShmdW4sIGFyZ3MpKTtcbiAgICBpZiAocXVldWUubGVuZ3RoID09PSAxICYmICFkcmFpbmluZykge1xuICAgICAgICBzZXRUaW1lb3V0KGRyYWluUXVldWUsIDApO1xuICA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c3MrK10gPSBhW2dyZWF0XTtcbiAgICAgICAgICAgICAgYVtncmVhdC0tXSA9IGVrO1xuICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIGFba10gPSBhW2dyZWF0XTtcbiAgICAgICAgICAgICAgYVtncmVhdC0tXSA9IGVrO1xuICAgICAgICAgICAgICAvLyBOb3RlOiBpZiBncmVhdCA8IGsgdGhlbiB3ZSB3aWxsIGV4aXQgdGhlIG91dGVyIGxvb3AgYW5kIGZpeFxuICAgICAgICAgICAgICAvLyBpbnZhcmlhbnQgMiAod2hpY2ggd2UganVzdCB2aW9sYXRlZCkuXG4gICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgIH0gZWxzZSB7XG5cbiAgICAgIC8vIFdlIHBhcnRpdGlvbiB0aGUgbGlzdCBpbnRvIHRocmVlIHBhcnRzOlxuICAgICAgLy8gIDEuIDwgcGl2b3QxXG4gICAgICAvLyAgMi4gPj0gcGl2b3QxICYmIDw9IHBpdm90MlxuICAgICAgLy8gIDMuID4gcGl2b3QyXG4gICAgICAvL1xuICAgICAgLy8gRHVyaW5nIHRoZSBsb29wIHdlIGhhdmU6XG4gICAgICAvLyBbIHwgPCBwaXZvdDEgfCA+PSBwaXZvdDEgJiYgPD0gcGl2b3QyIHwgdW5wYXJ0aXRpb25lZCAgfCA+IHBpdm90MiAgfCBdXG4gICAgICAvLyAgXiAgICAgICAgICAgIF4gICAgICAgICAgICAgICAgICAgICAgICBeICAgICAgICAgICAgICBeICAgICAgICAgICAgIF5cbiAgICAgIC8vIGxlZnQgICAgICAgICBsZXNzICAgICAgICAgICAgICAgICAgICAgayAgICAgICAgICAgICAgZ3JlYXQgICAgICAgIHJpZ2h0XG4gICAgICAvL1xuICAgICAgLy8gYVtsZWZ0XSBhbmQgYVtyaWdodF0gYXJlIHVuZGVmaW5lZCBhbm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gIGNvbnRpbnVlO1xuICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIC8vIGFbZ3JlYXRdIDw9IHBpdm90Mi5cbiAgICAgICAgICAgICAgICBpZiAoZ3JlYXRWYWx1ZSA8IHBpdm90VmFsdWUxKSB7XG4gICAgICAgICAgICAgICAgICAvLyBUcmlwbGUgZXhjaGFuZ2UuXG4gICAgICAgICAgICAgICAgICBhW2tdID0gYVtsZXNzXTtcbiAgICAgICAgICAgICAgICAgIGFbbGVzcysrXSA9IGFbZ3JlYXRdO1xuICAgICAgICAgICAgICAgICAgYVtncmVhdC0tXSA9IGVrO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAvLyBhW2dyZWF0XSA+PSBwaXZvdDEuXG4gICAgICAgICAgICAgICAgICBhW2tdID0gYVtncmVhdF07XG4gICAgICAgICAgICAgICAgICBhW2dyZWF0LS1dID0gZWs7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuXG4gICAgLy8gTW92ZSBwaXZvdHMgaW50byB0aGVpciBmaW5hbCBwb3NpdGlvbnMuXG4gICAgLy8gV2Ugc2hydW5rIHRoZSBsaXN0IGZyb20gYm90aCBzaWRlcyAoYVtsZWZ0XSBhbmQgYVtyaWdodF0gaGF2ZVxuICAgIC8vIG1lYW5pbmdsZXNzIHZhbHVlcyBpbiB0aGVtKSBhbmQgbm93IHdlIG1vdmUgZWxlbWVudHMgZnJvbSB0aGUgZmlyc3RcbiAgICAvLyBhbmQgdGhpcmQgcGFydGl0aW9uIGludG8gdGhlc2UgbG9jYXRpb25zIHNvIHRoYXQgd2UgY2FuIHN0b3JlIHRoZVxuICAgIC8vIHBpdm90cy5cbiAgICBhW2xvXSA9IGFbbGVzcyAtIDFdO1xuICAgIGFbb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Vsc2Uge1xuICAgICAgICAgICAgICAgIC8vIGFbZ3JlYXRdIDwgcGl2b3QyLlxuICAgICAgICAgICAgICAgIGlmIChncmVhdFZhbHVlIDwgcGl2b3RWYWx1ZTEpIHtcbiAgICAgICAgICAgICAgICAgIC8vIFRyaXBsZSBleGNoYW5nZS5cbiAgICAgICAgICAgICAgICAgIGFba10gPSBhW2xlc3NdO1xuICAgICAgICAgICAgICAgICAgYVtsZXNzKytdID0gYVtncmVhdF07XG4gICAgICAgICAgICAgICAgICBhW2dyZWF0LS1dID0gZWs7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgIC8vIGFbZ3JlYXRdID09IHBpdm90MS5cbiAgICAgICAgICAgICAgICAgIGFba10gPSBhW2dyZWF0XTtcbiAgICAgICAgICAgICAgICAgIGFbZ3JlYXQtLV0gPSBlaztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG5cbiAgICAvLyBUaGUgc2Vjb25kIHBhcnRpdGlvbiBoYXMgbm93IGJlZW4gY2xlYXJlZCBvZiBwaXZvdCBlbGVtZW50cyBhbmQgbG9va3NcbiAgICAvLyBhcyBmb2xsb3dzOlxuICAgIC8vIFsgICogIHwgID4gcGl2b3QxICYmIDwgcGl2b3QyICB8ICogXVxuICAgIC8vICAgICAgICBeICAgICAgICAgICAgICAgICAgICAgIF5cbiAgICAvLyAgICAgICBsZXNzICAgICAgICAgICAgICAgICAgZ3JlYXRcbiAgICAvLyBTb3J0IHRoZSBzZWNvbmQgcGFydGl0aW9uIHVzaW5nIHJlY3Vyc2l2ZSBkZXNjZW50LlxuXG4gICAgLy8gVGhlIHNlY29uZCBwYXJ0aXRpb24gbG9va3MgYXMgZm9sbG93czpcbiAgICAvLyBbICAqICB8ICA+PSBwaXZvdDEgJi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93c1tpXSkpIHtcbiAgICAgICAgICAgIGFycmF5LnB1c2goZGF0YVtqXSk7XG4gICAgICAgICAgICAtLWs7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG5cbiAgICAgIHJldHVybiBhcnJheTtcbiAgICB9XG5cbiAgICAvLyBSZXR1cm5zIHRoZSBib3R0b20gSyBzZWxlY3RlZCByZWNvcmRzIGJhc2VkIG9uIHRoaXMgZGltZW5zaW9uJ3Mgb3JkZXIuXG4gICAgLy8gTm90ZTogb2JzZXJ2ZXMgdGhpcyBkaW1lbnNpb24ncyBmaWx0ZXIsIHVubGlrZSBncm91cCBhbmQgZ3JvdXBBbGwuXG4gICAgZnVuY3Rpb24gYm90dG9tKGspIHtcbiAgICAgIHZhciBhcnJheSA9IFtdLFxuICAgICAgICAgIGksXG4gICAgICAgICAgajtcblxuICAgICAgaWYoaXRlcmFibGUpIHtcbiAgICAgICAgLy8gQWRkIGVtcHR5IHJvd3MgYXQgdGhlIHRvcFxuICAgICAgICBmb3IoaSA9IDA7IGkgPCBpdGVyYWJsZXNFbXB0eVJvd3MubGVuZ3RoICYmIGsgPiAwOyBpKyspIHtcbiAgICAgICAgICBpZihmaWx0ZXJzLnplcm8oaiA9IGl0ZXJhYmxlc0VtcHR5Um93c1tpXSkpIHtcbiAgICAgICAgICAgIGFycmF5LnB1c2goZGF0YVtqXSk7XG4gICAgICAgICAgICAtLWs7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG5cbiAgICAgIGkgPSBsbzA7XG5cbiAgICAgIHdoaWxlIChpIDwgaGkwICYmIGsgPiAwKSB7XG4gICAgICAgIGlmIChmaWx0ZXJzLnplcm8oaiA9IGluZGV4W2ldKSkge1xuICAgICAgICAgIGFycmF5LnB1c2goZGF0YVtqXSk7XG4gICAgICAgICAgLS1rO1xuICAgICAgICB9XG4gICAgICAgIGkrKztcbiAgICAgIH1cblxuICAgICAgcmV0dXJuIGFycmF5O1xuICAgIH1cblxuICAgIC8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aW5kZXggb2YgdGhlIG9sZCBncm91cC5cbiAgICAgICAgd2hpbGUgKGkwIDwgazApIHtcbiAgICAgICAgICBncm91cHNbcmVJbmRleFtpMF0gPSBrXSA9IG9sZEdyb3Vwc1tpMCsrXTtcbiAgICAgICAgICBncm91cEluY3JlbWVudCgpO1xuICAgICAgICB9XG5cblxuICAgICAgICAvLyBGaWxsIGluIGdhcHMgd2l0aCBlbXB0eSBhcnJheXMgd2hlcmUgdGhlcmUgbWF5IGhhdmUgYmVlbiByb3dzIHdpdGggZW1wdHkgaXRlcmFibGVzXG4gICAgICAgIGlmKGl0ZXJhYmxlKXtcbiAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwgZ3JvdXBJbmRleC5sZW5ndGg7IGkrKykge1xuICAgICAgICAgICAgaWYoIWdyb3VwSW5kZXhbaV0pe1xuICAgICAgICAgICAgICBncm91cEluZGV4W2ldID0gW11cbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICAvLyBJZiB3ZSBhZGRlZCBhbnkgbmV3IGdyb3VwcyBiZWZvcmUgYW55IG9sZCBncm91cHMsXG4gICAgICAgIC8vIHVwZGF0ZSB0aGUgZ3JvdXAgaW5kZXggb2YgYWxsIHRoZSBvbGQgcmVjb3Jkcy5cbiAgICAgICAgaWYoayA+IGkwKXtcbiAgICAgICAgICBpZihpdGVyYWJsZSl7XG4gICAgICAgICAgICBncm91cEluZGV4ID0gcGVybXV0ZShncm91cEluZGV4LCByZUluZGV4LCB0cnVlKVxuICAgICAgICAgIH1cbiAgICAgICAgICBlbHNle1xuICAgICAgICAgICAgZm9yIChpMCA9IDA7IGkwIDwgbjA7ICsraTApIHtcbiAgICAgICAgICAgICAgZ3JvdXBJbmRleFtpMF0gPSByZUluZGV4W2dyb3VwSW5kZXhbaTBdXTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICAvLyBNb2RpZnkgdGhlIHVwZGF0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gICAgICAgIC8vIHRoZSBiZWdpbm5pbmcgb2YgdGhlIGFycmF5LlxuICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBqID0gMDsgaSA8IG47ICsraSkge1xuICAgICAgICAgICAgaWYgKCFmaWx0ZXJzLnplcm8oaSkpIHtcbiAgICAgICAgICAgICAgc2Vlbkdyb3Vwc1tncm91cEluZGV4W2pdID0gZ3JvdXBJbmRleFtpXV0gPSAxO1xuICAgICAgICAgICAgICArK2o7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuXG4gICAgICAgICAgLy8gUmVhc3NlbWJsZSBncm91cHMgaW5jbHVkaW5nIG9ubHkgdGhvc2UgZ3JvdXBzIHRoYXQgd2VyZSByZWZlcnJlZFxuICAgICAgICAgIC8vIHRvIGJ5IG1hdGNoaW5nIGdyb3VwIGluZGV4IGVudHJpZXMuICBOb3RlIHRoZSBuZXcgZ3JvdXAgaW5kZXggaW5cbiAgICAgICAgICAvLyBzZWVuR3JvdXBzLlxuICAgICAgICAgIGdyb3VwcyA9IFtdLCBrID0gMDtcbiAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwgb2xkSzsgKytpKSB7XG4gICAgICAgICAgICBpZiAoc2Vlbkdyb3Vwc1tpXSkge1xuICAgICAgICAgICAgICBzZWVuR3JvdXBzW2ldID0gaysrO1xuICAgICAgICAgICAgICBncm91cHMucHVzaChvbGRHcm91cHNbaV0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cblxuICAgICAgICAgIGlmIChrID4gMSkge1xuICAgICAgICAgICAgLy8gUmVpbmRleCB0aGUgZ3JvdXAgaW5kZXggdXNpbmcgc2Vlbkdyb3VwcyB0byBmaW5kIHRoZSBuZXcgaW5kZXguXG4gICAgICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IGo7ICsraSkgZ3JvdXBJbmRleFtpXSA9IHNlZW5Hcm91cHNbZ3JvdXBJbmRleFtpXV07XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAg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lsdGVyT2Zmc2V0LCBhZGRlZCwgcmVtb3ZlZCwgbm90RmlsdGVyKSB7XG5cbiAgICAgICAgaWYgKChmaWx0ZXJPbmUgPT09IG9uZSAmJiBmaWx0ZXJPZmZzZXQgPT09IG9mZnNldCkgfHwgcmVzZXROZWVkZWQpIHJldHVybjtcblxuICAgICAgICB2YXIgaSxcbiAgICAgICAgICAgIGosXG4gICAgICAgICAgICBrLFxuICAgICAgICAgICAgbixcbiAgICAgICAgICAgIGc7XG5cbiAgICAgICAgaWYoaXRlcmFibGUpe1xuICAgICAgICAgIC8vIEFkZCB0aGUgYWRkZWQgdmFsdWVzLlxuICAgICAgICAgIGZvciAoaSA9IDAsIG4gPSBhZGRlZC5sZW5ndGg7IGkgPCBuOyArK2kpIHtcbiAgICAgICAgICAgIGlmIChmaWx0ZXJzLnplcm9FeGNlcHQoayA9IGFkZGVkW2ldLCBvZmZzZXQsIHplcm8pKSB7XG4gICAgICAgICAgICAgIGZvciAoaiA9IDA7IGogPCBncm91cEluZGV4W2tdLmxlbmd0aDsgaisrKSB7XG4gICAgICAgICAgICAgICAgZyA9IGdyb3Vwc1tncm91cEluZGV4W2tdW2pdXTtcbiAgICAgICAgICAgICAgICBnLnZhbHVlID0gcmVkdWNlQWRkKGcudmFsdWUsIGRhdGFba10sIGZhbHNlLCBqKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cblxuICAgICAgICAgIC8vIFJlbW92ZSB0aGUgcmVtb3ZlZCB2YWx1ZXMuXG4gICAgICAgICAgZm9yIChpID0gMCwgbiA9IHJlbW92ZWQubGVuZ3RoOyBpIDwgbjsgKytpKSB7XG4gICAgICAgICAgICBpZiAoZmlsdGVycy5vbmx5RXhjZXB0KGsgPSByZW1vdmVkW2ldLCBvZmZzZXQsIHplcm8sIGZpbHRlck9mZnNldCwgZmlsdGVyT25lKSkge1xuICAgICAgICAgICAgICBmb3IgKGogPSAwOyBqIDwgZ3JvdXBJbmRleFtrXS5sZW5ndGg7IGorKykge1xuICAgICAgICAgICAgICAgIGcgPSBncm91cHNbZ3JvdXBJbmRleFtrXVtqXV07XG4gICAgICAgICAgICAgICAgZy52YWx1ZSA9IHJlZHVjZVJlbW92ZShnLnZhbHVlLCBkYXRhW2tdLCBub3RGaWx0ZXIsIGopO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfVxuXG4gICAgICAgIC8vIEFkZCB0aGUgYWRkZWQgdmFsdWVzLlxuICAgICAgICBmb3IgKGkgPSAwLCBuID0gYWRkZWQubGVuZ3RoOyBpIDwgbjsgKytpKSB7XG4gICAgICAgICAgaWYgKGZpbHRlcnMuemVyb0V4Y2VwdChrID0gYWRkZWRbaV0sIG9mZnNldCwgemVybykpIHtcbiAgICAgICAgICAgIGcgPSBncm91cHNbZ3JvdXBJbmRleFtrXV07XG4gICAgICAgICAgICBnLnZhbHVlID0gcmVkdWNlQWRkKGcudmFsdWUsIGRhdGFba10sIGZhbHNlKTtcbiAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICAvLyBSZW1vdmUgdGhlIHJlbW92ZWQgdmFsdWVzLlxuICAgICAgICBmb3IgKGkgPSAwLCBuID0gcmVtb3ZlZC5sZW5ndGg7IGkgPCBuOyArK2kpIHtcbiAgICAgICAgICBpZiAoZmlsdGVycy5vbmx5RXhjZXB0KGsgPSByZW1vdmVkW2ldLCBvZmZzZXQsIHplcm8sIGZpbHRlck9mZnNldCwgZmlsdGVyT25lKSkge1xuICAgICAgICAgICAgZyA9IGdyb3Vwc1tncm91cEluZGV4W2tdXTtcbiAgICAgICAgICAgIGcudmFsdWUgPSByZWR1Y2VSZW1vdmUoZy52YWx1ZSwgZGF0YVtrXSwgbm90RmlsdGVyKTtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cblxuICAgICAgLy8gUmVkdWNlcyB0aGUgc3BlY2lmaWVkI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nZhbHVlID0gcmVkdWNlQWRkKGcudmFsdWUsIGRhdGFbaV0sIHRydWUsIGopO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbjsgKytpKSB7XG4gICAgICAgICAgICBpZiAoIWZpbHRlcnMuemVyb0V4Y2VwdChpLCBvZmZzZXQsIHplcm8pKSB7XG4gICAgICAgICAgICAgIGZvciAoaiA9IDA7IGogPCBncm91cEluZGV4W2ldLmxlbmd0aDsgaisrKSB7XG4gICAgICAgICAgICAgICAgZyA9IGdyb3Vwc1tncm91cEluZGV4W2ldW2pdXTtcbiAgICAgICAgICAgICAgICBnLnZhbHVlID0gcmVkdWNlUmVtb3ZlKGcudmFsdWUsIGRhdGFbaV0sIGZhbHNlLCBqKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cblxuICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbjsgKytpKSB7XG4gICAgICAgICAgZyA9IGdyb3Vwc1tncm91cEluZGV4W2ldXTtcbiAgICAgICAgICBnLnZhbHVlID0gcmVkdWNlQWRkKGcudmFsdWUsIGRhdGFbaV0sIHRydWUpO1xuICAgICAgICB9XG4gICAgICAgIGZvciAoaSA9IDA7IGkgPCBuOyArK2kpIHtcbiAgICAgICAgICBpZiAoIWZpbHRlcnMuemVyb0V4Y2VwdChpLCBvZmZzZXQsIHplcm8pKSB7XG4gICAgICAgICAgICBnID0gZ3JvdXBzW2dyb3VwSW5kZXhbaV1dO1xuICAgICAgICAgICAgZy52YWx1ZSA9IHJlZHVjZVJlbW92ZShnLnZhbHVlLCBkYXRhW2ldLCBmYWxzZSk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG5cbiAgICAgIC8vIFJlY29tcHV0ZXMgdGhlIGdyb3VwIHJlZHVjZSB2YWx1ZXMgZnJvbSBzY3JhdGNoLlxu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24gaW4gdGhlIGFzeW5jIHF1ZXVlXG4gICAgZnVuY3Rpb24gcnVuU2luZ2xlKHRhc2ssIGRvbWFpbikge1xuICAgICAgICB0cnkge1xuICAgICAgICAgICAgdGFzaygpO1xuXG4gICAgICAgIH0gY2F0Y2ggKGUpIHtcbiAgICAgICAgICAgIGlmIChpc05vZGVKUykge1xuICAgICAgICAgICAgICAgIC8vIEluIG5vZGUsIHVuY2F1Z2h0IGV4Y2VwdGlvbnMgYXJlIGNvbnNpZGVyZWQgZmF0YWwgZXJyb3JzLlxuICAgICAgICAgICAgICAgIC8vIFJlLXRocm93IHRoZW0gc3luY2hyb25vdXNseSB0byBpbnRlcnJ1cHQgZmx1c2hpbmchXG5cbiAgICAgICAgICAgICAgICAvLyBFbnN1cmUgY29udGludWF0aW9uIGlmIHRoZSB1bmNhdWdodCBleGNlcHRpb24gaXMgc3VwcHJlc3NlZFxuICAgICAgICAgICAgICAgIC8vIGxpc3RlbmluZyBcInVuY2F1Z2h0RXhjZXB0aW9uXCIgZXZlbnRzIChhcyBkb21haW5zIGRvZXMpLlxuICAgICAgICAgICAgICAgIC8vIENvbnRpbnVlIGluIG5leHQgZXZlbnQgdG8gYXZvaWQgdGljayByZWN1cnNpb24uXG4gICAgICAgICAgICAgICAgaWYgKGRvbWFpbikge1xuICAgICAgICAgICAgICAgICAgICBkb21haW4uZXhpdCgpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBzZXRUaW1lb3V0KGZsdXNoLCAwKTtcbiAgICAgICAgICAgICAgICBpZiAoZG9tYWluKSB7XG4gICAgICAgICAgICAgICAgICAgIGRvbWFpbi5lbnRlcigpO1xuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIHRocm93IGU7XG5cbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgLy8gSW4gYnJvd3NlcnMsIHVuY2F1Z2h0IGV4Y2VwdGlvbnMgYXJlIG5vdCBmYXRhbC5cbiAgICAgICAgICAgICAgICAvLyBSZS10aHJvdyB0aGVtIGFzeW5jaHJvbm91c2x5IHRvIGF2b2lkIHNsb3ctZG93bnMuXG4gICAgICAgICAgICAgICAgc2V0VGltZW91dChmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgICAgIHRocm93IGU7XG4gICAgICAgICAgICAgICAgfSwgMCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBpZiAoZG9tYWluKSB7XG4gICAgICAgICAgICBkb21haW4uZXhpdCgpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgbmV4dFRpY2sgPSBmdW5jdGlvbiAodGFzaykge1xuICAgICAgICB0YWlsID0gdGFpbC5uZXh0ID0ge1xuICAgICAgICAgICAgdGFzazogdGFzayxcbiAgICAgICAgICAgIGRvbWFpbjogaXNOb2RlSlMgJiYgcHJvY2Vzcy5kb21haW4sXG4gICAgICAgICAgICBuZXh0OiBudWxsXG4gICAgICAgIH07XG5cbiAgICAgICAgaWYgKCFmbHVzaGluZykge1xuICAgICAgICAgICAgZmx1c2hpbmcgPSB0cnVlO1xuICAgICAgICAgICAgcmVxdWVzdFRpY2soKTtcbiAgICAgICAgfVxuICAgIH07XG5cbiAgICBpZiAodHlwZW9mIHByb2Nlc3MgPT09IFwib2JqZWN0XCIgJiZcbiAgICAgICAgcHJvY2Vzcy50b1N0cmluZygpID09PSBcIltvYmplY3QgcHJvY2Vzc11cIiAmJiBwcm9jZXNzLm5leHRUaWNrKSB7XG4gICAgICAgIC8vIEVuc3VyZSBRIGlzIGluIGEgcmVhbCBOb2RlIGVudmlyb25tZW50LCB3aXRoIGEgYHByb2Nlc3MubmV4dFRpY2tgLlxuICAgICAgICAvLyBUbyBzZWUgdGhyb3VnaCBmYWtlIE5vZGUgZW52aXJvbm1lbnRzOlxuICAgICAgICAvLyAqIE1vY2hhIHRlc3QgcnVubmVyIC0gZXhwb3NlcyBhIGBwcm9jZXNzYCBnbG9iYWwgd2l0aG91dCBh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lcm5pbmcgdGhlIGluaXRpYWwgdmFsdWUsIGlmIG9uZSBpcyBub3QgcHJvdmlkZWRcbiAgICAgICAgaWYgKGFyZ3VtZW50cy5sZW5ndGggPT09IDEpIHtcbiAgICAgICAgICAgIC8vIHNlZWsgdG8gdGhlIGZpcnN0IHZhbHVlIGluIHRoZSBhcnJheSwgYWNjb3VudGluZ1xuICAgICAgICAgICAgLy8gZm9yIHRoZSBwb3NzaWJpbGl0eSB0aGF0IGlzIGlzIGEgc3BhcnNlIGFycmF5XG4gICAgICAgICAgICBkbyB7XG4gICAgICAgICAgICAgICAgaWYgKGluZGV4IGluIHRoaXMpIHtcbiAgICAgICAgICAgICAgICAgICAgYmFzaXMgPSB0aGlzW2luZGV4KytdO1xuICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgaWYgKCsraW5kZXggPj0gbGVuZ3RoKSB7XG4gICAgICAgICAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IHdoaWxlICgxKTtcbiAgICAgICAgfVxuICAgICAgICAvLyByZWR1Y2VcbiAgICAgICAgZm9yICg7IGluZGV4IDwgbGVuZ3RoOyBpbmRleCsrKSB7XG4gICAgICAgICAgICAvLyBhY2NvdW50IGZvciB0aGUgcG9zc2liaWxpdHkgdGhhdCB0aGUgYXJyYXkgaXMgc3BhcnNlXG4gICAgICAgICAgICBpZiAoaW5kZXggaW4gdGhpcykge1xuICAgICAgICAgICAgICAgIGJhc2lzID0gY2FsbGJhY2soYmFzaXMsIHRoaXNbaW5kZXhdLCBpbmRleCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIGJhc2lzO1xuICAgIH1cbik7XG5cbnZhciBhcnJheV9pbmRleE9mID0gdW5jdXJyeVRoaXMoXG4gICAgQXJyYXkucHJvdG90eXBlLmluZGV4T2YgfHwgZn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Wx0O1xuICAgICAgICB0cnkge1xuICAgICAgICAgICAgaWYgKGRlc2NyaXB0b3Jbb3BdKSB7XG4gICAgICAgICAgICAgICAgcmVzdWx0ID0gZGVzY3JpcHRvcltvcF0uYXBwbHkocHJvbWlzZSwgYXJncyk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHJlc3VsdCA9IGZhbGxiYWNrLmNhbGwocHJvbWlzZSwgb3AsIGFyZ3MpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcbiAgICAgICAgICAgIHJlc3VsdCA9IHJlamVjdChleGNlcHRpb24pO1xuICAgICAgICB9XG4gICAgICAgIGlmIChyZXNvbHZlKSB7XG4gICAgICAgICAgICByZXNvbHZlKHJlc3VsdCk7XG4gICAgICAgIH1cbiAgICB9O1xuXG4gICAgcHJvbWlzZS5pbnNwZWN0ID0gaW5zcGVjdDtcblxuICAgIC8vIFhYWCBkZXByZWNhdGVkIGB2YWx1ZU9mYCBhbmQgYGV4Y2VwdGlvbmAgc3VwcG9ydFxuICAgIGlmIChpbnNwZWN0KSB7XG4gICAgICAgIHZhciBpbnNwZWN0ZWQgPSBpbnNwZWN0KCk7XG4gICAgICAgIGlmIChpbnNwZWN0ZWQuc3RhdGUgPT09IFwicmVqZWN0ZWRcIikge1xuICAgICAgICAgICAgcHJvbWlzZS5leGNlcHRpb24gPSBpbnNwZWN0ZWQucmVhc29uO1xuICAgICAgICB9XG5cbiAgICAgICAgcHJvbWlzZS52YWx1ZU9mID0gZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgdmFyIGluc3BlY3RlZCA9IGluc3BlY3QoKTtcbiAgICAgICAgICAgIGlmIChpbnNwZWN0ZWQuc3RhdGUgPT09IFwicGVuZGluZ1wiIHx8XG4gICAgICAgICAgICAgICAgaW5zcGVjdGVkLnN0YXRlID09PSBcInJlamVjdGVkXCIpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gcHJvbWl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SBpdCBwb3NzaWJsZSB0byB1c2UgZ2VuZXJhdG9ycyBpbiBkZXBsb3llZCBicm93c2Vycywgc29cbiAgICAgICAgICAgIC8vIHdlIGFsc28gc3VwcG9ydCBQeXRob24tc3R5bGUgZ2VuZXJhdG9ycy4gIEF0IHNvbWUgcG9pbnQgd2UgY2FuIHJlbW92ZVxuICAgICAgICAgICAgLy8gdGhpcyBibG9jay5cblxuICAgICAgICAgICAgaWYgKHR5cGVvZiBTdG9wSXRlcmF0aW9uID09PSBcInVuZGVmaW5lZFwiKSB7XG4gICAgICAgICAgICAgICAgLy8gRVM2IEdlbmVyYXRvcnNcbiAgICAgICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICAgICAgICByZXN1bHQgPSBnZW5lcmF0b3JbdmVyYl0oYXJnKTtcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHJlamVjdChleGNlcHRpb24pO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBpZiAocmVzdWx0LmRvbmUpIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIFEocmVzdWx0LnZhbHVlKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gd2hlbihyZXN1bHQudmFsdWUsIGNhbGxiYWNrLCBlcnJiYWNrKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIC8vIFNwaWRlck1vbmtleSBHZW5lcmF0b3JzXG4gICAgICAgICAgICAgICAgLy8gRklYTUU6IFJlbW92ZSB0aGlzIGNhc2Ugd2hlbiBTTSBkb2VzIEVTNiBnZW5lcmF0b3JzLlxuICAgICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IGdlbmVyYXRvclt2ZXJiXShhcmcpO1xuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGV4Y2VwdGlvbikge1xuICAgICAgICAgICAgICAgICAgICBpZiAoaXNTdG9wSXRlcmF0aW9uKGV4Y2VwdGlvbikpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBRKGV4Y2VwdGlvbi52YWx1ZSk7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gcmVqZWN0KGV4Y2VwdGlvbik7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgcmV0dXJuIHdoZW4ocmVzdWx0LCBjYWxsYmFjaywgZXJyYmFjayk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgdmFyIGdlbmVyYXRvciA9IG1ha2VHZW5lcmF0b3IuYXBwbHkodGhpcywgYXJndW1lbnRzKTtcbiAgICAgICAgdmFyIGNhbGxiYWNrID0gY29udGludWVyLmJpbmQoY29udGludWVyLCBcIm5leHRcIik7XG4gICAgICAgIHZhciBlcnJiYWNrID0gY29udGludWVyLmJpbmQoY29udGludWVyLCBcInRocm93XCIpO1xuICAgICAgICByZXR1cm4gY2FsbGJhY2soKTtcbiAgICB9O1xufVxuXG4vKipcbiAqIFRoZSBzcGF3biBmdW5jdGlvbiBpcyBhIHNtYWxsIHdyYXBwZXIgYXJvdW5kIGFzeW5jIHRoYXQgaW1tZWRpYXRlbHlcbiAqIGNhbGxzIHRoZSBnZW5lcmF0b3IgYW5kIGFsc28gZW5kcyB0aGUgcHJvbWlzZSBjaGFpbiwgc28gdGhhdCBhbnlcbiAqIHVuaGFuZGxlZCBlcnJvcnMgYXJlIHRocm93biBpbnN0ZWFkIG9mIGZvcndhcmRlZCB0byB0aGUgZXJyb3JcbiAqIGhhbmRsZXIuIFRoaXMgaXMgdXNlZnVsIGJlY2F1c2UgaXQncyBleHRyZW1lbHkgY29tbW9uIHRvIHJ1blxuICogZ2Vu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HVjZShwcm9taXNlcywgZnVuY3Rpb24gKHVuZGVmaW5lZCwgcHJvbWlzZSwgaW5kZXgpIHtcbiAgICAgICAgICAgIHZhciBzbmFwc2hvdDtcbiAgICAgICAgICAgIGlmIChcbiAgICAgICAgICAgICAgICBpc1Byb21pc2UocHJvbWlzZSkgJiZcbiAgICAgICAgICAgICAgICAoc25hcHNob3QgPSBwcm9taXNlLmluc3BlY3QoKSkuc3RhdGUgPT09IFwiZnVsZmlsbGVkXCJcbiAgICAgICAgICAgICkge1xuICAgICAgICAgICAgICAgIHByb21pc2VzW2luZGV4XSA9IHNuYXBzaG90LnZhbHVlO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICArK3BlbmRpbmdDb3VudDtcbiAgICAgICAgICAgICAgICB3aGVuKFxuICAgICAgICAgICAgICAgICAgICBwcm9taXNlLFxuICAgICAgICAgICAgICAgICAgICBmdW5jdGlvbiAodmFsdWUpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHByb21pc2VzW2luZGV4XSA9IHZhbHVlO1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKC0tcGVuZGluZ0NvdW50ID09PSAwKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgZGVmZXJyZWQucmVzb2x2ZShwcm9taXNlcyk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgIGRlZmVycmVkLnJlamVjdCxcbiAgICAgICAgICAgICAgICAgICAgZnVuY3Rpb24gKHByb2dyZXNzKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBkZWZlcnJlZC5ub3RpZnkoeyBpbmRleDogaW5kZXgsIHZhbHVlOiBwcm9ncmVzcyB9KTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0sIHZvaWQgMCk7XG4gICAgICAgIGlmIChwZW5kaW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gICAgIHBlbmRpbmdDb3VudCsrO1xuXG4gICAgICAgIHdoZW4ocHJvbWlzZSwgb25GdWxmaWxsZWQsIG9uUmVqZWN0ZWQsIG9uUHJvZ3Jlc3MpO1xuICAgICAgICBmdW5jdGlvbiBvbkZ1bGZpbGxlZChyZXN1bHQpIHtcbiAgICAgICAgICAgIGRlZmVycmVkLnJlc29sdmUocmVzdWx0KTtcbiAgICAgICAgfVxuICAgICAgICBmdW5jdGlvbiBvblJlamVjdGVkKCkge1xuICAgICAgICAgICAgcGVuZGluZ0NvdW50LS07XG4gICAgICAgICAgICBpZiAocGVuZGluZ0NvdW50ID09PSAwKSB7XG4gICAgICAgICAgICAgICAgZGVmZXJyZWQucmVqZWN0KG5ldyBFcnJvcihcbiAgICAgICAgICAgICAgICAgICAgXCJDYW4ndCBnZXQgZnVsZmlsbG1lbnQgdmFsdWUgZnJvbSBhbnkgcHJvbWlzZSwgYWxsIFwiICtcbiAgICAgICAgICAgICAgICAgICAgXCJwcm9taXNlcyB3ZXJlIHJlamVjdGVkLlwiXG4gICAgICAgICAgICAgICAgKSk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgZnVuY3Rpb24gb25Qcm9ncmVzcyhwcm9ncmVzcykge1xuICAgICAgICAgICAgZGVmZXJyZWQubm90aWZ5KHtcbiAgICAgICAgICAgICAgICBpbmRleDogaW5kZXgsXG4gICAgICAgICAgICAgICAgdmFsdWU6IHByb2dyZXNzXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgIH0sIHVuZGVmaW5lZCk7XG5cbiAgICByZXR1cm4gZGVmZXJyZWQucHJvbWlzZTtcbn1cblxuUHJvbWlzZS5wcm90b3R5cGUuYW55ID0gZnVuY3Rpb24gKCkge1xuICAgIHJldHVybiBhbnkodGhpcyk7XG59O1xuXG4vKipcbiAqIFdhaXRzIGZvciBhbGwgcHJvbWlzZXMgdG8gYmUgc2V0dGxlZCwgZWl0aGVyIGZ1bGZpbGxlZCBvcl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B7XG4gICAgICAgICAgICAgIGFba10gPSBhW2dyZWF0XTtcbiAgICAgICAgICAgICAgYVtncmVhdC0tXSA9IGVrO1xuICAgICAgICAgICAgICAvLyBOb3RlOiBpZiBncmVhdCA8IGsgdGhlbiB3ZSB3aWxsIGV4aXQgdGhlIG91dGVyIGxvb3AgYW5kIGZpeFxuICAgICAgICAgICAgICAvLyBpbnZhcmlhbnQgMiAod2hpY2ggd2UganVzdCB2aW9sYXRlZCkuXG4gICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgIH0gZWxzZSB7XG5cbiAgICAgIC8vIFdlIHBhcnRpdGlvbiB0aGUgbGlzdCBpbnRvIHRocmVlIHBhcnRzOlxuICAgICAgLy8gIDEuIDwgcGl2b3QxXG4gICAgICAvLyAgMi4gPj0gcGl2b3QxICYmIDw9IHBpdm90MlxuICAgICAgLy8gIDMuID4gcGl2b3QyXG4gICAgICAvL1xuICAgICAgLy8gRHVyaW5nIHRoZSBsb29wIHdlIGhhdmU6XG4gICAgICAvLyBbIHwgPCBwaXZvdDEgfCA+PSBwaXZvdDEgJiYgPD0gcGl2b3QyIHwgdW5wYXJ0aXRpb25lZCAgfCA+IHBpdm90MiAgfCBdXG4gICAgICAvLyAgXiAgICAgICAgICAgIF4gICAgICAgICAgICAgICAgICAgICAgICBeICAgICAgICAgICAgICBeICAgICAgICAgICAgIF5cbiAgICAgIC8vIGxlZnQgICAgICAgICBsZXNzICAgICAgICAgICAgICAgICAgICAgayAgICAgICAgICAgICAgZ3JlYXQgICAgICAgIHJpZ2h0XG4gICAgICAvL1xuICAgICAgLy8gYVtsZWZ0XSBhbmQgYVtyaWdodF0gYXJlIHVuZGVmaW5lZCBhbmQgYXJlIGZpbGxlZCBhZnRlciB0aGVcbiAgICAgIC8vIHBhcnRpdGlvbmluZy5cbiAgICAgIC8vXG4gICAgICAvLyBJbnZhcmlhbnRzOlxuICAgICAgLy8gICAxLiBmb3IgeCBpbiBdbGVmdCwgbGVzc1sgOiB4IDwgcGl2b3QxXG4gICAgICAvLyAgIDIuIGZvciB4IGluIFtsZXNzLCBrWyA6IHBpdm90MSA8PSB4ICYmIHggPD0gcGl2b3QyXG4gICAgICAvLyAgIDMuIGZvciB4IGluIF1ncmVhdCwgcmlnaHRbIDogeCA+IHBpdm90MlxuICAgICAgZm9yICh2YXIgayA9IGxlc3M7IGsgPD0gZ3JlYXQ7IGsrKykge1xuICAgICAgICB2YXIgZWsgPSBhW2tdLCB4ayA9IGYoZWspO1xuICAgICAgICBpZiAoeGsgPCBwaXZvdFZhbHVlMSkge1xuICAgICAgICAgIGlmIChrICE9PSBsZXNzKSB7XG4gICAgICAgICAgICBhW2tdID0gYVtsZXNzXTtcbiAgICAgICAgICAgIGFbbGVzc10gPSBlaztcbiAgICAgICAgICB9XG4gICAgICAgICAgKytsZXNzO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIGlmICh4ayA+IHBpdm90VmFsdWUyKSB7XG4gICAgICAgICAgICB3aGlsZSAodHJ1ZSkge1xuICAgICAgICAgICAgICB2YXIgZ3JlYXRWYWx1ZSA9IGYoYVtncmVhdF0pO1xuICAgICAgICAgICAgICBpZiAoZ3JlYXRWYWx1ZSA+IHBpdm90VmFsdWUyKSB7XG4gICAgICAgICAgICAgICAgZ3JlYXQtLTtcbiAgICAgICAgICAgICAgICBpZiAoZ3JlYXQgPCBrKSBicmVhaztcbiAgICAgICAgICAgICAgICAvLyBUaGlzIGlzIHRoZSBvbmx5IGxvY2F0aW9uIGluc2lkZSB0aGUgbG9vcCB3aGVyZSBhIG5ld1xuICAgICAgICAgICAgICAgIC8vIGl0ZXJhdGlvbiBpcyBzdGFydGVkLlxuICAgICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIC8vIGFbZ3JlYXRdIDw9IHBpdm90Mi5cbiAgICAgICAgICAgIC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Gl2b3QyXG4gICAgICAvLyAgIDMuIGZvciB4IGluIF1ncmVhdCwgKiBdIDogeCA9PSBwaXZvdDJcbiAgICAgIGZvciAodmFyIGsgPSBsZXNzOyBrIDw9IGdyZWF0OyBrKyspIHtcbiAgICAgICAgdmFyIGVrID0gYVtrXSwgeGsgPSBmKGVrKTtcbiAgICAgICAgaWYgKHhrIDw9IHBpdm90VmFsdWUxICYmIHhrID49IHBpdm90VmFsdWUxKSB7XG4gICAgICAgICAgaWYgKGsgIT09IGxlc3MpIHtcbiAgICAgICAgICAgIGFba10gPSBhW2xlc3NdO1xuICAgICAgICAgICAgYVtsZXNzXSA9IGVrO1xuICAgICAgICAgIH1cbiAgICAgICAgICBsZXNzKys7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgaWYgKHhrIDw9IHBpdm90VmFsdWUyICYmIHhrID49IHBpdm90VmFsdWUyKSB7XG4gICAgICAgICAgICB3aGlsZSAodHJ1ZSkge1xuICAgICAgICAgICAgICB2YXIgZ3JlYXRWYWx1ZSA9IGYoYVtncmVhdF0pO1xuICAgICAgICAgICAgICBpZiAoZ3JlYXRWYWx1ZSA8PSBwaXZvdFZhbHVlMiAmJiBncmVhdFZhbHVlID49IHBpdm90VmFsdWUyKSB7XG4gICAgICAgICAgICAgICAgZ3JlYXQtLTtcbiAgICAgICAgICAgICAgICBpZiAoZ3JlYXQgPCBrKSBicmVhaztcbiAgICAgICAgICAgICAgICAvLyBUaGlzIGlzIHRoZSBvbmx5IGxvY2F0aW9uIGluc2lkZSB0aGUgbG9vcCB3aGVyZSBhIG5ld1xuICAgICAgICAgICAgICAgIC8vIGl0ZXJhdGlvbiBpcyBzdGFydGVkLlxuICAgICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIC8vIGFbZ3JlYXRdIDwgcGl2b3QyLlxuICAgICAgICAgICAgICAgIGlmIChncmVhdFZhbHVlIDwgcGl2b3RWYWx1ZTEpIHtcbiAgICAgICAgICAgICAgICAgIC8vIFRyaXBsZSBleGNoYW5nZS5cbiAgICAgICAgICAgICAgICAgIGFba10gPSBhW2xlc3NdO1xuICAgICAgICAgICAgICAgICAgYVtsZXNzKytdID0gYVtncmVhdF07XG4gICAgICAgICAgICAgICAgICBhW2dyZWF0LS1dID0gZWs7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgIC8vIGFbZ3JlYXRdID09IHBpdm90MS5cbiAgICAgICAgICAgICAgICAgIGFba10gPSBhW2dyZWF0XTtcbiAgICAgICAgICAgICAgICAgIGFbZ3JlYXQtLV0gPSBlaztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG5cbiAgICAvLyBUaGUgc2Vjb25kIHBhcnRpdGlvbiBoYXMgbm93IGJlZW4gY2xlYXJlZCBvZiBwaXZvdCBlbGVtZW50cyBhbmQgbG9va3NcbiAgICAvLyBhcyBmb2xsb3dzOlxuICAgIC8vIFsgICogIHwgID4gcGl2b3QxICYmIDwgcGl2b3QyICB8ICogXVxuICAgIC8vICAgICAgICBeICAgICAgICAgICAgICAgICAgICAgIF5cbiAgICAvLyAgICAgICBsZXNzICAgICAgICAgICAgICAgICAgZ3JlYXRcbiAgICAvLyBTb3J0IHRoZSBzZWNvbmQgcGFydGl0aW9uIHVzaW5nIHJlY3Vyc2l2ZSBkZXNjZW50LlxuXG4gICAgLy8gVGhlIHNlY29uZCBwYXJ0aXRpb24gbG9va3MgYXMgZm9sbG93czpcbiAgICAvLyBbICAqICB8ICA+PSBwaXZvdDEgJiYgPD0gcGl2b3QyICB8ICogXVxuICAgIC8vICAgICAgICBeICAgICAgICAgICAgICAgICAgICAgICAgXlxuICAgIC8vICAgICAgIGxlc3MgICAgICAgICAgICAgICAgICA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gICAgICAgICAgICAgICByZXR1cm4gcG9zdHByb2Nlc3MuYWxsKCk7XG4gICAgICAgICAgICB9O1xuICAgICAgICAgICAgcG9zdHByb2Nlc3MuYWxsID0gZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgIHJldHVybiBncm91cC5hbGwoKTtcbiAgICAgICAgICAgIH07XG4gICAgICAgICAgICB2YXIgcG9zdHByb2Nlc3NvcnMgPSByZWR1Y3Rpby5wb3N0cHJvY2Vzc29ycztcbiAgICAgICAgICAgIE9iamVjdC5rZXlzKHBvc3Rwcm9jZXNzb3JzKS5mb3JFYWNoKGZ1bmN0aW9uIChuYW1lKSB7XG4gICAgICAgICAgICAgICAgcG9zdHByb2Nlc3NbbmFtZV0gPSBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhciBfYWxsID0gcG9zdHByb2Nlc3MuYWxsO1xuICAgICAgICAgICAgICAgICAgICB2YXIgYXJncyA9IFtdLnNsaWNlLmNhbGwoYXJndW1lbnRzKTtcbiAgICAgICAgICAgICAgICAgICAgcG9zdHByb2Nlc3MuYWxsID0gZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHBvc3Rwcm9jZXNzb3JzW25hbWVdKF9hbGwsIGYsIHApLmFwcGx5KG51bGwsIGFyZ3MpO1xuICAgICAgICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gcG9zdHByb2Nlc3M7XG4gICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgcmV0dXJuIHBvc3Rwcm9jZXNzO1xuICAgICAgICB9O1xuICAgIH07XG59XG5cbm1vZHVsZS5leHBvcnRzID0gcG9zdFByb2Nlc3M7XG4iLCJtb2R1bGUuZXhwb3J0cyA9IGZ1bmN0aW9uKHJlZHVjdGlvKXtcbiAgICByZWR1Y3Rpby5wb3N0cHJvY2Vzc29ycyA9IHt9O1xuICAgIHJlZH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H1cblxuICAgIGlmICghZGVmKSB7XG4gICAgICAvLyBDbGVhciBhbGwgb2YgdGhlIGNvbHVtbiBkZWZlbml0aW9uc1xuICAgICAgcmV0dXJuIFByb21pc2UuYWxsKF8ubWFwKHNlcnZpY2UuY29sdW1ucywgZGlzcG9zZUNvbHVtbikpXG4gICAgICAgIC50aGVuKGZ1bmN0aW9uKCkge1xuICAgICAgICAgIHNlcnZpY2UuY29sdW1ucyA9IFtdXG4gICAgICAgICAgcmV0dXJuIHNlcnZpY2VcbiAgICAgICAgfSlcblxuICAgIH1cblxuXG4gICAgcmV0dXJuIFByb21pc2UuYWxsKF8ubWFwKGRlZiwgZnVuY3Rpb24oZCkge1xuICAgICAgICBpZiAoXy5pc09iamVjdChkKSkge1xuICAgICAgICAgIGQgPSBkLmtleVxuICAgICAgICB9XG4gICAgICAgIC8vIENsZWFyIHRoZSBjb2x1bW5cbiAgICAgICAgdmFyIGNvbHVtbiA9IF8ucmVtb3ZlKHNlcnZpY2UuY29sdW1ucywgZnVuY3Rpb24oYykge1xuICAgICAgICAgIGlmIChfLmlzQXJyYXkoZCkpIHtcbiAgICAgICAgICAgIHJldHVybiAhXy54b3IoYy5rZXksIGQpLmxlbmd0aFxuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAoYy5rZXkgPT09IGQpIHtcbiAgICAgICAgICAgIGlmIChjLmR5bmFtaWNSZWZlcmVuY2UpIHtcbiAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlXG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXR1cm4gdHJ1ZVxuICAgICAgICAgIH1cbiAgICAgICAgfSlbMF1cblxuICAgICAgICBpZiAoIWNvbHVtbikge1xuICAgICAgICAgIC8vIGNvbnNvbGUuaW5mbygnQXR0ZW1wdGVkIHRvIGNsZWFyIGEgY29sdW1uIHRoYXQgaXMgcmVxdWlyZWQgZm9yIGFub3RoZXIgcXVlcnkhJywgYylcbiAgICAgICAgICByZXR1cm5cbiAgICAgICAgfVxuXG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JlZENvbHVtbnMsIGZ1bmN0aW9uKGNvbHVtbktleSkge1xuICAgICAgICAgICAgICByZXR1cm4gc2VydmljZS5jb2x1bW4oe1xuICAgICAgICAgICAgICAgIGtleTogY29sdW1uS2V5LFxuICAgICAgICAgICAgICAgIGR5bmFtaWNSZWZlcmVuY2U6IGdyb3VwXG4gICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICB9KSlcbiAgICAgICAgICAgIC50aGVuKGZ1bmN0aW9uKCkge1xuICAgICAgICAgICAgICByZXR1cm4gdHJ1ZVxuICAgICAgICAgICAgfSlcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gZmFsc2VcbiAgICAgIH0pXG4gICAgICAudGhlbihmdW5jdGlvbihuZWVkc0xpc3RlbmVyKSB7XG4gICAgICAgIC8vIEhlcmUsIHdlIGNyZWF0ZSBhIGxpc3RlbmVyIHRvIHJlY3JlYXRlIGFuZCBhcHBseSB0aGUgcmVkdWNlclxuICAgICAgICAvLyAod2l0aCB1cGRhdGVkIHJlZmVyZW5jZSBkYXRhKSB0b1xuICAgICAgICAvLyB0aGUgZ3JvdXAgYW55dGltZSBkYXRhIGNoYW5nZXMuXG5cbiAgICAgICAgdmFyIHF1ZXJ5UmVzID0ge1xuICAgICAgICAgIC8vIFRoZSBVbml2ZXJzZSBmb3IgY29udGludW91cyBwcm9taXNlIGNoYWluaW5nXG4gICAgICAgICAgdW5pdmVyc2U6IHNlcnZpY2UsXG4gICAgICAgICAgLy8gVGhlIGJhcmUgbWV0YWxxdWVyeVJlcy5kYXRhXG4gICAgICAgICAgY3Jvc3NmaWx0ZXI6IHNlcnZpY2UuY2YsXG4gICAgICAgICAgZGltZW5zaW9uOiBjb2x1bW4uZGltZW5zaW9uLFxuICAgICAgICAgIGdyb3VwOiBncm91cCxcbiAgICAgICAgICAvLyBSZWR1Y3RpbyByZWR1Y2VyIGluc3RhbmNlXG4gICAgICAgICAgcmVkdWNlcjogbnVsbCxcbiAgICAgICAgfVxuXG4gICAgICAg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GlsZSAodHJ1ZSkge1xuICAgICAgICAgICAgdmFyIGdyZWF0VmFsdWUgPSBmKGFbZ3JlYXRdKTtcbiAgICAgICAgICAgIGlmIChncmVhdFZhbHVlID4gcGl2b3RWYWx1ZTEpIHtcbiAgICAgICAgICAgICAgZ3JlYXQtLTtcbiAgICAgICAgICAgICAgLy8gVGhpcyBpcyB0aGUgb25seSBsb2NhdGlvbiBpbiB0aGUgd2hpbGUtbG9vcCB3aGVyZSBhIG5ld1xuICAgICAgICAgICAgICAvLyBpdGVyYXRpb24gaXMgc3RhcnRlZC5cbiAgICAgICAgICAgICAgY29udGludWU7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKGdyZWF0VmFsdWUgPCBwaXZvdFZhbHVlMSkge1xuICAgICAgICAgICAgICAvLyBUcmlwbGUgZXhjaGFuZ2UuXG4gICAgICAgICAgICAgIGFba10gPSBhW2xlc3NdO1xuICAgICAgICAgICAgICBhW2xlc3MrK10gPSBhW2dyZWF0XTtcbiAgICAgICAgICAgICAgYVtncmVhdC0tXSA9IGVrO1xuICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIGFba10gPSBhW2dyZWF0XTtcbiAgICAgICAgICAgICAgYVtncmVhdC0tXSA9IGVrO1xuICAgICAgICAgICAgICAvLyBOb3RlOiBpZiBncmVhdCA8IGsgdGhlbiB3ZSB3aWxsIGV4aXQgdGhlIG91dGVyIGxvb3AgYW5kIGZpeFxuICAgICAgICAgICAgICAvLyBpbnZhcmlhbnQgMiAod2hpY2ggd2UganVzdCB2aW9sYXRlZCkuXG4gICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgIH0gZWxzZSB7XG5cbiAgICAgIC8vIFdlIHBhcnRpdGlvbiB0aGUgbGlzdCBpbnRvIHRocmVlIHBhcnRzOlxuICAgICAgLy8gIDEuIDwgcGl2b3QxXG4gICAgICAvLyAgMi4gPj0gcGl2b3QxICYmIDw9IHBpdm90MlxuICAgICAgLy8gIDMuID4gcGl2b3QyXG4gICAgICAvL1xuICAgICAgLy8gRHVyaW5nIHRoZSBsb29wIHdlIGhhdmU6XG4gICAgICAvLyBbIHwgPCBwaXZvdDEgfCA+PSBwaXZvdDEgJiYgPD0gcGl2b3QyIHwgdW5wYXJ0aXRpb25lZCAgfCA+IHBpdm90MiAgfCBdXG4gICAgICAvLyAgXiAgICAgICAgICAgIF4gICAgICAgICAgICAgICAgICAgICAgICBeICAgICAgICAgICAgICBeICAgICAgICAgICAgIF5cbiAgICAgIC8vIGxlZnQgICAgICAgICBsZXNzICAgICAgICAgICAgICAgICAgICAgayAgICAgICAgICAgICAgZ3JlYXQgICAgICAgIHJpZ2h0XG4gICAgICAvL1xuICAgICAgLy8gYVtsZWZ0XSBhbmQgYVtyaWdodF0gYXJlIHVuZGVmaW5lZCBhbmQgYXJlIGZpbGxlZCBhZnRlciB0aGVcbiAgICAgIC8vIHBhcnRpdGlvbmluZy5cbiAgICAgIC8vXG4gICAgICAvLyBJbnZhcmlhbnRzOlxuICAgICAgLy8gICAxLiBmb3IgeCBpbiBdbGVmdCwgbGVzc1sgOiB4IDwgcGl2b3QxXG4gICAgICAvLyAgIDIuIGZvciB4IGluIFtsZXNzLCBrWyA6IHBpdm90MSA8PSB4ICYmIHggPD0gcGl2b3QyXG4gICAgICAvLyAgIDMuIGZvciB4IGluIF1ncmVhdCwgcmlnaHRbIDogeCA+IHBpdm90MlxuICAgICAgZm9yICh2YXIgayA9IGxlc3M7IGsgPD0gZ3JlYXQ7IGsrKykge1xuICAgICAgICB2YXIgZWsgPSBhW2tdLCB4ayA9IGYoZWspO1xuICAgICAgICBpZiAoeGsgPCBwaXZvdFZhbHVlMSkge1xuICAgICAgICAgIGlmIChrICE9PSBsZXNzKSB7XG4gICAgICAgICAgICBhW2tdID0gYVtsZXNzXTtcbiAgICAgICAgICAgIGFbbGVzc10gPSBlaztcbiAgICAgICAgICB9XG4gICAgICAgICAgKytsZXNzO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIGlmICh4ayA+IHBpdm90VmFsdWUyKSB7XG4gICAgICAgICAgICB3aGlsZSAodHJ1ZSkge1xuICAgICAgICAgICAgICB2YXIgZ3JlYXRWYWx1ZSA9IGYoYVtncmVhdF0pO1xuICAgICAgICAgICAgICBpZiAoZ3JlYXRWYWx1ZSA+IHBpdm90VmFsdWUyKSB7XG4gICAgICAgICAgICAgICAgZ3JlYXQtLTtcbiAgICAgICAgICAgICAgICBpZiAoZ3JlYXQgPCBrKSBicmVhaztcbiAgICAgICAgICAgICAgICAvLyBUaGlzIGlzIHRoZSBvbmx5IGxvY2F0aW9uIGluc2lkZSB0aGUgbG9vcCB3aGVyZSBhIG5ld1xuICAgICAgICAgICAgICAgIC8vIGl0ZXJhdGlvbiBpcyBzdGFydGVkLlxuICAgICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIC8vIGFbZ3JlYXRdIDw9IHBpdm90Mi5cbiAgICAgICAgICAgICAgICBpZiAoZ3JlYXRWYWx1ZSA8IHBpdm90VmFsdWUxKSB7XG4gICAgICAgICAgICAgICAgICAvLyBUcmlwbGUgZXhjaGFuZ2UuXG4gICAgICAgICAgICAgICAgICBhW2tdID0gYVtsZXNzXTtcbiAgICAgICAgICAgICAgICAgIGFbbGVzcysrXSA9IGFbZ3JlYXRdO1xuICAgICAgICAgICAgICAgICAgYVtncmVhdC0tXSA9IGVrO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAvLyBhW2dyZWF0XSA+PSBwaXZvdDEuXG4gICAgICAgICAgICAgICAgICBhW2tdID0gYVtncmVhdF07XG4gICAgICAgICAgICAgICAgICBhW2dyZWF0LS1dID0gZWs7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGJyZWFrO1xuIC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GUgbGlzdCBpbnRvIHRocmVlIHBhcnRzOlxuICAgICAgLy8gIDEuID09IHBpdm90MVxuICAgICAgLy8gIDIuID4gcGl2b3QxICYmIDwgcGl2b3QyXG4gICAgICAvLyAgMy4gPT0gcGl2b3QyXG4gICAgICAvL1xuICAgICAgLy8gRHVyaW5nIHRoZSBsb29wIHdlIGhhdmU6XG4gICAgICAvLyBbID09IHBpdm90MSB8ID4gcGl2b3QxICYmIDwgcGl2b3QyIHwgdW5wYXJ0aXRpb25lZCAgfCA9PSBwaXZvdDIgXVxuICAgICAgLy8gICAgICAgICAgICAgIF4gICAgICAgICAgICAgICAgICAgICAgXiAgICAgICAgICAgICAgXlxuICAgICAgLy8gICAgICAgICAgICBsZXNzICAgICAgICAgICAgICAgICAgICAgayAgICAgICAgICAgICAgZ3JlYXRcbiAgICAgIC8vXG4gICAgICAvLyBJbnZhcmlhbnRzOlxuICAgICAgLy8gICAxLiBmb3IgeCBpbiBbICosIGxlc3NbIDogeCA9PSBwaXZvdDFcbiAgICAgIC8vICAgMi4gZm9yIHggaW4gW2xlc3MsIGtbIDogcGl2b3QxIDwgeCAmJiB4IDwgcGl2b3QyXG4gICAgICAvLyAgIDMuIGZvciB4IGluIF1ncmVhdCwgKiBdIDogeCA9PSBwaXZvdDJcbiAgICAgIGZvciAodmFyIGsgPSBsZXNzOyBrIDw9IGdyZWF0OyBrKyspIHtcbiAgICAgICAgdmFyIGVrID0gYVtrXSwgeGsgPSBmKGVrKTtcbiAgICAgICAgaWYgKHhrIDw9IHBpdm90VmFsdWUxICYmIHhrID49IHBpdm90VmFsdWUxKSB7XG4gICAgICAgICAgaWYgKGsgIT09IGxlc3MpIHtcbiAgICAgICAgICAgIGFba10gPSBhW2xlc3NdO1xuICAgICAgICAgICAgYVtsZXNzXSA9IGVrO1xuICAgICAgICAgIH1cbiAgICAgICAgICBsZXNzKys7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgaWYgKHhrIDw9IHBpdm90VmFsdWUyICYmIHhrID49IHBpdm90VmFsdWUyKSB7XG4gICAgICAgICAgICB3aGlsZSAodHJ1ZSkge1xuICAgICAgICAgICAgICB2YXIgZ3JlYXRWYWx1ZSA9IGYoYVtncmVhdF0pO1xuICAgICAgICAgICAgICBpZiAoZ3JlYXRWYWx1ZSA8PSBwaXZvdFZhbHVlMiAmJiBncmVhdFZhbHVlID49IHBpdm90VmFsdWUyKSB7XG4gICAgICAgICAgICAgICAgZ3JlYXQtLTtcbiAgICAgICAgICAgICAgICBpZiAoZ3JlYXQgPCBrKSBicmVhaztcbiAgICAgICAgICAgICAgICAvLyBUaGlzIGlzIHRoZSBvbmx5IGxvY2F0aW9uIGluc2lkZSB0aGUgbG9vcCB3aGVyZSBhIG5ld1xuICAgICAgICAgICAgICAgIC8vIGl0ZXJhdGlvbiBpcyBzdGFydGVkLlxuICAgICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIC8vIGFbZ3JlYXRdIDwgcGl2b3QyLlxuICAgICAgICAgICAgICAgIGlmIChncmVhdFZhbHVlIDwgcGl2b3RWYWx1ZTEpIHtcbiAgICAgICAgICAgICAgICAgIC8vIFRyaXBsZSBleGNoYW5nZS5cbiAgICAgICAgICAgICAgICAgIGFba10gPSBhW2xlc3NdO1xuICAgICAgICAgICAgICAgICAgYVtsZXNzKytdID0gYVtncmVhdF07XG4gICAgICAgICAgICAgICAgICBhW2dyZWF0LS1dID0gZWs7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgIC8vIGFbZ3JlYXRdID09IHBpdm90MS5cbiAgICAgICAgICAgICAgICAgIGFba10gPSBhW2dyZWF0XTtcbiAgICAgICAgICAgICAgICAgIGFbZ3JlYXQtLV0gPSBlaztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAg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gICAgayA9IFtdO1xuXG4gICAgICAgIGZvciAoaSA9IDA7IGkgPCBuZXdEYXRhLmxlbmd0aDsgaSsrKSB7XG4gICAgICAgICAgZm9yKGogPSAwLCBrID0gdmFsdWUobmV3RGF0YVtpXSk7IGogPCBrLmxlbmd0aDsgaisrKSB7XG4gICAgICAgICAgICB0Kys7XG4gICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgbmV3VmFsdWVzID0gW107XG4gICAgICAgIG5ld0l0ZXJhYmxlc0luZGV4Q291bnQgPSBjcm9zc2ZpbHRlcl9yYW5nZShuZXdEYXRhLmxlbmd0aCk7XG4gICAgICAgIG5ld0l0ZXJhYmxlc0luZGV4RmlsdGVyU3RhdHVzID0gY3Jvc3NmaWx0ZXJfaW5kZXgodCwxKTtcbiAgICAgICAgaXRlcmFibGVzRW1wdHlSb3dzID0gW107XG4gICAgICAgIHZhciB1bnNvcnRlZEluZGV4ID0gY3Jvc3NmaWx0ZXJfcmFuZ2UodCk7XG5cbiAgICAgICAgZm9yIChsID0gMCwgaSA9IDA7IGkgPCBuZXdEYXRhLmxlbmd0aDsgaSsrKSB7XG4gICAgICAgICAgayA9IHZhbHVlKG5ld0RhdGFbaV0pXG4gICAgICAgICAgLy9cbiAgICAgICAgICBpZighay5sZW5ndGgpe1xuICAgICAgICAgICAgbmV3SXRlcmFibGVzSW5kZXhDb3VudFtpXSA9IDA7XG4gICAgICAgICAgICBpdGVyYWJsZXNFbXB0eVJvd3MucHVzaChpKTtcbiAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgIH1cbiAgICAgICAgICBuZXdJdGVyYWJsZXNJbmRleENvdW50W2ldID0gay5sZW5ndGhcbiAgICAgICAgICBmb3IgKGogPSAwOyBqIDwgay5sZW5ndGg7IGorKykge1xuICAgICAgICAgICAgbmV3VmFsdWVzLnB1c2goa1tqXSk7XG4gICAgICAgICAgICB1bnNvcnRlZEluZGV4W2xdID0gaTtcbiAgICAgICAgICAgIGwrKztcbi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mlsdGVySW5kZXhCb3VuZHMoYm91bmRzKSB7XG5cbiAgICAgIHZhciBsbzEgPSBib3VuZHNbMF0sXG4gICAgICAgICAgaGkxID0gYm91bmRzWzFdO1xuXG4gICAgICBpZiAocmVmaWx0ZXJGdW5jdGlvbikge1xuICAgICAgICByZWZpbHRlckZ1bmN0aW9uID0gbnVsbDtcbiAgICAgICAgZmlsdGVySW5kZXhGdW5jdGlvbihmdW5jdGlvbihkLCBpKSB7IHJldHVybiBsbzEgPD0gaSAmJiBpIDwgaGkxOyB9LCBib3VuZHNbMF0gPT09IDAgJiYgYm91bmRzWzFdID09PSBpbmRleC5sZW5ndGgpO1xuICAgICAgICBsbzAgPSBsbzE7XG4gICAgICAgIGhpMCA9IGhpMTtcbiAgICAgICAgcmV0dXJuIGRpbWVuc2lvbjtcbiAgICAgIH1cblxuICAgICAgdmFyIGksXG4gICAgICAgICAgaixcbiAgICAgICAgICBrLFxuICAgICAgICAgIGFkZGVkID0gW10sXG4gICAgICAgICAgcmVtb3ZlZCA9IFtdLFxuICAgICAgICAgIHZhbHVlSW5kZXhBZGRlZCA9IFtdLFxuICAgICAgICAgIHZhbHVlSW5kZXhSZW1vdmVkID0gW107XG5cblxuICAgICAgLy8gRmFzdCBpbmNyZW1lbnRhbCB1cGRhdGUgYmFzZWQgb24gcHJldmlvdXMgbG8gaW5kZXguXG4gICAgICBpZiAobG8xIDwgbG8wKSB7XG4gICAgICAgIGZvciAoaSA9IGxvMSwgaiA9IE1hdGgubWluKGxvMCwgaGkxKTsgaSA8IGo7ICsraSkge1xuICAgICAgICAgIGFkZGVkLnB1c2goaW5kZXhbaV0pO1xuICAgICAgICAgIHZhbHVlSW5kZXhBZGRlZC5wdXNoKGkpO1xuICAgICAgICB9XG4gICAgICB9IGVsc2UgaWYgKGxvMSA+IGxvMCkge1xuICAgICAgICBmb3IgKGkgPSBsbzAsIGogPSBNYXRoLm1pbihsbzEsIGhpMCk7IGkgPCBqOyArK2kpIHtcbiAgICAgICAgIC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JlZmlsdGVyRnVuY3Rpb24gPSBmLCBmYWxzZSk7XG5cbiAgICAgIGxvMCA9IDA7XG4gICAgICBoaTAgPSBuO1xuXG4gICAgICByZXR1cm4gZGltZW5zaW9uO1xuICAgIH1cblxuICAgIGZ1bmN0aW9uIGZpbHRlckluZGV4RnVuY3Rpb24oZiwgZmlsdGVyQWxsKSB7XG4gICAgICB2YXIgaSxcbiAgICAgICAgICBrLFxuICAgICAgICAgIHgsXG4gICAgICAgICAgYWRkZWQgPSBbXSxcbiAgICAgICAgICByZW1vdmVkID0gW10sXG4gICAgICAgICAgdmFsdWVJbmRleEFkZGVkID0gW10sXG4gICAgICAgICAgdmFsdWVJbmRleFJlbW92ZWQgPSBbXSxcbiAgICAgICAgICBpbmRleExlbmd0aCA9IGluZGV4Lmxlbmd0aDtcblxuICAgICAgaWYoIWl0ZXJhYmxlKSB7XG4gICAgICAgIGZvciAoaSA9IDA7IGkgPCBpbmRleExlbmd0aDsgKytpKSB7XG4gICAgICAgICAgaWYgKCEoZmlsdGVyc1tvZmZzZXRdW2sgPSBpbmRleFtpXV0gJiBvbmUpIF4gISEoeCA9IGYodmFsdWVzW2ldLCBpKSkpIHtcbiAgICAgICAgICAgIGlmICh4KSBhZGRlZC5wdXNoKGspO1xuICAgICAgICAgICAgZWxzZSByZW1vdmVkLnB1c2goayk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG5cbiAgICAgIGlmKGl0ZXJhYmxlKSB7XG4gICAgICAgIGZvcihpPTA7IGkgPCBpbmRleExlbmd0aDsgKytpKSB7XG4gICAgICAgICAgaWYoZih2YWx1ZXNbaV0sIGkpKSB7XG4gICAgICAgICAgICBhZGRlZC5wdXNoKGluZGV4W2ldKTtcbiAgICAgICAgICAgIHZhbHVlSW5kZXhBZGRlZC5wdXNoKGkpO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZW1vdmVkLnB1c2goaW5kZXhbaV0pO1xuICAgICAgICAgICAgdmFsd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AgICBmdW5jdGlvbiB0b3Aoaykge1xuICAgICAgdmFyIGFycmF5ID0gW10sXG4gICAgICAgICAgaSA9IGhpMCxcbiAgICAgICAgICBqO1xuXG4gICAgICB3aGlsZSAoLS1pID49IGxvMCAmJiBrID4gMCkge1xuICAgICAgICBpZiAoZmlsdGVycy56ZXJvKGogPSBpbmRleFtpXSkpIHtcbiAgICAgICAgICBhcnJheS5wdXNoKGRhdGFbal0pO1xuICAgICAgICAgIC0taztcbiAgICAgICAgfVxuICAgICAgfVxuXG4gICAgICBpZihpdGVyYWJsZSl7XG4gICAgICAgIGZvcihpID0gMDsgaSA8IGl0ZXJhYmxlc0VtcHR5Um93cy5sZW5ndGggJiYgayA+IDA7IGkrKykge1xuICAgICAgICAgIC8vIEFkZCBlbXB0eSByb3dzIGF0IHRoZSBlbmRcbiAgICAgICAgICBpZihmaWx0ZXJzLnplcm8oaiA9IGl0ZXJhYmxlc0VtcHR5Um93c1tpXSkpIHtcbiAgICAgICAgICAgIGFycmF5LnB1c2goZGF0YVtqXSk7XG4gICAgICAgICAgICAtLWs7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG5cbiAgICAgIHJldHVybiBhcnJheTtcbiAgICB9XG5cbiAgICAvLyBSZXR1cm5zIHRoZSBib3R0b20gSyBzZWxlY3RlZCByZWNvcmRzIGJhc2VkIG9uIHRoaXMgZGltZW5zaW9uJ3Mgb3JkZXIuXG4gICAgLy8gTm90ZTogb2JzZXJ2ZXMgdGhpcyBkaW1lbnNpb24ncyBmaWx0ZXIsIHVubGlrZSBncm91cCBhbmQgZ3JvdXBBbGwuXG4gICAgZnVuY3Rpb24gYm90dG9tKGspIHtcbiAgICAgIHZhciBhcnJheSA9IFtdLFxuICAgICAgICAgIGksXG4gICAgICAgICAgajtcblxuICAgICAgaWYoaXRlcmFibGUpIHtcbiAgICAgICAgLy8gQWRkIGVtcHR5IHJvd3MgYXQgdGhlIHRvcFxuICAgICAgICBmb3IoaSA9IDA7IGkgP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2VJbml0aWFsLFxuICAgICAgICAgICAgazAgPSBrLCAvLyBvbGQgY2FyZGluYWxpdHlcbiAgICAgICAgICAgIGkwID0gMCwgLy8gaW5kZXggb2Ygb2xkIGdyb3VwXG4gICAgICAgICAgICBpMSA9IDAsIC8vIGluZGV4IG9mIG5ldyByZWNvcmRcbiAgICAgICAgICAgIGosIC8vIG9iamVjdCBpZFxuICAgICAgICAgICAgZzAsIC8vIG9sZCBncm91cFxuICAgICAgICAgICAgeDAsIC8vIG9sZCBrZXlcbiAgICAgICAgICAgIHgxLCAvLyBuZXcga2V5XG4gICAgICAgICAgICBnLCAvLyBncm91cCB0byBhZGRcbiAgICAgICAgICAgIHg7IC8vIGtleSBvZiBncm91cCB0byBhZGRcblxuICAgICAgICAvLyBJZiBhIHJlc2V0IGlzIG5lZWRlZCwgd2UgZG9uJ3QgbmVlZCB0byB1cGRhdGUgdGhlIHJlZHVjZSB2YWx1ZXMuXG4gICAgICAgIGlmIChyZXNldE5lZWRlZCkgYWRkID0gaW5pdGlhbCA9IGNyb3NzZmlsdGVyX251bGw7XG4gICAgICAgIGlmIChyZXNldE5lZWRlZCkgcmVtb3ZlID0gaW5pdGlhbCA9IGNyb3NzZmlsdGVyX251bGw7XG5cbiAgICAgICAgLy8gUmVzZXQgdGhlIG5ldyBncm91cHMgKGsgaXMgYSBsb3dlciBib3VuZCkuXG4gICAgICAgIC8vIEFsc28sIG1ha2Ugc3VyZSB0aGF0IGdyb3VwSW5kZXggZXhpc3RzIGFuZCBpcyBsb25nIGVub3VnaC5cbiAgICAgICAgZ3JvdXBzID0gbmV3IEFycmF5KGspLCBrID0gMDtcbiAgICAgICAgaWYoaXRlcmFibGUpe1xuICAgICAgICAgIGdyb3VwSW5kZXggPSBrMCA+IDEgPyBncm91cEluZGV4IDogW107XG4gICAgICAgIH1cbiAgICAgICAgZWxzZXtcbiAgICAgICAgICBncm91cEluZGV4ID0gazAgPiAxID8gY3Jvc3NmaWx0ZXJfYXJyYXlMZW5ndG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BrID0gMDtcbiAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwgb2xkSzsgKytpKSB7XG4gICAgICAgICAgICBpZiAoc2Vlbkdyb3Vwc1tpXSkge1xuICAgICAgICAgICAgICBzZWVuR3JvdXBzW2ldID0gaysrO1xuICAgICAgICAgICAgICBncm91cHMucHVzaChvbGRHcm91cHNbaV0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cblxuICAgICAgICAgIGlmIChrID4gMSkge1xuICAgICAgICAgICAgLy8gUmVpbmRleCB0aGUgZ3JvdXAgaW5kZXggdXNpbmcgc2Vlbkdyb3VwcyB0byBmaW5kIHRoZSBuZXcgaW5kZXguXG4gICAgICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IGo7ICsraSkgZ3JvdXBJbmRleFtpXSA9IHNlZW5Hcm91cHNbZ3JvdXBJbmRleFtpXV07XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGdyb3VwSW5kZXggPSBudWxsO1xuICAgICAgICAgIH1cbiAgICAgICAgICBmaWx0ZXJMaXN0ZW5lcnNbZmlsdGVyTGlzdGVuZXJzLmluZGV4T2YodXBkYXRlKV0gPSBrID4gMVxuICAgICAgICAgICAgICA/IChyZXNldCA9IHJlc2V0TWFueSwgdXBkYXRlID0gdXBkYXRlTWFueSlcbiAgICAgICAgICAgICAgOiBrID09PSAxID8gKHJlc2V0ID0gcmVzZXRPbmUsIHVwZGF0ZSA9IHVwZGF0ZU9uZSlcbiAgICAgICAgICAgICAgOiByZXNldCA9IHVwZGF0ZSA9IGNyb3NzZmlsdGVyX251bGw7XG4gICAgICAgIH0gZWxzZSBpZiAoayA9PT0gMSkge1xuICAgICAgICAgIGlmIChncm91cEFsbCkgcmV0dXJuO1xuICAgICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgbjsgKytpKSBpZiAoIWZpbHRlcnMuemVybyhpKSkgcmV0dXJuO1xuICAgICAgICAgIGdyb3VwcyA9IFtdLCBrID0gMDtcbi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sgaisrKSB7XG4gICAgICAgICAgICAgICAgZyA9IGdyb3Vwc1tncm91cEluZGV4W2tdW2pdXTtcbiAgICAgICAgICAgICAgICBnLnZhbHVlID0gcmVkdWNlQWRkKGcudmFsdWUsIGRhdGFba10sIGZhbHNlLCBqKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cblxuICAgICAgICAgIC8vIFJlbW92ZSB0aGUgcmVtb3ZlZCB2YWx1ZXMuXG4gICAgICAgICAgZm9yIChpID0gMCwgbiA9IHJlbW92ZWQubGVuZ3RoOyBpIDwgbjsgKytpKSB7XG4gICAgICAgICAgICBpZiAoZmlsdGVycy5vbmx5RXhjZXB0KGsgPSByZW1vdmVkW2ldLCBvZmZzZXQsIHplcm8sIGZpbHRlck9mZnNldCwgZmlsdGVyT25lKSkge1xuICAgICAgICAgICAgICBmb3IgKGogPSAwOyBqIDwgZ3JvdXBJbmRleFtrXS5sZW5ndGg7IGorKykge1xuICAgICAgICAgICAgICAgIGcgPSBncm91cHNbZ3JvdXBJbmRleFtrXVtqXV07XG4gICAgICAgICAgICAgICAgZy52YWx1ZSA9IHJlZHVjZVJlbW92ZShnLnZhbHVlLCBkYXRhW2tdLCBub3RGaWx0ZXIsIGopO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfVxuXG4gICAgICAgIC8vIEFkZCB0aGUgYWRkZWQgdmFsdWVzLlxuICAgICAgICBmb3IgKGkgPSAwLCBuID0gYWRkZWQubGVuZ3RoOyBpIDwgbjsgKytpKSB7XG4gICAgICAgICAgaWYgKGZpbHRlcnMuemVyb0V4Y2VwdChrID0gYWRkZWRbaV0sIG9mZnNldCwgemVybykpIHtcbiAgICAgICAgICAgIGcgPSBncm91cHNbZ3JvdXBJbmRleFtrXV07XG4gICAgICAgICAgICBnLnZhbHVlID0gcmVkdWNlQWRkKGcudmFsdWUsIGRhdGFba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gICBoZWFkLnRhc2sgPSB2b2lkIDA7XG4gICAgICAgICAgICBkb21haW4gPSBoZWFkLmRvbWFpbjtcblxuICAgICAgICAgICAgaWYgKGRvbWFpbikge1xuICAgICAgICAgICAgICAgIGhlYWQuZG9tYWluID0gdm9pZCAwO1xuICAgICAgICAgICAgICAgIGRvbWFpbi5lbnRlcigpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcnVuU2luZ2xlKHRhc2ssIGRvbWFpbik7XG5cbiAgICAgICAgfVxuICAgICAgICB3aGlsZSAobGF0ZXJRdWV1ZS5sZW5ndGgpIHtcbiAgICAgICAgICAgIHRhc2sgPSBsYXRlclF1ZXVlLnBvcCgpO1xuICAgICAgICAgICAgcnVuU2luZ2xlKHRhc2spO1xuICAgICAgICB9XG4gICAgICAgIGZsdXNoaW5nID0gZmFsc2U7XG4gICAgfVxuICAgIC8vIHJ1bnMgYSBzaW5nbGUgZnVuY3Rpb24gaW4gdGhlIGFzeW5jIHF1ZXVlXG4gICAgZnVuY3Rpb24gcnVuU2luZ2xlKHRhc2ssIGRvbWFpbikge1xuICAgICAgICB0cnkge1xuICAgICAgICAgICAgdGFzaygpO1xuXG4gICAgICAgIH0gY2F0Y2ggKGUpIHtcbiAgICAgICAgICAgIGlmIChpc05vZGVKUykge1xuICAgICAgICAgICAgICAgIC8vIEluIG5vZGUsIHVuY2F1Z2h0IGV4Y2VwdGlvbnMgYXJlIGNvbnNpZGVyZWQgZmF0YWwgZXJyb3JzLlxuICAgICAgICAgICAgICAgIC8vIFJlLXRocm93IHRoZW0gc3luY2hyb25vdXNseSB0byBpbnRlcnJ1cHQgZmx1c2hpbmchXG5cbiAgICAgICAgICAgICAgICAvLyBFbnN1cmUgY29udGludWF0aW9uIGlmIHRoZSB1bmNhdWdodCBleGNlcHRpb24gaXMgc3VwcHJlc3NlZFxuICAgICAgICAgICAgICAgIC8vIGxpc3RlbmluZyBcInVuY2F1Z2h0RXhjZXB0aW9uXCIgZXZlbnRzIChhcyBkb21haW5zIGRvZXMpLlxuICAgICAgICAgICAgICAgIC8vIENvbnRpbnVlIGluIG5leHQgZXZlbnQgdG8gYXZvaWQgdGljayByZWN1cnNpb24uXG4gICAgICAgICAgICAgICAgaWYgKGRvbWFpbikge1xuICAgICAgICAgICAgICAgICAgICBkb21haW4uZXhpdCgpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBzZXRUaW1lb3V0KGZsdXNoLCAwKTtcbiAgICAgICAgICAgICAgICBpZiAoZG9tYWluKSB7XG4gICAgICAgICAgICAgICAgICAgIGRvbWFpbi5lbnRlcigpO1xuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIHRocm93IGU7XG5cbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgLy8gSW4gYnJvd3NlcnMsIHVuY2F1Z2h0IGV4Y2VwdGlvbnMgYXJlIG5vdCBmYXRhbC5cbiAgICAgICAgICAgICAgICAvLyBSZS10aHJvdyB0aGVtIGFzeW5jaHJvbm91c2x5IHRvIGF2b2lkIHNsb3ctZG93bnMuXG4gICAgICAgICAgICAgICAgc2V0VGltZW91dChmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgICAgIHRocm93IGU7XG4gICAgICAgICAgICAgICAgfSwgMCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBpZiAoZG9tYWluKSB7XG4gICAgICAgICAgICBkb21haW4uZXhpdCgpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgbmV4dFRpY2sgPSBmdW5jdGlvbiAodGFzaykge1xuICAgICAgICB0YWlsID0gdGFpbC5uZXh0ID0ge1xuICAgICAgICAgICAgdGFzazogdGFzayxcbiAgICAgICAgICAgIGRvbWFpbjogaXNOb2RlSlMgJiYgcHJvY2Vzcy5kb21haW4sXG4gICAgICAgICAgICBuZXh0OiBudWxsXG4gICAgICAgIH07XG5cbiAgICAgICAgaWYgKCFmbHVzaGluZykge1xuICA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ICAgICAgICAgICB9XG4gICAgICAgICAgICB9IHdoaWxlICgxKTtcbiAgICAgICAgfVxuICAgICAgICAvLyByZWR1Y2VcbiAgICAgICAgZm9yICg7IGluZGV4IDwgbGVuZ3RoOyBpbmRleCsrKSB7XG4gICAgICAgICAgICAvLyBhY2NvdW50IGZvciB0aGUgcG9zc2liaWxpdHkgdGhhdCB0aGUgYXJyYXkgaXMgc3BhcnNlXG4gICAgICAgICAgICBpZiAoaW5kZXggaW4gdGhpcykge1xuICAgICAgICAgICAgICAgIGJhc2lzID0gY2FsbGJhY2soYmFzaXMsIHRoaXNbaW5kZXhdLCBpbmRleCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIGJhc2lzO1xuICAgIH1cbik7XG5cbnZhciBhcnJheV9pbmRleE9mID0gdW5jdXJyeVRoaXMoXG4gICAgQXJyYXkucHJvdG90eXBlLmluZGV4T2YgfHwgZnVuY3Rpb24gKHZhbHVlKSB7XG4gICAgICAgIC8vIG5vdCBhIHZlcnkgZ29vZCBzaGltLCBidXQgZ29vZCBlbm91Z2ggZm9yIG91ciBvbmUgdXNlIG9mIGl0XG4gICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgdGhpcy5sZW5ndGg7IGkrKykge1xuICAgICAgICAgICAgaWYgKHRoaXNbaV0gPT09IHZhbHVlKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIC0xO1xuICAgIH1cbik7XG5cbnZhciBhcnJheV9tYXAgPSB1bmN1cnJ5VGhpcyhcbiAgICBBcnJheS5wcm90b3R5cGUubWFwIHx8IGZ1bmN0aW9uIChjYWxsYmFjaywgdGhpc3ApIHtcbiAgICAgICAgdmFyIHNlbGYgPSB0aGlzO1xuICAgICAgICB2YXIgY29sbGVjdCA9IFtdO1xuICAgICAgICBhcnJheV9yZWR1Y2Uoc2VsZiwgZnVuY3Rpb24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TtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIFEubmV4dFRpY2soZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgIHJlc29sdmVkUHJvbWlzZS5wcm9taXNlRGlzcGF0Y2guYXBwbHkocmVzb2x2ZWRQcm9taXNlLCBhcmdzKTtcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgfTtcblxuICAgIC8vIFhYWCBkZXByZWNhdGVkXG4gICAgcHJvbWlzZS52YWx1ZU9mID0gZnVuY3Rpb24gKCkge1xuICAgICAgICBpZiAobWVzc2FnZXMpIHtcbiAgICAgICAgICAgIHJldHVybiBwcm9taXNlO1xuICAgICAgICB9XG4gICAgICAgIHZhciBuZWFyZXJWYWx1ZSA9IG5lYXJlcihyZXNvbHZlZFByb21pc2UpO1xuICAgICAgICBpZiAoaXNQcm9taXNlKG5lYXJlclZhbHVlKSkge1xuICAgICAgICAgICAgcmVzb2x2ZWRQcm9taXNlID0gbmVhcmVyVmFsdWU7IC8vIHNob3J0ZW4gY2hhaW5cbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gbmVhcmVyVmFsdWU7XG4gICAgfTtcblxuICAgIHByb21pc2UuaW5zcGVjdCA9IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgaWYgKCFyZXNvbHZlZFByb21pc2UpIHtcbiAgICAgICAgICAgIHJldHVybiB7IHN0YXRlOiBcInBlbmRpbmdcIiB9O1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiByZXNvbHZlZFByb21pc2UuaW5zcGVjdCgpO1xuICAgIH07XG5cbiAgICBpZiAoUS5sb25nU3RhY2tTdXBwb3J0ICYmIGhhc1N0YWNrcykge1xuICAgICAgICB0cnkge1xuICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCk7XG4gICAgICAgIH0gY2F0Y2ggKGUpIHtcbiAgICAgICAgICAgIC8vIE5PVEU6IGRvbid0IHRyeSB0byB1c2UgYEVycm9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IChvcCkge1xuICAgICAgICAgICAgcmV0dXJuIHJlamVjdChuZXcgRXJyb3IoXG4gICAgICAgICAgICAgICAgXCJQcm9taXNlIGRvZXMgbm90IHN1cHBvcnQgb3BlcmF0aW9uOiBcIiArIG9wXG4gICAgICAgICAgICApKTtcbiAgICAgICAgfTtcbiAgICB9XG4gICAgaWYgKGluc3BlY3QgPT09IHZvaWQgMCkge1xuICAgICAgICBpbnNwZWN0ID0gZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgcmV0dXJuIHtzdGF0ZTogXCJ1bmtub3duXCJ9O1xuICAgICAgICB9O1xuICAgIH1cblxuICAgIHZhciBwcm9taXNlID0gb2JqZWN0X2NyZWF0ZShQcm9taXNlLnByb3RvdHlwZSk7XG5cbiAgICBwcm9taXNlLnByb21pc2VEaXNwYXRjaCA9IGZ1bmN0aW9uIChyZXNvbHZlLCBvcCwgYXJncykge1xuICAgICAgICB2YXIgcmVzdWx0O1xuICAgICAgICB0cnkge1xuICAgICAgICAgICAgaWYgKGRlc2NyaXB0b3Jbb3BdKSB7XG4gICAgICAgICAgICAgICAgcmVzdWx0ID0gZGVzY3JpcHRvcltvcF0uYXBwbHkocHJvbWlzZSwgYXJncyk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHJlc3VsdCA9IGZhbGxiYWNrLmNhbGwocHJvbWlzZSwgb3AsIGFyZ3MpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcbiAgICAgICAgICAgIHJlc3VsdCA9IHJlamVjdChleGNlcHRpb24pO1xuICAgICAgICB9XG4gICAgICAgIGlmIChyZXNvbHZlKSB7XG4gICAgICAgICAgICByZXNvbHZlKHJlc3VsdCk7XG4gICAgICAgIH1cbiAgICB9O1xuXG4gICAgcHJvbWlzZS5pbnNwZWN0ID0gaW5zcGVjdDtcblxuICAgIC8vIFhYWCBkZXByZWNhdGVkIGB2YWx1ZU9mYCBhbmQgYGV4Y2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ICAgICAgIH1cbiAgICAgICAgICAgIGRvbmUgPSB0cnVlO1xuXG4gICAgICAgICAgICBkZWZlcnJlZC5yZXNvbHZlKF9mdWxmaWxsZWQodmFsdWUpKTtcbiAgICAgICAgfSwgXCJ3aGVuXCIsIFtmdW5jdGlvbiAoZXhjZXB0aW9uKSB7XG4gICAgICAgICAgICBpZiAoZG9uZSkge1xuICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGRvbmUgPSB0cnVlO1xuXG4gICAgICAgICAgICBkZWZlcnJlZC5yZXNvbHZlKF9yZWplY3RlZChleGNlcHRpb24pKTtcbiAgICAgICAgfV0pO1xuICAgIH0pO1xuXG4gICAgLy8gUHJvZ3Jlc3MgcHJvcGFnYXRvciBuZWVkIHRvIGJlIGF0dGFjaGVkIGluIHRoZSBjdXJyZW50IHRpY2suXG4gICAgc2VsZi5wcm9taXNlRGlzcGF0Y2godm9pZCAwLCBcIndoZW5cIiwgW3ZvaWQgMCwgZnVuY3Rpb24gKHZhbHVlKSB7XG4gICAgICAgIHZhciBuZXdWYWx1ZTtcbiAgICAgICAgdmFyIHRocmV3ID0gZmFsc2U7XG4gICAgICAgIHRyeSB7XG4gICAgICAgICAgICBuZXdWYWx1ZSA9IF9wcm9ncmVzc2VkKHZhbHVlKTtcbiAgICAgICAgfSBjYXRjaCAoZSkge1xuICAgICAgICAgICAgdGhyZXcgPSB0cnVlO1xuICAgICAgICAgICAgaWYgKFEub25lcnJvcikge1xuICAgICAgICAgICAgICAgIFEub25lcnJvcihlKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhyb3cgZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIGlmICghdGhyZXcpIHtcbiAgICAgICAgICAgIGRlZmVycmVkLm5vdGlmeShuZXdWYWx1ZSk7XG4gICAgICAgIH1cbiAgICB9XSk7XG5cbiAgICByZXR1cm4gZGVmZXJyZ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IHtcbiAgICAgICAgICAgIHJldHVybiB2YWx1ZVtuYW1lXTtcbiAgICAgICAgfSxcbiAgICAgICAgXCJzZXRcIjogZnVuY3Rpb24gKG5hbWUsIHJocykge1xuICAgICAgICAgICAgdmFsdWVbbmFtZV0gPSByaHM7XG4gICAgICAgIH0sXG4gICAgICAgIFwiZGVsZXRlXCI6IGZ1bmN0aW9uIChuYW1lKSB7XG4gICAgICAgICAgICBkZWxldGUgdmFsdWVbbmFtZV07XG4gICAgICAgIH0sXG4gICAgICAgIFwicG9zdFwiOiBmdW5jdGlvbiAobmFtZSwgYXJncykge1xuICAgICAgICAgICAgLy8gTWFyayBNaWxsZXIgcHJvcG9zZXMgdGhhdCBwb3N0IHdpdGggbm8gbmFtZSBzaG91bGQgYXBwbHkgYVxuICAgICAgICAgICAgLy8gcHJvbWlzZWQgZnVuY3Rpb24uXG4gICAgICAgICAgICBpZiAobmFtZSA9PT0gbnVsbCB8fCBuYW1lID09PSB2b2lkIDApIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gdmFsdWUuYXBwbHkodm9pZCAwLCBhcmdzKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIHZhbHVlW25hbWVdLmFwcGx5KHZhbHVlLCBhcmdzKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSxcbiAgICAgICAgXCJhcHBseVwiOiBmdW5jdGlvbiAodGhpc3AsIGFyZ3MpIHtcbiAgICAgICAgICAgIHJldHVybiB2YWx1ZS5hcHBseSh0aGlzcCwgYXJncyk7XG4gICAgICAgIH0sXG4gICAgICAgIFwia2V5c1wiOiBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICByZXR1cm4gb2JqZWN0X2tleXModmFsdWUpO1xuICAgICAgICB9XG4gICAgfSwgdm9pZCAwLCBmdW5jdGlvbiBpbnNwZWN0KCkge1xuICAgICAgICByZXR1cm4geyBzdGF0ZTogXCJmdWxmaWxsZWRcIiwgdmFsdWU6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AgICAgICBpZiAocmVzdWx0LmRvbmUpIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIFEocmVzdWx0LnZhbHVlKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gd2hlbihyZXN1bHQudmFsdWUsIGNhbGxiYWNrLCBlcnJiYWNrKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIC8vIFNwaWRlck1vbmtleSBHZW5lcmF0b3JzXG4gICAgICAgICAgICAgICAgLy8gRklYTUU6IFJlbW92ZSB0aGlzIGNhc2Ugd2hlbiBTTSBkb2VzIEVTNiBnZW5lcmF0b3JzLlxuICAgICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IGdlbmVyYXRvclt2ZXJiXShhcmcpO1xuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGV4Y2VwdGlvbikge1xuICAgICAgICAgICAgICAgICAgICBpZiAoaXNTdG9wSXRlcmF0aW9uKGV4Y2VwdGlvbikpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBRKGV4Y2VwdGlvbi52YWx1ZSk7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gcmVqZWN0KGV4Y2VwdGlvbik7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgcmV0dXJuIHdoZW4ocmVzdWx0LCBjYWxsYmFjaywgZXJyYmFjayk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgdmFyIGdlbmVyYXRvciA9IG1ha2VHZW5lcmF0b3IuYXBwbHkodGhpcywgYXJndW1lbnRzKTtcbiAgICAgICAgdmFyIGNhbGxiYWNrID0gY29udGludWVyLmJpbmQoY29udGludWVyLCBcIm5leHRcI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HZhbHVlcyAob3JcbiAqIHByb21pc2VzIGZvciB2YWx1ZXMpXG4gKiBAcmV0dXJucyBhIHByb21pc2UgZm9yIGFuIGFycmF5IG9mIHRoZSBjb3JyZXNwb25kaW5nIHZhbHVlc1xuICovXG4vLyBCeSBNYXJrIE1pbGxlclxuLy8gaHR0cDovL3dpa2kuZWNtYXNjcmlwdC5vcmcvZG9rdS5waHA/aWQ9c3RyYXdtYW46Y29uY3VycmVuY3kmcmV2PTEzMDg3NzY1MjEjYWxsZnVsZmlsbGVkXG5RLmFsbCA9IGFsbDtcbmZ1bmN0aW9uIGFsbChwcm9taXNlcykge1xuICAgIHJldHVybiB3aGVuKHByb21pc2VzLCBmdW5jdGlvbiAocHJvbWlzZXMpIHtcbiAgICAgICAgdmFyIHBlbmRpbmdDb3VudCA9IDA7XG4gICAgICAgIHZhciBkZWZlcnJlZCA9IGRlZmVyKCk7XG4gICAgICAgIGFycmF5X3JlZHVjZShwcm9taXNlcywgZnVuY3Rpb24gKHVuZGVmaW5lZCwgcHJvbWlzZSwgaW5kZXgpIHtcbiAgICAgICAgICAgIHZhciBzbmFwc2hvdDtcbiAgICAgICAgICAgIGlmIChcbiAgICAgICAgICAgICAgICBpc1Byb21pc2UocHJvbWlzZSkgJiZcbiAgICAgICAgICAgICAgICAoc25hcHNob3QgPSBwcm9taXNlLmluc3BlY3QoKSkuc3RhdGUgPT09IFwiZnVsZmlsbGVkXCJcbiAgICAgICAgICAgICkge1xuICAgICAgICAgICAgICAgIHByb21pc2VzW2luZGV4XSA9IHNuYXBzaG90LnZhbHVlO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICArK3BlbmRpbmdDb3VudDtcbiAgICAgICAgICAgICAgICB3aGVuKFxuICAgICAgICAgICAgICAgICAgICBwcm9taXNlLFxuICAgICAgICAgICAgICAgICAgICBmdW5jdGlvbiAodmFsdWUpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHByb21pc2VzW2luZGV4XSA9IHZhbHVlO1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKC0tcGVuZGluZ0NvdW50ID09PSAwKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgZGVmZXJyZWQucmVzb2x2ZShwcm9taXNlcyk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgIGRlZmVycmVkLnJlamVjdCxcbiAgICAgICAgICAgICAgICAgICAgZnVuY3Rpb24gKHByb2dyZXNzKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBkZWZlcnJlZC5ub3RpZnkoeyBpbmRleDogaW5kZXgsIHZhbHVlOiBwcm9ncmVzcyB9KTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0sIHZvaWQgMCk7XG4gICAgICAgIGlmIChwZW5kaW5nQ291bnQgPT09IDApIHtcbiAgICAgICAgICAgIGRlZmVycmVkLnJlc29sdmUocHJvbWlzZXMpO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBkZWZlcnJlZC5wcm9taXNlO1xuICAgIH0pO1xufVxuXG5Qcm9taXNlLnByb3RvdHlwZS5hbGwgPSBmdW5jdGlvbiAoKSB7XG4gICAgcmV0dXJuIGFsbCh0aGlzKTtcbn07XG5cbi8qKlxuICogUmV0dXJucyB0aGUgZmlyc3QgcmVzb2x2ZWQgcHJvbWlzZSBvZiBhbiBhcnJheS4gUHJpb3IgcmVqZWN0ZWQgcHJvbWlzZXMgYXJlXG4gKiBpZ25vcmVkLiAgUmVqZWN0cyBvbmx5IGlmIGFsbCBwcm9taXNlcyBhcmUgcmVqZWN0ZWQuXG4gKiBAcGFyYW0ge0FycmF5Kn0gYW4gYXJyYXkgY29udGFpbmluZyB2YWx1ZXMgb3IgcHJvbWlzZXMgZm9yIHZhbHVlc1xuICogQHJldHVybnMgYSBwcm9taXNlIGZ1bGZpbGxl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RhY2tUcmFjZUxvbmcoZXJyb3IsIHByb21pc2UpO1xuICAgICAgICAgICAgaWYgKFEub25lcnJvcikge1xuICAgICAgICAgICAgICAgIFEub25lcnJvcihlcnJvcik7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRocm93IGVycm9yO1xuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICB9O1xuXG4gICAgLy8gQXZvaWQgdW5uZWNlc3NhcnkgYG5leHRUaWNrYGluZyB2aWEgYW4gdW5uZWNlc3NhcnkgYHdoZW5gLlxuICAgIHZhciBwcm9taXNlID0gZnVsZmlsbGVkIHx8IHJlamVjdGVkIHx8IHByb2dyZXNzID9cbiAgICAgICAgdGhpcy50aGVuKGZ1bGZpbGxlZCwgcmVqZWN0ZWQsIHByb2dyZXNzKSA6XG4gICAgICAgIHRoaXM7XG5cbiAgICBpZiAodHlwZW9mIHByb2Nlc3MgPT09IFwib2JqZWN0XCIgJiYgcHJvY2VzcyAmJiBwcm9jZXNzLmRvbWFpbikge1xuICAgICAgICBvblVuaGFuZGxlZEVycm9yID0gcHJvY2Vzcy5kb21haW4uYmluZChvblVuaGFuZGxlZEVycm9yKTtcbiAgICB9XG5cbiAgICBwcm9taXNlLnRoZW4odm9pZCAwLCBvblVuaGFuZGxlZEVycm9yKTtcbn07XG5cbi8qKlxuICogQ2F1c2VzIGEgcHJvbWlzZSB0byBiZSByZWplY3RlZCBpZiBpdCBkb2VzIG5vdCBnZXQgZnVsZmlsbGVkIGJlZm9yZVxuICogc29tZSBtaWxsaXNlY29uZHMgdGltZSBvdXQuXG4gKiBAcGFyYW0ge0FueSp9IHByb21pc2VcbiAqIEBwYXJhbSB7TnVtYmVyfSBtaWxsaXNlY29uZHMgdGltZW91dFxuICogQHBhcmFtIHtBbnkqfSBjdXN0b20gZXJyb3IgbWVzc2FnZSBvciBFcnJvciBvYmplY3QgKG9wdGlvbmFsKVxuICogQHJldHVybnMgYSBwcm9taXNlIGZvciB0aG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cGl2b3RWYWx1ZTEpIHtcbiAgICAgICAgICAgICAgZ3JlYXQtLTtcbiAgICAgICAgICAgICAgLy8gVGhpcyBpcyB0aGUgb25seSBsb2NhdGlvbiBpbiB0aGUgd2hpbGUtbG9vcCB3aGVyZSBhIG5ld1xuICAgICAgICAgICAgICAvLyBpdGVyYXRpb24gaXMgc3RhcnRlZC5cbiAgICAgICAgICAgICAgY29udGludWU7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKGdyZWF0VmFsdWUgPCBwaXZvdFZhbHVlMSkge1xuICAgICAgICAgICAgICAvLyBUcmlwbGUgZXhjaGFuZ2UuXG4gICAgICAgICAgICAgIGFba10gPSBhW2xlc3NdO1xuICAgICAgICAgICAgICBhW2xlc3MrK10gPSBhW2dyZWF0XTtcbiAgICAgICAgICAgICAgYVtncmVhdC0tXSA9IGVrO1xuICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIGFba10gPSBhW2dyZWF0XTtcbiAgICAgICAgICAgICAgYVtncmVhdC0tXSA9IGVrO1xuICAgICAgICAgICAgICAvLyBOb3RlOiBpZiBncmVhdCA8IGsgdGhlbiB3ZSB3aWxsIGV4aXQgdGhlIG91dGVyIGxvb3AgYW5kIGZpeFxuICAgICAgICAgICAgICAvLyBpbnZhcmlhbnQgMiAod2hpY2ggd2UganVzdCB2aW9sYXRlZCkuXG4gICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgIH0gZWxzZSB7XG5cbiAgICAgIC8vIFdlIHBhcnRpdGlvbiB0aGUgbGlzdCBpbnRvIHRocmVlIHBhcnRzOlxuICAgICAgLy8gIDEuIDwgcGl2b3QxXG4gICAgICAvLyAgMi4gPj0gcGl2b3QxICYmIDw9IHBpdm90MlxuICAgICAgLy8gIDMuID4gcGl2b3QyXG4gICAgICAvL1xuICAgICAgLy8gRHVyaW5nIHRoZSBsb29wIHdlIGhhdmU6XG4gICAgICAvLyBbIHwgPCBwaXZvdDEgfCA+PSBwaXZvdDEgJiYgPD0gcGl2b3QyIHwgdW5wYXJ0aXRpb25lZCAgfCA+IHBpdm90MiAgfCBdXG4gICAgICAvLyAgXiAgICAgICAgICAgIF4gICAgICAgICAgICAgICAgICAgICAgICBeICAgICAgICAgICAgICBeICAgICAgICAgICAgIF5cbiAgICAgIC8vIGxlZnQgICAgICAgICBsZXNzICAgICAgICAgICAgICAgICAgICAgayAgICAgICAgICAgICAgZ3JlYXQgICAgICAgIHJpZ2h0XG4gICAgICAvL1xuICAgICAgLy8gYVtsZWZ0XSBhbmQgYVtyaWdodF0gYXJlIHVuZGVmaW5lZCBhbmQgYXJlIGZpbGxlZCBhZnRlciB0aGVcbiAgICAgIC8vIHBhcnRpdGlvbmluZy5cbiAgICAgIC8vXG4gICAgICAvLyBJbnZhcmlhbnRzOlxuICAgICAgLy8gICAxLiBmb3IgeCBpbiBdbGVmdCwgbGVzc1sgOiB4IDwgcGl2b3QxXG4gICAgICAvLyAgIDIuIGZvciB4IGluIFtsZXNzLCBrWyA6IHBpdm90MSA8PSB4ICYmIHggPD0gcGl2b3QyXG4gICAgICAvLyAgIDMuIGZvciB4IGluIF1ncmVhdCwgcmlnaHRbIDogeCA+IHBpdm90MlxuICAgICAgZm9yICh2YXIgayA9IGxlc3M7IGsgPD0gZ3JlYXQ7IGsrKykge1xuICAgICAgICB2YXIgZWsgPSBhW2tdLCB4ayA9IGYoZWspO1xuICAgICAgICBpZiAoeGsgPCBwaXZvdFZhbHVlMSkge1xuICAgICAgICAgIGlmIChrICE9PSBsZXNzKSB7XG4gICAgICAgICAgICBhW2tdID0gYVtsZXNzXTtcbiAgICAgICAgICAgIGFbbGVzc10gPSBlaztcbiAgICAgICAgICB9XG4gICAgICAgICAgKytsZXNzO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIGlmICh4ayA+IHBpdm90VmFsdWUyKSB7XG4gICAgICAgICAgICB3aGlsZSAodHJ1ZSkge1xuICAgICAgICAgICAgICB2YXIgZ3JlYXRWYWx1ZSA9IGYoYVtncmVhdF0pO1xuICAgICAgICAgICAgICBpZiAoZ3JlYXRWYWx1ZSA+IHBpdm90VmFsdWUyKSB7XG4gICAgICAgICAgICAgICAgZ3JlYXQtLTtcbiAgICAgICAgICAgICAgICBpZiAoZ3JlYXQgPCBrKSBicmVhaztcbiAgICAgICAgICAgICAgICAvLyBUaGlzIGlzIHRoZSBvbmx5IGxvY2F0aW9uIGluc2lkZSB0aGUgbG9vcCB3aGVyZSBhIG5ld1xuICAgICAgICAgICAgICAgIC8vIGl0ZXJhdGlvbiBpcyBzdGFydGVkLlxuICAgICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIC8vIGFbZ3JlYXRdIDw9IHBpdm90Mi5cbiAgICAgICAgICAgICAgICBpZiAoZ3JlYXRWYWx1ZSA8IHBpdm90VmFsdWUxKSB7XG4gICAgICAgICAgICAgICAgICAvLyBUcmlwbGUgZXhjaGFuZ2UuXG4gICAgICAgICAgICAgICAgICBhW2tdID0gYVtsZXNzXTtcbiAgICAgICAgICAgICAgICAgIGFbbGVzcysrXSA9IGFbZ3JlYXRdO1xuICAgICAgICAgICAgICAgICAgYVtncmVhdC0tXSA9IGVrO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAvLyBhW2dyZWF0XSA+PSBwaXZvdDEuXG4gICAgICAgICAgICAgICAgICBhW2tdID0gYVtncmVhdF07XG4gICAgICAgICAgICAgICAgICBhW2dyZWF0LS1dID0gZWs7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuXG4gICAgLy8gTW92ZSBwaXZvdHMgaW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AgICAvLyAgMy4gPT0gcGl2b3QyXG4gICAgICAvL1xuICAgICAgLy8gRHVyaW5nIHRoZSBsb29wIHdlIGhhdmU6XG4gICAgICAvLyBbID09IHBpdm90MSB8ID4gcGl2b3QxICYmIDwgcGl2b3QyIHwgdW5wYXJ0aXRpb25lZCAgfCA9PSBwaXZvdDIgXVxuICAgICAgLy8gICAgICAgICAgICAgIF4gICAgICAgICAgICAgICAgICAgICAgXiAgICAgICAgICAgICAgXlxuICAgICAgLy8gICAgICAgICAgICBsZXNzICAgICAgICAgICAgICAgICAgICAgayAgICAgICAgICAgICAgZ3JlYXRcbiAgICAgIC8vXG4gICAgICAvLyBJbnZhcmlhbnRzOlxuICAgICAgLy8gICAxLiBmb3IgeCBpbiBbICosIGxlc3NbIDogeCA9PSBwaXZvdDFcbiAgICAgIC8vICAgMi4gZm9yIHggaW4gW2xlc3MsIGtbIDogcGl2b3QxIDwgeCAmJiB4IDwgcGl2b3QyXG4gICAgICAvLyAgIDMuIGZvciB4IGluIF1ncmVhdCwgKiBdIDogeCA9PSBwaXZvdDJcbiAgICAgIGZvciAodmFyIGsgPSBsZXNzOyBrIDw9IGdyZWF0OyBrKyspIHtcbiAgICAgICAgdmFyIGVrID0gYVtrXSwgeGsgPSBmKGVrKTtcbiAgICAgICAgaWYgKHhrIDw9IHBpdm90VmFsdWUxICYmIHhrID49IHBpdm90VmFsdWUxKSB7XG4gICAgICAgICAgaWYgKGsgIT09IGxlc3MpIHtcbiAgICAgICAgICAgIGFba10gPSBhW2xlc3NdO1xuICAgICAgICAgICAgYVtsZXNzXSA9IGVrO1xuICAgICAgICAgIH1cbiAgICAgICAgICBsZXNzKys7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgaWYgKHhrIDw9IHBpdm90VmFsdWUyICYmIHhrID49IHBpdm90VmFsdWUyKSB7XG4gICAgICAgICAgICB3aGlsZSAodHJ1ZSkge1xuICAgICAgICAgICAgICB2YXIgZ3JlYXRWYWx1ZSA9IGYoYVtncmVhdF0pO1xuICAgICAgICAgICAgICBpZiAoZ3JlYXRWYWx1ZSA8PSBwaXZvdFZhbHVlMiAmJiBncmVhdFZhbHVlID49IHBpdm90VmFsdWUyKSB7XG4gICAgICAgICAgICAgICAgZ3JlYXQtLTtcbiAgICAgICAgICAgICAgICBpZiAoZ3JlYXQgPCBrKSBicmVhaztcbiAgICAgICAgICAgICAgICAvLyBUaGlzIGlzIHRoZSBvbmx5IGxvY2F0aW9uIGluc2lkZSB0aGUgbG9vcCB3aGVyZSBhIG5ld1xuICAgICAgICAgICAgICAgIC8vIGl0ZXJhdGlvbiBpcyBzdGFydGVkLlxuICAgICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIC8vIGFbZ3JlYXRdIDwgcGl2b3QyLlxuICAgICAgICAgICAgICAgIGlmIChncmVhdFZhbHVlIDwgcGl2b3RWYWx1ZTEpIHtcbiAgICAgICAgICAgICAgICAgIC8vIFRyaXBsZSBleGNoYW5nZS5cbiAgICAgICAgICAgICAgICAgIGFba10gPSBhW2xlc3NdO1xuICAgICAgICAgICAgICAgICAgYVtsZXNzKytdID0gYVtncmVhdF07XG4gICAgICAgICAgICAgICAgICBhW2dyZWF0LS1dID0gZWs7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgIC8vIGFbZ3JlYXRdID09IHBpdm90MS5cbiAgICAgICAgICAgICAgICAgIGFba10gPSBhW2dyZWF0XTtcbiAgICAgICAgICAgICAgICAgIGFbZ3JlYXQtLV0gPSBlaztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG5cbiAgICAvLyBUaGUgc2Vjb25kIHBhcnRpdGlvbiBoYXMgbm93IGJlZW4gY2xlYXJlZC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8wID0gbG8xO1xuICAgICAgICBoaTAgPSBoaTE7XG4gICAgICAgIHJldHVybiBkaW1lbnNpb247XG4gICAgICB9XG5cbiAgICAgIHZhciBpLFxuICAgICAgICAgIGosXG4gICAgICAgICAgayxcbiAgICAgICAgICBhZGRlZCA9IFtdLFxuICAgICAgICAgIHJlbW92ZWQgPSBbXTtcblxuICAgICAgLy8gRmFzdCBpbmNyZW1lbnRhbCB1cGRhdGUgYmFzZWQgb24gcHJldmlvdXMgbG8gaW5kZXguXG4gICAgICBpZiAobG8xIDwgbG8wKSB7XG4gICAgICAgIGZvciAoaSA9IGxvMSwgaiA9IE1hdGgubWluKGxvMCwgaGkxKTsgaSA8IGo7ICsraSkge1xuICAgICAgICAgIGZpbHRlcnNbb2Zmc2V0XVtrID0gaW5kZXhbaV1dIF49IG9uZTtcbiAgICAgICAgICBhZGRlZC5wdXNoKGspO1xuICAgICAgICB9XG4gICAgICB9IGVsc2UgaWYgKGxvMSA+IGxvMCkge1xuICAgICAgICBmb3IgKGkgPSBsbzAsIGogPSBNYXRoLm1pbihsbzEsIGhpMCk7IGkgPCBqOyArK2kpIHtcbiAgICAgICAgICBmaWx0ZXJzW29mZnNldF1bayA9IGluZGV4W2ldXSBePSBvbmU7XG4gICAgICAgICAgcmVtb3ZlZC5wdXNoKGspO1xuICAgICAgICB9XG4gICAgICB9XG5cbiAgICAgIC8vIEZhc3QgaW5jcmVtZW50YWwgdXBkYXRlIGJhc2VkIG9uIHByZXZpb3VzIGhpIGluZGV4LlxuICAgICAgaWYgKGhpMSA+IGhpMCkge1xuICAgICAgICBmb3IgKGkgPSBNYXRoLm1heChsbzEsIGhpMCksIGogPSBoaTE7IGkgPCBqOyArK2kpIHtcbiAgICAgICAgICBmaWx0ZXJzW29mZnNldF1bayA9IGluZGV4W2ldXSBePSBvbmU7XG4gICAgICAgICAgYWRkZWQucHVzaChrKTtcbiAgICAgICAgfVxuICAgICAgfSBlbHNlIGlmIChoaTEgPCBoaTApIHtcbiAgICA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CBsaXN0ZW5lciB0byBwb2ludCB0byB0aGUgbmV3IG1ldGhvZC5cbiAgICAgICAgaiA9IGZpbHRlckxpc3RlbmVycy5pbmRleE9mKHVwZGF0ZSk7XG4gICAgICAgIGlmIChrID4gMSkge1xuICAgICAgICAgIHVwZGF0ZSA9IHVwZGF0ZU1hbnk7XG4gICAgICAgICAgcmVzZXQgPSByZXNldE1hbnk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgaWYgKCFrICYmIGdyb3VwQWxsKSB7XG4gICAgICAgICAgICBrID0gMTtcbiAgICAgICAgICAgIGdyb3VwcyA9IFt7a2V5OiBudWxsLCB2YWx1ZTogaW5pdGlhbCgpfV07XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmIChrID09PSAxKSB7XG4gICAgICAgICAgICB1cGRhdGUgPSB1cGRhdGVPbmU7XG4gICAgICAgICAgICByZXNldCA9IHJlc2V0T25lO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB1cGRhdGUgPSBjcm9zc2ZpbHRlcl9udWxsO1xuICAgICAgICAgICAgcmVzZXQgPSBjcm9zc2ZpbHRlcl9udWxsO1xuICAgICAgICAgIH1cbiAgICAgICAgICBncm91cEluZGV4ID0gbnVsbDtcbiAgICAgICAgfVxuICAgICAgICBmaWx0ZXJMaXN0ZW5lcnNbal0gPSB1cGRhdGU7XG5cbiAgICAgICAgLy8gQ291bnQgdGhlIG51bWJlciBvZiBhZGRlZCBncm91cHMsXG4gICAgICAgIC8vIGFuZCB3aWRlbiB0aGUgZ3JvdXAgaW5kZXggYXMgbmVlZGVkLlxuICAgICAgICBmdW5jdGlvbiBncm91cEluY3JlbWVudCgpIHtcbiAgICAgICAgICBpZiAoKytrID09PSBncm91cENhcGFjaXR5KSB7XG4gICAgICAgICAgICByZUluZGV4ID0gY3Jvc3NmaWx0ZXJfYXJyYXlXaWRlbihyZUluZGV4LCBncm91cFdpZHRoIDw8PSAxKTtcbiAgICAgICAgICAgIGdyb3V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gICAgICBncm91cHMgPSBbXSwgayA9IDA7XG4gICAgICAgICAgZm9yIChpID0gMDsgaSA8IG9sZEs7ICsraSkge1xuICAgICAgICAgICAgaWYgKHNlZW5Hcm91cHNbaV0pIHtcbiAgICAgICAgICAgICAgc2Vlbkdyb3Vwc1tpXSA9IGsrKztcbiAgICAgICAgICAgICAgZ3JvdXBzLnB1c2gob2xkR3JvdXBzW2ldKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG5cbiAgICAgICAgICBpZiAoayA+IDEpIHtcbiAgICAgICAgICAgIC8vIFJlaW5kZXggdGhlIGdyb3VwIGluZGV4IHVzaW5nIHNlZW5Hcm91cHMgdG8gZmluZCB0aGUgbmV3IGluZGV4LlxuICAgICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBqOyArK2kpIGdyb3VwSW5kZXhbaV0gPSBzZWVuR3JvdXBzW2dyb3VwSW5kZXhbaV1dO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBncm91cEluZGV4ID0gbnVsbDtcbiAgICAgICAgICB9XG4gICAgICAgICAgZmlsdGVyTGlzdGVuZXJzW2ZpbHRlckxpc3RlbmVycy5pbmRleE9mKHVwZGF0ZSldID0gayA+IDFcbiAgICAgICAgICAgICAgPyAocmVzZXQgPSByZXNldE1hbnksIHVwZGF0ZSA9IHVwZGF0ZU1hbnkpXG4gICAgICAgICAgICAgIDogayA9PT0gMSA/IChyZXNldCA9IHJlc2V0T25lLCB1cGRhdGUgPSB1cGRhdGVPbmUpXG4gICAgICAgICAgICAgIDogcmVzZXQgPSB1cGRhdGUgPSBjcm9zc2ZpbHRlcl9udWxsO1xuICAgICAgICB9IGVsc2UgaWYgKGsgPT09IDEpIHtcbiAgICAgICAgICBpZiAoZ3JvdXBBbGwpIHJldHVybjtcbiAgICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IG47ICsraSkgaWYgKCFmaWx0ZXJzLnplcm8oaSkpIHJldHVybjtcbiAgICAgICAg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1pY1JlZmVyZW5jZSkge1xuICAgICAgICBleGlzdGluZy5keW5hbWljUmVmZXJlbmNlID0gZmFsc2VcbiAgICAgIH1cbiAgICAgIHJldHVybiBleGlzdGluZy5wcm9taXNlXG4gICAgICAgIC50aGVuKGZ1bmN0aW9uKCkge1xuICAgICAgICAgIHJldHVybiBzZXJ2aWNlXG4gICAgICAgIH0pXG4gICAgfVxuXG4gICAgc2VydmljZS5jb2x1bW5zLnB1c2goY29sdW1uKVxuXG4gICAgY29sdW1uLnByb21pc2UgPSBQcm9taXNlLnRyeShmdW5jdGlvbigpIHtcbiAgICAgICAgcmV0dXJuIFByb21pc2UucmVzb2x2ZShzZXJ2aWNlLmNmLmFsbCgpKVxuICAgICAgfSlcbiAgICAgIC50aGVuKGZ1bmN0aW9uKGFsbCkge1xuXG4gICAgICAgIHZhciBzYW1wbGVcblxuICAgICAgICAvLyBDb21wbGV4IGNvbHVtbiBLZXlzXG4gICAgICAgIGlmIChfLmlzQXJyYXkoY29sdW1uLmtleSkpIHtcbiAgICAgICAgICBjb2x1bW4uY29tcGxleCA9IHRydWVcbiAgICAgICAgICBzYW1wbGUgPSBfLnZhbHVlcyhfLnBpY2soYWxsWzBdLCBjb2x1bW4ua2V5KSlcbiAgICAgICAgICBpZiAoc2FtcGxlLmxlbmd0aCAhPT0gY29sdW1uLmtleS5sZW5ndGgpIHtcbiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcignQ29sdW1uIGtleSBkb2VzIG5vdCBleGlzdCBpbiBkYXRhIScsIGNvbHVtbi5rZXkpXG4gICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHNhbXBsZSA9IGFsbFswXVtjb2x1bW4ua2V5XVxuICAgICAgICB9XG5cbiAgICAgICAgLy8gSW5kZXggQ29sdW1uXG4gICAgICAgIGlmICghY29sdW1uLmNvbXBsZXggJiYgY29sdW1uLmtleSAhPT0gdHJ1ZSAmJiB0eXBlb2Yoc2FtcGxlKSA9PT0gJ3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IEJ1aWxkIHRoZSBjb2x1bW5LZXlzXG4gICAgICAgIGZ1bmN0aW9uIGJ1aWxkQ29sdW1uS2V5cyhvbkFkZCkge1xuICAgICAgICAgIGlmIChjb2x1bW4ua2V5ID09PSB0cnVlKSB7XG4gICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yZXNvbHZlKClcbiAgICAgICAgICB9XG4gICAgICAgICAgcmV0dXJuIFByb21pc2UucmVzb2x2ZShjb2x1bW4uZGltZW5zaW9uLmJvdHRvbShJbmZpbml0eSkpXG4gICAgICAgICAgICAudGhlbihmdW5jdGlvbihyb3dzKSB7XG4gICAgICAgICAgICAgIHZhciBhY2Nlc3NvciA9IGRpbWVuc2lvbi5tYWtlQWNjZXNzb3IoY29sdW1uLmtleSlcbiAgICAgICAgICAgICAgaWYgKGNvbHVtbi50eXBlID09PSAnY29tcGxleCcpIHtcbiAgICAgICAgICAgICAgICBjb2x1bW4udmFsdWVzID0gXy51bmlxKF8uZmxhdHRlbihfLm1hcChyb3dzLCBhY2Nlc3NvcikpKVxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIGVsc2UgaWYgKGNvbHVtbi50eXBlID09PSAnYXJyYXknKSB7XG4gICAgICAgICAgICAgICAgY29sdW1uLnZhbHVlcyA9IF8udW5pcShfLmZsYXR0ZW4oXy5tYXAocm93cywgYWNjZXNzb3IpKSlcbiAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBjb2x1bW4udmFsdWVzID0gXy51bmlxKF8ubWFwKHJvd3MsIGFjY2Vzc29yKSlcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSlcbiAgICAgICAgfVxuICAgICAgfSlcblxuICAgIHJldHVybiBjb2x1bW4ucHJvbWlzZVxuICAgICAgLnRoZW4oZnVuY3Rpb24oKSB7XG4gICAgICAgIHJldHVybiBzZXJ2aWNlXG4gICAgICB9KVxuICB9XG5cbn1cbiIsIid1c2Ugc3RyaWN0J1xuXG52YXIgUHJv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dncmVnYXRvck9iai5wYXJhbXMpKVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIC8vIEl0IG11c3QgYmUgYSBzdHJpbmcgdGhlbi4gUGx1Y2sgdGhhdCBzdHJpbmcga2V5IGZyb20gcGFyZW50LCBhbmQgcGFzcyBpdCBhcyB0aGUgbmV3IHZhbHVlIHRvIHRoZSBzdWJHZXR0ZXJcbiAgICAgICAgcmV0dXJuIGZ1bmN0aW9uKGQpIHtcbiAgICAgICAgICBkID0gZFtrZXldXG4gICAgICAgICAgcmV0dXJuIGdldFN1YihkLCBnZXRTdWIpXG4gICAgICAgIH1cblxuICAgICAgfSlcblxuICAgICAgLy8gQWxsIG9iamVjdCBleHByZXNzaW9ucyBhcmUgYmFzaWNhbGx5IEFORCdzXG4gICAgICAvLyBSZXR1cm4gQU5EIHdpdGggYSBtYXAgb2YgdGhlIHN1YkdldHRlcnNcbiAgICAgIGlmIChpc0FnZ3JlZ2F0aW9uKSB7XG4gICAgICAgIGlmIChzdWJHZXR0ZXJzLmxlbmd0aCA9PT0gMSkge1xuICAgICAgICAgIHJldHVybiBmdW5jdGlvbihkKSB7XG4gICAgICAgICAgICByZXR1cm4gc3ViR2V0dGVyc1swXShkKVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gZnVuY3Rpb24oZCkge1xuICAgICAgICAgIHJldHVybiBfLm1hcChzdWJHZXR0ZXJzLCBmdW5jdGlvbihnZXRTdWIpIHtcbiAgICAgICAgICAgIHJldHVybiBnZXRTdWIoZClcbiAgICAgICAgICB9KVxuICAgICAgICB9XG4gICAgICB9XG4gICAgICByZXR1cm4gZnVuY3Rpb24oZCkge1xuICAgICAgICByZXR1cm4gZXhwcmVzc2lvbnMuJGFuZChkLCBmdW5jdGlvbihkKSB7XG4gICAgICAgICAgcmV0dXJuIF8ubWFwKHN1YkdldHRlcnMsIGZ1bmN0aW9uKGdldFN1Yikge1xuICAgICAgICAgICAgcmV0dXJuIG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x2ZWQgb3IgcmVqZWN0ZWQgdG8gZXhlY3V0ZSB0aGUgbmV4dCB0YXNrXG4gICAgICBuZXh0UHJvbWlzZSA9IHByZXZQcm9taXNlLnRoZW4oXG4gICAgICAgIC8qc3VjY2VzcyovXG4gICAgICAgIGZ1bmN0aW9uKGRhdGEpIHtcbiAgICAgICAgICBpZiAoIXN1Y2Nlc3MpIHtcbiAgICAgICAgICAgIHJldHVybiBkYXRhO1xuICAgICAgICAgIH1cbiAgICAgICAgICB2YXIgcmV0ID0gc3VjY2VzcyhkYXRhKTtcbiAgICAgICAgICBpZiAoIWlzUHJvbWlzZUxpa2UocmV0KSkge1xuICAgICAgICAgICAgZXJyb3IubWVzc2FnZSA9IFwiVGFzayBcIiArIGtleSArIFwiIGRpZCBub3QgcmV0dXJuIGEgcHJvbWlzZS5cIjtcbiAgICAgICAgICAgIHRocm93IGVycm9yO1xuICAgICAgICAgIH1cbiAgICAgICAgICByZXR1cm4gcmV0O1xuICAgICAgICB9LFxuICAgICAgICAvKmZhaWx1cmUqL1xuICAgICAgICBmdW5jdGlvbihyZWFzb24pIHtcbiAgICAgICAgICBpZiAoIWZhaWwpIHtcbiAgICAgICAgICAgIHJldHVybiBQcm9taXNlLnJlamVjdChyZWFzb24pO1xuICAgICAgICAgIH1cbiAgICAgICAgICB2YXIgcmV0ID0gZmFpbChyZWFzb24pO1xuICAgICAgICAgIGlmICghaXNQcm9taXNlTGlrZShyZXQpKSB7XG4gICAgICAgICAgICBlcnJvci5tZXNzYWdlID0gXCJGYWlsIGZvciB0YXNrIFwiICsga2V5ICsgXCIgZGlkIG5vdCByZXR1cm4gYSBwcm9taXNlLlwiO1xuICAgICAgICAgICAgdGhyb3cgZXJyb3I7XG4gICAgICAgICAgfVxuICAgICAgICAgIHJldHVybiByZXQ7XG4gICAgICAgIH0sXG4gICAgICAgIG5vdGlmeSk7XG4gICAgfVxuICAgIHByZXZQcm9taXNlID0gbmV4dFByb21pc2U7XG4gIH0pO1xuXG4gIHJ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lOiBjZi5yZW1vdmUsXG4gICAgICAgIGNvbHVtbjogcmVxdWlyZSgnLi9jb2x1bW4nKShzZXJ2aWNlKSxcbiAgICAgICAgcXVlcnk6IHJlcXVpcmUoJy4vcXVlcnknKShzZXJ2aWNlKSxcbiAgICAgICAgZmlsdGVyOiByZXF1aXJlKCcuL2ZpbHRlcnMnKShzZXJ2aWNlKS5maWx0ZXIsXG4gICAgICAgIGNsZWFyOiByZXF1aXJlKCcuL2NsZWFyJykoc2VydmljZSksXG4gICAgICAgIG9uRGF0YUNoYW5nZTogb25EYXRhQ2hhbmdlXG4gICAgICB9KVxuICAgIH0pXG5cbiAgZnVuY3Rpb24gb25EYXRhQ2hhbmdlKGNiKXtcbiAgICBzZXJ2aWNlLmRhdGFMaXN0ZW5lcnMucHVzaChjYilcbiAgICByZXR1cm4gZnVuY3Rpb24oKXtcbiAgICAgIHNlcnZpY2UuZGF0YUxpc3RlbmVycy5zcGxpY2Uoc2VydmljZS5kYXRhTGlzdGVuZXJzLmluZGV4T2YoY2IpLCAxKVxuICAgIH1cbiAgfVxufVxuIl19 diff --git a/universe.min.js b/universe.min.js index 6f5ff52..07f0b38 100644 --- a/universe.min.js +++ b/universe.min.js @@ -1,3 +1,3 @@ !function(n){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.universe=n()}}(function(){var n;return function e(n,t,r){function u(o,c){if(!t[o]){if(!n[o]){var f="function"==typeof require&&require;if(!c&&f)return f(o,!0);if(i)return i(o,!0);var a=new Error("Cannot find module '"+o+"'");throw a.code="MODULE_NOT_FOUND",a}var s=t[o]={exports:{}};n[o][0].call(s.exports,function(e){var t=n[o][1][e];return u(t?t:e)},s,s.exports,e,n,t,r)}return t[o].exports}for(var i="function"==typeof require&&require,o=0;o1)for(var t=1;tr;++r)i[r]=n[e[r]];return i}function r(n){function e(e,t,r,u){for(;u>r;){var i=r+u>>>1;n(e[i])r;){var i=r+u>>>1;t>>1)+1;--i>0;)r(n,i,u,e);return n}function t(n,e,t){for(var u,i=t-e;--i>0;)u=n[e],n[e]=n[e+i],n[e+i]=u,r(n,1,i,e);return n}function r(e,t,r,u){for(var i,o=e[--u+t],c=n(o);(i=t<<1)<=r&&(r>i&&n(e[u+i])>n(e[u+i+1])&&i++,!(c<=n(e[u+i])));)e[u+t]=e[u+i],t=i;e[u+t]=o}return e.sort=t,e}function o(n){function e(e,r,u,i){var o,c,f,a,s=new Array(i=Math.min(u-r,i));for(c=0;i>c;++c)s[c]=e[r++];if(t(s,0,i),u>r){o=n(s[0]);do(f=n(a=e[r])>o)&&(s[0]=a,o=n(t(s,0,i)[0]));while(++ru;++u){for(var i=u,o=e[u],c=n(o);i>t&&n(e[i-1])>c;--i)e[i]=e[i-1];e[i]=o}return e}return e}function f(n){function e(n,e,u){return(T>u-e?r:t)(n,e,u)}function t(t,r,u){var i,o=(u-r)/6|0,c=r+o,f=u-1-o,a=r+u-1>>1,s=a-o,l=a+o,p=t[c],d=n(p),v=t[s],h=n(v),m=t[a],y=n(m),g=t[l],x=n(g),b=t[f],k=n(b);d>h&&(i=p,p=v,v=i,i=d,d=h,h=i),x>k&&(i=g,g=b,b=i,i=x,x=k,k=i),d>y&&(i=p,p=m,m=i,i=d,d=y,y=i),h>y&&(i=v,v=m,m=i,i=h,h=y,y=i),d>x&&(i=p,p=g,g=i,i=d,d=x,x=i),y>x&&(i=m,m=g,g=i,i=y,y=x,x=i),h>k&&(i=v,v=b,b=i,i=h,h=k,k=i),h>y&&(i=v,v=m,m=i,i=h,h=y,y=i),x>k&&(i=g,g=b,b=i,i=x,x=k,k=i);var w=v,A=h,j=g,O=x;t[c]=p,t[s]=t[r],t[a]=m,t[l]=t[u-1],t[f]=b;var E=r+1,L=u-2,S=O>=A&&A>=O;if(S)for(var R=E;L>=R;++R){var $=t[R],q=n($);if(A>q)R!==E&&(t[R]=t[E],t[E]=$),++E;else if(q>A)for(;;){var I=n(t[L]);{if(!(I>A)){if(A>I){t[R]=t[E],t[E++]=t[L],t[L--]=$;break}t[R]=t[L],t[L--]=$;break}L--}}}else for(var R=E;L>=R;R++){var $=t[R],q=n($);if(A>q)R!==E&&(t[R]=t[E],t[E]=$),++E;else if(q>O)for(;;){var I=n(t[L]);{if(!(I>O)){A>I?(t[R]=t[E],t[E++]=t[L],t[L--]=$):(t[R]=t[L],t[L--]=$);break}if(L--,R>L)break}}}if(t[r]=t[E-1],t[E-1]=w,t[u-1]=t[L+1],t[L+1]=j,e(t,r,E-1),e(t,L+2,u),S)return t;if(c>E&&L>f){for(var T,I;(T=n(t[E]))<=A&&T>=A;)++E;for(;(I=n(t[L]))<=O&&I>=O;)--L;for(var R=E;L>=R;R++){var $=t[R],q=n($);if(A>=q&&q>=A)R!==E&&(t[R]=t[E],t[E]=$),E++;else if(O>=q&&q>=O)for(;;){var I=n(t[L]);{if(!(O>=I&&I>=O)){A>I?(t[R]=t[E],t[E++]=t[L],t[L--]=$):(t[R]=t[L],t[L--]=$);break}if(L--,R>L)break}}}}return e(t,E,L+1)}var r=c(n);return e}function a(n){for(var e=new Array(n),t=-1;++tt;)n[t++]=0;return n}function p(n,e){if(e>32)throw new Error("invalid array width!");return n}function d(n){this.length=n,this.subarrays=1,this.width=8,this.masks={0:0},this[0]=z(n)}function v(n,e){return function(t){var r=t.length;return[n.left(t,e,0,r),n.right(t,e,0,r)]}}function h(n,e){var t=e[0],r=e[1];return function(e){var u=e.length;return[n.left(e,t,0,u),n.left(e,r,0,u)]}}function m(n){return[0,n.length]}function y(){return null}function g(){return 0}function x(n){return n+1}function b(n){return n-1}function w(n){return function(e,t){return e+ +n(t)}}function A(n){return function(e,t){return e-n(t)}}function j(){function n(n){var e=T,t=n.length;return t&&(I=I.concat(n),$.lengthen(T+=t),N.forEach(function(r){r(n,e,t)}),R("dataAdded")),q}function r(){for(var n=O(T,T),e=[],t=0,r=0;T>t;++t)$.zero(t)?e.push(t):n[t]=r++;z.forEach(function(n){n(-1,-1,[],e,!0)}),C.forEach(function(e){e(n)});for(var t=0,r=0;T>t;++t)$.zero(t)||(t!==r&&($.copy(r,t),I[r]=I[t]),++r);I.length=T=r,$.truncate(r),R("dataRemoved")}function c(n,r){function c(e,u,o){if(r){for(yn=0,v=0,k=[],i=0;iv+d;v++)tn[v+d]=rn[v]}for(i=0;i0t;++t)$.zero(e=X[t])||(t!==r&&(H[r]=H[t]),X[r]=n[e],++r);for(H.length=r;T>r;)X[r++]=0;var u=pn(H);hn=u[0],mn=u[1]}function p(n){var e=n[0],t=n[1];if(an)return an=null,D(function(n,r){return r>=e&&t>r},0===n[0]&&n[1]===X.length),hn=e,mn=t,sn;var u,i,o,c=[],f=[],a=[],s=[];if(hn>e)for(u=e,i=Math.min(hn,t);i>u;++u)c.push(X[u]),a.push(u);else if(e>hn)for(u=hn,i=Math.min(e,mn);i>u;++u)f.push(X[u]),s.push(u);if(t>mn)for(u=Math.max(e,mn),i=t;i>u;++u)c.push(X[u]),a.push(u);else if(mn>t)for(u=Math.max(hn,t),i=mn;i>u;++u)f.push(X[u]),s.push(u);if(r){var l=[],p=[];for(u=0;ut;++t)!($[G][u=X[t]]&Q)^!!(i=n(H[t],t))&&(i?o.push(u):c.push(u));if(r)for(t=0;s>t;++t)n(H[t],t)?(o.push(X[t]),f.push(t)):(c.push(X[t]),a.push(t));if(r){var l=[],p=[];for(t=0;t=hn&&n>0;)$.zero(e=X[u])&&(t.push(I[e]),--n);if(r)for(u=0;u0;u++)$.zero(e=fn[u])&&(t.push(I[e]),--n);return t}function K(n){var e,t,u=[];if(r)for(e=0;e0;e++)$.zero(t=fn[e])&&(u.push(I[t]),--n);for(e=hn;mn>e&&n>0;)$.zero(t=X[e])&&(u.push(I[t]),--n),e++;return u}function V(n){function c(e,u,o,c){function f(){return r?void W++:void(++W===J&&(k=F(k,_<<=1),M=F(M,_),J=L(_)))}r&&(n0old=o,o=H.length-e.length,c=e.length);var d,v,h,m,g,x,b=N,k=r?[]:O(W,J),w=B,A=K,j=V,E=W,S=0,R=0;for(en&&(w=j=y),en&&(A=j=y),N=new Array(W),W=0,M=r?E>1?M:[]:E>1?P(M,T):O(T,J),E&&(h=(v=b[0]).key);c>R&&!((m=n(e[R]))>=m);)++R;for(;c>R;){for(v&&m>=h?(g=v,x=h,k[S]=W,(v=b[++S])&&(h=v.key)):(g={key:m,value:j()},x=m),N[W]=g;x>=m&&(d=u[R]+(r?n0old:o),r?M[d]?M[d].push(W):M[d]=[W]:M[d]=W,g.value=w(g.value,I[d],!0),$.zeroExcept(d,G,Y)||(g.value=A(g.value,I[d],!1)),!(++R>=c));)m=n(e[R]);f()}for(;E>S;)N[k[S]=W]=b[S++],f();if(r)for(i=0;iS)if(r)M=t(M,k,!0);else for(S=0;o>S;++S)M[S]=k[M[S]];d=z.indexOf(Z),W>1?(Z=a,nn=l):(!W&&tn&&(W=1,N=[{key:null,value:j()}]),1===W?(Z=s,nn=p):(Z=y,nn=y),M=null),z[d]=Z}function f(){if(W>1){for(var n=W,e=N,t=O(n,n),r=0,u=0;T>r;++r)$.zero(r)||(t[M[u]=M[r]]=1,++u);for(N=[],W=0,r=0;n>r;++r)t[r]&&(t[r]=W++,N.push(e[r]));if(W>1)for(var r=0;u>r;++r)M[r]=t[M[r]];else M=null;z[z.indexOf(Z)]=W>1?(nn=l,Z=a):1===W?(nn=p,Z=s):nn=Z=y}else if(1===W){if(tn)return;for(var r=0;T>r;++r)if(!$.zero(r))return;N=[],W=0,z[z.indexOf(Z)]=Z=nn=y}}function a(n,e,t,u,i){if(!(n===Q&&e===G||en)){var o,c,f,a,s;if(r){for(o=0,a=t.length;a>o;++o)if($.zeroExcept(f=t[o],G,Y))for(c=0;co;++o)if($.onlyExcept(f=u[o],G,Y,e,n))for(c=0;co;++o)$.zeroExcept(f=t[o],G,Y)&&(s=N[M[f]],s.value=B(s.value,I[f],!1));for(o=0,a=u.length;a>o;++o)$.onlyExcept(f=u[o],G,Y,e,n)&&(s=N[M[f]],s.value=K(s.value,I[f],i))}}}function s(n,e,t,r,u){if(!(n===Q&&e===G||en)){var i,o,c,f=N[0];for(i=0,c=t.length;c>i;++i)$.zeroExcept(o=t[i],G,Y)&&(f.value=B(f.value,I[o],!1));for(i=0,c=r.length;c>i;++i)$.onlyExcept(o=r[i],G,Y,e,n)&&(f.value=K(f.value,I[o],u))}}function l(){var n,e,t;for(n=0;W>n;++n)N[n].value=V();if(r){for(n=0;T>n;++n)for(e=0;en;++n)if(!$.zeroExcept(n,G,Y))for(e=0;en;++n)t=N[M[n]],t.value=B(t.value,I[n],!0);for(n=0;T>n;++n)$.zeroExcept(n,G,Y)||(t=N[M[n]],t.value=K(t.value,I[n],!1))}}function p(){var n,e=N[0];for(e.value=V(),n=0;T>n;++n)e.value=B(e.value,I[n],!0);for(n=0;T>n;++n)$.zeroExcept(n,G,Y)||(e.value=K(e.value,I[n],!1))}function d(){return en&&(nn(),en=!1),N}function v(n){var e=U(d(),0,N.length,n);return D.sort(e,0,e.length)}function h(n,e,t){return B=n,K=e,V=t,en=!0,q}function m(){return h(x,b,g)}function k(n){return h(w(n),A(n),g)}function j(n){function e(e){return n(e.value)}return U=o(e),D=u(e),q}function E(){return j(e)}function S(){return W}function R(){var n=z.indexOf(Z);return n>=0&&z.splice(n,1),n=dn.indexOf(c),n>=0&&dn.splice(n,1),n=C.indexOf(f),n>=0&&C.splice(n,1),q}var q={top:v,all:d,reduce:h,reduceCount:m,reduceSum:k,order:j,orderNatural:E,size:S,dispose:R,remove:R};vn.push(q);var N,M,U,D,B,K,V,_=8,J=L(_),W=0,Z=y,nn=y,en=!0,tn=n===y;return arguments.length<1&&(n=e),z.push(Z),dn.push(c),C.push(f),c(H,X,0,T),m().orderNatural()}function _(){var n=V(y),e=n.all;return delete n.all,delete n.top,delete n.order,delete n.orderNatural,delete n.size,n.value=function(){return e()[0].value},n}function J(){vn.forEach(function(n){n.dispose()});var n=N.indexOf(c);return n>=0&&N.splice(n,1),n=N.indexOf(a),n>=0&&N.splice(n,1),n=C.indexOf(s),n>=0&&C.splice(n,1),$.masks[G]&=Y,M()}var Q,Y,G,H,X,W,Z,nn,en,tn,rn,un,on,cn,fn,an,sn={filter:d,filterExact:j,filterRange:q,filterFunction:U,filterAll:M,top:B,bottom:K,group:V,groupAll:_,dispose:J,remove:J},ln=f(function(n){return nn[n]}),pn=m,dn=[],vn=[],hn=0,mn=0,yn=0;N.unshift(c),N.push(a),C.push(s);var gn=$.add();return G=gn.offset,Q=gn.one,Y=~Q,c(I,0,T),a(I,0,T),sn}function a(){function n(n,e){var t;if(!d)for(t=e;T>t;++t)f=a(f,I[t],!0),$.zero(t)||(f=s(f,I[t],!1))}function e(n,e,t,r,u){var i,o,c;if(!d){for(i=0,c=t.length;c>i;++i)$.zero(o=t[i])&&(f=a(f,I[o],u));for(i=0,c=r.length;c>i;++i)$.only(o=r[i],e,n)&&(f=s(f,I[o],u))}}function t(){var n;for(f=l(),n=0;T>n;++n)f=a(f,I[n],!0),$.zero(n)||(f=s(f,I[n],!1))}function r(n,e,t){return a=n,s=e,l=t,d=!0,p}function u(){return r(x,b,g)}function i(n){return r(w(n),A(n),g)}function o(){return d&&(t(),d=!1),f}function c(){var t=z.indexOf(e);return t>=0&&z.splice(t),t=N.indexOf(n),t>=0&&N.splice(t),p}var f,a,s,l,p={reduce:r,reduceCount:u,reduceSum:i,value:o,dispose:c,remove:c},d=!0;return z.push(e),N.push(n),n(I,0,T),u()}function s(){return T}function p(){return I}function j(n){return"function"!=typeof n?void console.warn("onChange callback parameter must be a function!"):(M.push(n),function(){M.splice(M.indexOf(n),1)})}function R(n){for(var e=0;ee?z:65537>e?N:C)(n)}function E(n){for(var e=O(n,n),t=-1;++t=e)return n;var t=new n.constructor(e);return t.set(n),t},F=function(n,e){var t;switch(e){case 16:t=N(n.length);break;case 32:t=C(n.length);break;default:throw new Error("invalid array width!")}return t.set(n),t}),d.prototype.lengthen=function(n){var e,t;for(e=0,t=this.subarrays;t>e;++e)this[e]=P(this[e],n);this.length=n},d.prototype.add=function(){var n,e,t,r,u;for(r=0,u=this.subarrays;u>r;++r)if(n=this.masks[r],e=this.width-32*r,t=~n&-~n,!(e>=32)||t)return 32>e&&t&1<t;++t)this[t][n]=this[t][e]},d.prototype.truncate=function(n){var e,t;for(e=0,t=this.subarrays;t>e;++e){for(var r=this.length-1;r>=n;r--)this[e][r]=0;this[e].length=n}this.length=n},d.prototype.zero=function(n){var e,t;for(e=0,t=this.subarrays;t>e;++e)if(this[e][n])return!1;return!0},d.prototype.zeroExcept=function(n,e,t){var r,u;for(r=0,u=this.subarrays;u>r;++r)if(r===e?this[r][n]&t:this[r][n])return!1;return!0},d.prototype.only=function(n,e,t){var r,u;for(r=0,u=this.subarrays;u>r;++r)if(this[r][n]!=(r===e?t:0))return!1;return!0},d.prototype.onlyExcept=function(n,e,t,r,u){var i,o,c;for(o=0,c=this.subarrays;c>o;++o)if(i=this[o][n],o===e&&(i&=t),i!=(o===r?u:0))return!1;return!0},n.crossfilter=j}("undefined"!=typeof t&&t||this)},{}],3:[function(n,e,t){e.exports=n("./crossfilter").crossfilter},{"./crossfilter":2}],4:[function(n,e,t){e.exports=function r(n,e){"use strict";var t,u,i=/(^([+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?)?$|^0x[0-9a-f]+$|\d+)/gi,o=/(^[ ]*|[ ]*$)/g,c=/(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,f=/^0x[0-9a-f]+$/i,a=/^0/,s=function(n){return r.insensitive&&(""+n).toLowerCase()||""+n},l=s(n).replace(o,"")||"",p=s(e).replace(o,"")||"",d=l.replace(i,"\x00$1\x00").replace(/\0$/,"").replace(/^\0/,"").split("\x00"),v=p.replace(i,"\x00$1\x00").replace(/\0$/,"").replace(/^\0/,"").split("\x00"),h=parseInt(l.match(f),16)||1!==d.length&&l.match(c)&&Date.parse(l),m=parseInt(p.match(f),16)||h&&p.match(c)&&Date.parse(p)||null;if(m){if(m>h)return-1;if(h>m)return 1}for(var y=0,g=Math.max(d.length,v.length);g>y;y++){if(t=!(d[y]||"").match(a)&&parseFloat(d[y])||d[y]||0,u=!(v[y]||"").match(a)&&parseFloat(v[y])||v[y]||0,isNaN(t)!==isNaN(u))return isNaN(t)?1:-1;if(typeof t!=typeof u&&(t+="",u+=""),u>t)return-1;if(t>u)return 1}return 0}},{}],5:[function(e,t,r){(function(e){!function(e){"use strict";if("function"==typeof bootstrap)bootstrap("promise",e);else if("object"==typeof r&&"object"==typeof t)t.exports=e();else if("function"==typeof n&&n.amd)n(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeQ=e}else{if("undefined"==typeof window&&"undefined"==typeof self)throw new Error("This environment was not anticipated by Q. Please file a bug.");var u="undefined"!=typeof window?window:self,i=u.Q;u.Q=e(),u.Q.noConflict=function(){return u.Q=i,this}}}(function(){"use strict";function n(n){return function(){return G.apply(n,arguments)}}function t(n){return n===Object(n)}function r(n){return"[object StopIteration]"===rn(n)||n instanceof _}function u(n,e){if(B&&e.stack&&"object"==typeof n&&null!==n&&n.stack&&-1===n.stack.indexOf(un)){for(var t=[],r=e;r;r=r.source)r.stack&&t.unshift(r.stack);t.unshift(n.stack);var u=t.join("\n"+un+"\n");n.stack=i(u)}}function i(n){for(var e=n.split("\n"),t=[],r=0;r=J&&sn>=r}function a(){if(B)try{throw new Error}catch(n){var e=n.stack.split("\n"),t=e[0].indexOf("@")>0?e[1]:e[2],r=c(t);if(!r)return;return V=r[0],r[1]}}function s(n,e,t){return function(){return"undefined"!=typeof console&&"function"==typeof console.warn&&console.warn(e+" is deprecated, use "+t+" instead.",new Error("").stack),n.apply(n,arguments)}}function l(n){return n instanceof h?n:x(n)?S(n):L(n)}function p(){function n(n){e=n,i.source=n,X(t,function(e,t){l.nextTick(function(){n.promiseDispatch.apply(n,t)})},void 0),t=void 0,r=void 0}var e,t=[],r=[],u=nn(p.prototype),i=nn(h.prototype);if(i.promiseDispatch=function(n,u,i){var o=H(arguments);t?(t.push(o),"when"===u&&i[1]&&r.push(i[1])):l.nextTick(function(){e.promiseDispatch.apply(e,o)})},i.valueOf=function(){if(t)return i;var n=y(e);return g(n)&&(e=n),n},i.inspect=function(){return e?e.inspect():{state:"pending"}},l.longStackSupport&&B)try{throw new Error}catch(o){i.stack=o.stack.substring(o.stack.indexOf("\n")+1)}return u.promise=i,u.resolve=function(t){e||n(l(t))},u.fulfill=function(t){e||n(L(t))},u.reject=function(t){e||n(E(t))},u.notify=function(n){e||X(r,function(e,t){l.nextTick(function(){t(n)})},void 0)},u}function d(n){if("function"!=typeof n)throw new TypeError("resolver must be a function.");var e=p();try{n(e.resolve,e.reject,e.notify)}catch(t){e.reject(t)}return e.promise}function v(n){return d(function(e,t){for(var r=0,u=n.length;u>r;r++)l(n[r]).then(e,t)})}function h(n,e,t){void 0===e&&(e=function(n){return E(new Error("Promise does not support operation: "+n))}),void 0===t&&(t=function(){return{state:"unknown"}});var r=nn(h.prototype);if(r.promiseDispatch=function(t,u,i){var o;try{o=n[u]?n[u].apply(r,i):e.call(r,u,i)}catch(c){o=E(c)}t&&t(o)},r.inspect=t,t){var u=t();"rejected"===u.state&&(r.exception=u.reason),r.valueOf=function(){var n=t();return"pending"===n.state||"rejected"===n.state?r:n.value}}return r}function m(n,e,t,r){return l(n).then(e,t,r)}function y(n){if(g(n)){var e=n.inspect();if("fulfilled"===e.state)return e.value}return n}function g(n){return n instanceof h}function x(n){return t(n)&&"function"==typeof n.then}function b(n){return g(n)&&"pending"===n.inspect().state}function k(n){return!g(n)||"fulfilled"===n.inspect().state}function w(n){return g(n)&&"rejected"===n.inspect().state}function A(){on.length=0,cn.length=0,an||(an=!0)}function j(n,t){an&&("object"==typeof e&&"function"==typeof e.emit&&l.nextTick.runAfter(function(){-1!==W(cn,n)&&(e.emit("unhandledRejection",t,n),fn.push(n))}),cn.push(n),t&&"undefined"!=typeof t.stack?on.push(t.stack):on.push("(no stack) "+t))}function O(n){if(an){var t=W(cn,n);-1!==t&&("object"==typeof e&&"function"==typeof e.emit&&l.nextTick.runAfter(function(){var r=W(fn,n);-1!==r&&(e.emit("rejectionHandled",on[t],n),fn.splice(r,1))}),cn.splice(t,1),on.splice(t,1))}}function E(n){var e=h({when:function(e){return e&&O(this),e?e(n):this}},function(){return this},function(){return{state:"rejected",reason:n}});return j(e,n),e}function L(n){return h({when:function(){return n},get:function(e){return n[e]},set:function(e,t){n[e]=t},"delete":function(e){delete n[e]},post:function(e,t){return null===e||void 0===e?n.apply(void 0,t):n[e].apply(n,t)},apply:function(e,t){return n.apply(e,t)},keys:function(){return tn(n)}},void 0,function(){return{state:"fulfilled",value:n}})}function S(n){var e=p();return l.nextTick(function(){try{n.then(e.resolve,e.reject,e.notify)}catch(t){e.reject(t)}}),e.promise}function R(n){return h({isDef:function(){}},function(e,t){return N(n,e,t)},function(){return l(n).inspect()})}function $(n,e,t){return l(n).spread(e,t)}function q(n){return function(){function e(n,e){var o;if("undefined"==typeof StopIteration){try{o=t[n](e)}catch(c){return E(c)}return o.done?l(o.value):m(o.value,u,i)}try{o=t[n](e)}catch(c){return r(c)?l(c.value):E(c)}return m(o,u,i)}var t=n.apply(this,arguments),u=e.bind(e,"next"),i=e.bind(e,"throw");return u()}}function I(n){l.done(l.async(n)())}function T(n){throw new _(n)}function z(n){return function(){return $([this,C(arguments)],function(e,t){return n.apply(e,t)})}}function N(n,e,t){return l(n).dispatch(e,t)}function C(n){return m(n,function(n){var e=0,t=p();return X(n,function(r,u,i){var o;g(u)&&"fulfilled"===(o=u.inspect()).state?n[i]=o.value:(++e,m(u,function(r){n[i]=r,0===--e&&t.resolve(n)},t.reject,function(n){t.notify({index:i,value:n})}))},void 0),0===e&&t.resolve(n),t.promise})}function P(n){if(0===n.length)return l.resolve();var e=l.defer(),t=0;return X(n,function(r,u,i){function o(n){e.resolve(n)}function c(){t--,0===t&&e.reject(new Error("Can't get fulfillment value from any promise, all promises were rejected."))}function f(n){e.notify({index:i,value:n})}var a=n[i];t++,m(a,o,c,f)},void 0),e.promise}function F(n){return m(n,function(n){return n=Z(n,l),m(C(Z(n,function(n){return m(n,Q,Q)})),function(){return n})})}function M(n){return l(n).allSettled()}function U(n,e){return l(n).then(void 0,void 0,e)}function D(n,e){return l(n).nodeify(e)}var B=!1;try{throw new Error}catch(K){B=!!K.stack}var V,_,J=a(),Q=function(){},Y=function(){function n(){for(var n,e;r.next;)r=r.next,n=r.task,r.task=void 0,e=r.domain,e&&(r.domain=void 0,e.enter()),t(n,e);for(;f.length;)n=f.pop(),t(n);i=!1}function t(e,t){try{e()}catch(r){if(c)throw t&&t.exit(),setTimeout(n,0),t&&t.enter(),r;setTimeout(function(){throw r},0)}t&&t.exit()}var r={task:void 0,next:null},u=r,i=!1,o=void 0,c=!1,f=[];if(Y=function(n){u=u.next={task:n,domain:c&&e.domain,next:null},i||(i=!0,o())},"object"==typeof e&&"[object process]"===e.toString()&&e.nextTick)c=!0,o=function(){e.nextTick(n)};else if("function"==typeof setImmediate)o="undefined"!=typeof window?setImmediate.bind(window,n):function(){setImmediate(n)};else if("undefined"!=typeof MessageChannel){var a=new MessageChannel;a.port1.onmessage=function(){o=s,a.port1.onmessage=n,n()};var s=function(){a.port2.postMessage(0)};o=function(){setTimeout(n,0),s()}}else o=function(){setTimeout(n,0)};return Y.runAfter=function(n){f.push(n),i||(i=!0,o())},Y}(),G=Function.call,H=n(Array.prototype.slice),X=n(Array.prototype.reduce||function(n,e){var t=0,r=this.length;if(1===arguments.length)for(;;){if(t in this){e=this[t++];break}if(++t>=r)throw new TypeError}for(;r>t;t++)t in this&&(e=n(e,this[t],t));return e}),W=n(Array.prototype.indexOf||function(n){for(var e=0;e2?n.resolve(H(arguments,1)):n.resolve(t)}},l.Promise=d,l.promise=d,d.race=v,d.all=C,d.reject=E,d.resolve=l,l.passByCopy=function(n){return n},h.prototype.passByCopy=function(){return this},l.join=function(n,e){return l(n).join(e)},h.prototype.join=function(n){return l([this,n]).spread(function(n,e){if(n===e)return n;throw new Error("Can't join: not the same: "+n+" "+e)})},l.race=v,h.prototype.race=function(){return this.then(l.race)},l.makePromise=h,h.prototype.toString=function(){return"[object Promise]"},h.prototype.then=function(n,e,t){function r(e){try{return"function"==typeof n?n(e):e}catch(t){return E(t)}}function i(n){if("function"==typeof e){u(n,c);try{return e(n)}catch(t){return E(t)}}return E(n)}function o(n){return"function"==typeof t?t(n):n}var c=this,f=p(),a=!1;return l.nextTick(function(){c.promiseDispatch(function(n){a||(a=!0,f.resolve(r(n)))},"when",[function(n){a||(a=!0,f.resolve(i(n)))}])}),c.promiseDispatch(void 0,"when",[void 0,function(n){var e,t=!1;try{e=o(n)}catch(r){if(t=!0,!l.onerror)throw r;l.onerror(r)}t||f.notify(e)}]),f.promise},l.tap=function(n,e){return l(n).tap(e)},h.prototype.tap=function(n){return n=l(n),this.then(function(e){return n.fcall(e).thenResolve(e)})},l.when=m,h.prototype.thenResolve=function(n){return this.then(function(){return n})},l.thenResolve=function(n,e){return l(n).thenResolve(e)},h.prototype.thenReject=function(n){return this.then(function(){throw n})},l.thenReject=function(n,e){return l(n).thenReject(e)},l.nearer=y,l.isPromise=g,l.isPromiseAlike=x,l.isPending=b,h.prototype.isPending=function(){return"pending"===this.inspect().state},l.isFulfilled=k,h.prototype.isFulfilled=function(){return"fulfilled"===this.inspect().state},l.isRejected=w,h.prototype.isRejected=function(){return"rejected"===this.inspect().state};var on=[],cn=[],fn=[],an=!0;l.resetUnhandledRejections=A,l.getUnhandledReasons=function(){return on.slice()},l.stopUnhandledRejectionTracking=function(){A(),an=!1},A(),l.reject=E,l.fulfill=L,l.master=R,l.spread=$,h.prototype.spread=function(n,e){return this.all().then(function(e){return n.apply(void 0,e)},e)},l.async=q,l.spawn=I,l["return"]=T,l.promised=z,l.dispatch=N,h.prototype.dispatch=function(n,e){var t=this,r=p();return l.nextTick(function(){t.promiseDispatch(r.resolve,n,e)}),r.promise},l.get=function(n,e){return l(n).dispatch("get",[e])},h.prototype.get=function(n){return this.dispatch("get",[n])},l.set=function(n,e,t){return l(n).dispatch("set",[e,t])},h.prototype.set=function(n,e){return this.dispatch("set",[n,e])},l.del=l["delete"]=function(n,e){return l(n).dispatch("delete",[e])},h.prototype.del=h.prototype["delete"]=function(n){return this.dispatch("delete",[n])},l.mapply=l.post=function(n,e,t){return l(n).dispatch("post",[e,t])},h.prototype.mapply=h.prototype.post=function(n,e){return this.dispatch("post",[n,e])},l.send=l.mcall=l.invoke=function(n,e){return l(n).dispatch("post",[e,H(arguments,2)])},h.prototype.send=h.prototype.mcall=h.prototype.invoke=function(n){return this.dispatch("post",[n,H(arguments,1)])},l.fapply=function(n,e){return l(n).dispatch("apply",[void 0,e])},h.prototype.fapply=function(n){return this.dispatch("apply",[void 0,n])},l["try"]=l.fcall=function(n){return l(n).dispatch("apply",[void 0,H(arguments,1)])},h.prototype.fcall=function(){return this.dispatch("apply",[void 0,H(arguments)])},l.fbind=function(n){var e=l(n),t=H(arguments,1);return function(){return e.dispatch("apply",[this,t.concat(H(arguments))])}},h.prototype.fbind=function(){var n=this,e=H(arguments);return function(){return n.dispatch("apply",[this,e.concat(H(arguments))])}},l.keys=function(n){return l(n).dispatch("keys",[])},h.prototype.keys=function(){return this.dispatch("keys",[])},l.all=C,h.prototype.all=function(){return C(this)},l.any=P,h.prototype.any=function(){return P(this)},l.allResolved=s(F,"allResolved","allSettled"),h.prototype.allResolved=function(){return F(this)},l.allSettled=M,h.prototype.allSettled=function(){return this.then(function(n){return C(Z(n,function(n){function e(){return n.inspect()}return n=l(n),n.then(e,e)}))})},l.fail=l["catch"]=function(n,e){return l(n).then(void 0,e)},h.prototype.fail=h.prototype["catch"]=function(n){return this.then(void 0,n)},l.progress=U,h.prototype.progress=function(n){return this.then(void 0,void 0,n)},l.fin=l["finally"]=function(n,e){return l(n)["finally"](e)},h.prototype.fin=h.prototype["finally"]=function(n){return n=l(n),this.then(function(e){return n.fcall().then(function(){return e})},function(e){return n.fcall().then(function(){throw e})})},l.done=function(n,e,t,r){return l(n).done(e,t,r)},h.prototype.done=function(n,t,r){var i=function(n){l.nextTick(function(){if(u(n,o),!l.onerror)throw n;l.onerror(n)})},o=n||t||r?this.then(n,t,r):this;"object"==typeof e&&e&&e.domain&&(i=e.domain.bind(i)),o.then(void 0,i)},l.timeout=function(n,e,t){return l(n).timeout(e,t)},h.prototype.timeout=function(n,e){var t=p(),r=setTimeout(function(){e&&"string"!=typeof e||(e=new Error(e||"Timed out after "+n+" ms"),e.code="ETIMEDOUT"),t.reject(e)},n);return this.then(function(n){clearTimeout(r),t.resolve(n)},function(n){clearTimeout(r),t.reject(n)},t.notify),t.promise},l.delay=function(n,e){return void 0===e&&(e=n,n=void 0),l(n).delay(e)},h.prototype.delay=function(n){return this.then(function(e){var t=p();return setTimeout(function(){t.resolve(e)},n),t.promise})},l.nfapply=function(n,e){return l(n).nfapply(e)},h.prototype.nfapply=function(n){var e=p(),t=H(n);return t.push(e.makeNodeResolver()),this.fapply(t).fail(e.reject),e.promise},l.nfcall=function(n){var e=H(arguments,1);return l(n).nfapply(e)},h.prototype.nfcall=function(){var n=H(arguments),e=p();return n.push(e.makeNodeResolver()),this.fapply(n).fail(e.reject),e.promise},l.nfbind=l.denodeify=function(n){var e=H(arguments,1);return function(){var t=e.concat(H(arguments)),r=p();return t.push(r.makeNodeResolver()),l(n).fapply(t).fail(r.reject),r.promise}},h.prototype.nfbind=h.prototype.denodeify=function(){var n=H(arguments);return n.unshift(this),l.denodeify.apply(void 0,n)},l.nbind=function(n,e){var t=H(arguments,2);return function(){function r(){return n.apply(e,arguments)}var u=t.concat(H(arguments)),i=p();return u.push(i.makeNodeResolver()),l(r).fapply(u).fail(i.reject),i.promise}},h.prototype.nbind=function(){var n=H(arguments,0);return n.unshift(this),l.nbind.apply(void 0,n)},l.nmapply=l.npost=function(n,e,t){return l(n).npost(e,t)},h.prototype.nmapply=h.prototype.npost=function(n,e){var t=H(e||[]),r=p(); return t.push(r.makeNodeResolver()),this.dispatch("post",[n,t]).fail(r.reject),r.promise},l.nsend=l.nmcall=l.ninvoke=function(n,e){var t=H(arguments,2),r=p();return t.push(r.makeNodeResolver()),l(n).dispatch("post",[e,t]).fail(r.reject),r.promise},h.prototype.nsend=h.prototype.nmcall=h.prototype.ninvoke=function(n){var e=H(arguments,1),t=p();return e.push(t.makeNodeResolver()),this.dispatch("post",[n,e]).fail(t.reject),t.promise},l.nodeify=D,h.prototype.nodeify=function(n){return n?void this.then(function(e){l.nextTick(function(){n(null,e)})},function(e){l.nextTick(function(){n(e)})}):this},l.noConflict=function(){throw new Error("Q.noConflict only works when Q is used as a global")};var sn=a();return l})}).call(this,e("_process"))},{_process:1}],6:[function(n,e,t){!function(n){function e(n){return n}function t(n,e){for(var t=0,r=e.length,u=new Array(r);r>t;++t)u[t]=n[e[t]];return u}function r(n){function e(e,t,r,u){for(;u>r;){var i=r+u>>>1;n(e[i])r;){var i=r+u>>>1;t>>1)+1;--i>0;)r(n,i,u,e);return n}function t(n,e,t){for(var u,i=t-e;--i>0;)u=n[e],n[e]=n[e+i],n[e+i]=u,r(n,1,i,e);return n}function r(e,t,r,u){for(var i,o=e[--u+t],c=n(o);(i=t<<1)<=r&&(r>i&&n(e[u+i])>n(e[u+i+1])&&i++,!(c<=n(e[u+i])));)e[u+t]=e[u+i],t=i;e[u+t]=o}return e.sort=t,e}function i(n){function e(e,r,u,i){var o,c,f,a,s=new Array(i=Math.min(u-r,i));for(c=0;i>c;++c)s[c]=e[r++];if(t(s,0,i),u>r){o=n(s[0]);do(f=n(a=e[r])>o)&&(s[0]=a,o=n(t(s,0,i)[0]));while(++ru;++u){for(var i=u,o=e[u],c=n(o);i>t&&n(e[i-1])>c;--i)e[i]=e[i-1];e[i]=o}return e}return e}function c(n){function e(n,e,u){return($>u-e?r:t)(n,e,u)}function t(t,r,u){var i,o=(u-r)/6|0,c=r+o,f=u-1-o,a=r+u-1>>1,s=a-o,l=a+o,p=t[c],d=n(p),v=t[s],h=n(v),m=t[a],y=n(m),g=t[l],x=n(g),b=t[f],k=n(b);d>h&&(i=p,p=v,v=i,i=d,d=h,h=i),x>k&&(i=g,g=b,b=i,i=x,x=k,k=i),d>y&&(i=p,p=m,m=i,i=d,d=y,y=i),h>y&&(i=v,v=m,m=i,i=h,h=y,y=i),d>x&&(i=p,p=g,g=i,i=d,d=x,x=i),y>x&&(i=m,m=g,g=i,i=y,y=x,x=i),h>k&&(i=v,v=b,b=i,i=h,h=k,k=i),h>y&&(i=v,v=m,m=i,i=h,h=y,y=i),x>k&&(i=g,g=b,b=i,i=x,x=k,k=i);var w=v,A=h,j=g,O=x;t[c]=p,t[s]=t[r],t[a]=m,t[l]=t[u-1],t[f]=b;var E=r+1,L=u-2,S=O>=A&&A>=O;if(S)for(var R=E;L>=R;++R){var $=t[R],q=n($);if(A>q)R!==E&&(t[R]=t[E],t[E]=$),++E;else if(q>A)for(;;){var I=n(t[L]);{if(!(I>A)){if(A>I){t[R]=t[E],t[E++]=t[L],t[L--]=$;break}t[R]=t[L],t[L--]=$;break}L--}}}else for(var R=E;L>=R;R++){var $=t[R],q=n($);if(A>q)R!==E&&(t[R]=t[E],t[E]=$),++E;else if(q>O)for(;;){var I=n(t[L]);{if(!(I>O)){A>I?(t[R]=t[E],t[E++]=t[L],t[L--]=$):(t[R]=t[L],t[L--]=$);break}if(L--,R>L)break}}}if(t[r]=t[E-1],t[E-1]=w,t[u-1]=t[L+1],t[L+1]=j,e(t,r,E-1),e(t,L+2,u),S)return t;if(c>E&&L>f){for(var T,I;(T=n(t[E]))<=A&&T>=A;)++E;for(;(I=n(t[L]))<=O&&I>=O;)--L;for(var R=E;L>=R;R++){var $=t[R],q=n($);if(A>=q&&q>=A)R!==E&&(t[R]=t[E],t[E]=$),E++;else if(O>=q&&q>=O)for(;;){var I=n(t[L]);{if(!(O>=I&&I>=O)){A>I?(t[R]=t[E],t[E++]=t[L],t[L--]=$):(t[R]=t[L],t[L--]=$);break}if(L--,R>L)break}}}}return e(t,E,L+1)}var r=o(n);return e}function f(n){for(var e=new Array(n),t=-1;++tt;)n[t++]=0;return n}function s(n,e){if(e>32)throw new Error("invalid array width!");return n}function l(n){this.length=n,this.subarrays=1,this.width=8,this.masks={0:0},this[0]=q(n)}function p(n,e){return function(t){var r=t.length;return[n.left(t,e,0,r),n.right(t,e,0,r)]}}function d(n,e){var t=e[0],r=e[1];return function(e){var u=e.length;return[n.left(e,t,0,u),n.left(e,r,0,u)]}}function v(n){return[0,n.length]}function h(){return null}function m(){return 0}function y(n){return n+1}function g(n){return n-1}function x(n){return function(e,t){return e+ +n(t)}}function b(n){return function(e,t){return e-n(t)}}function k(){function n(n){var e=S,t=n.length;return t&&(L=L.concat(n),k.lengthen(S+=t),$.forEach(function(r){r(n,e,t)})),E}function r(){for(var n=w(S,S),e=[],t=0,r=0;S>t;++t)k.zero(t)?e.push(t):n[t]=r++;R.forEach(function(n){n(-1,-1,[],e,!0)}),q.forEach(function(e){e(n)});for(var t=0,r=0;S>t;++t)k.zero(t)||(t!==r&&(k.copy(r,t),L[r]=L[t]),++r);L.length=S=r,k.truncate(r)}function o(n){function r(e,r,u){Q=e.map(n),Y=X(A(u),0,u),Q=t(Q,Y);var i,o=W(Q),c=o[0],f=o[1];if(G)for(i=0;u>i;++i)G(Q[i],i)||(k[V][Y[i]+r]|=B);else{for(i=0;c>i;++i)k[V][Y[i]+r]|=B;for(i=f;u>i;++i)k[V][Y[i]+r]|=B}if(!r)return _=Q,J=Y,en=c,void(tn=f);var a=_,s=J,l=0,p=0;for(_=new Array(S),J=w(S,S),i=0;r>l&&u>p;++i)a[l]l;++l,++i)_[i]=a[l],J[i]=s[l];for(;u>p;++p,++i)_[i]=Q[p],J[i]=Y[p]+r;o=W(_),en=o[0],tn=o[1]}function o(n,e,t){Z.forEach(function(n){n(Q,Y,e,t)}),Q=Y=null}function f(n){for(var e,t=0,r=0;S>t;++t)k.zero(e=J[t])||(t!==r&&(_[r]=_[t]),J[r]=n[e],++r);for(_.length=r;S>r;)J[r++]=0;var u=W(_);en=u[0],tn=u[1]}function a(n){var e=n[0],t=n[1];if(G)return G=null,C(function(n,r){return r>=e&&t>r}),en=e,tn=t,H;var r,u,i,o=[],c=[];if(en>e)for(r=e,u=Math.min(en,t);u>r;++r)k[V][i=J[r]]^=B,o.push(i);else if(e>en)for(r=en,u=Math.min(e,tn);u>r;++r)k[V][i=J[r]]^=B,c.push(i);if(t>tn)for(r=Math.max(e,tn),u=t;u>r;++r)k[V][i=J[r]]^=B,o.push(i);else if(tn>t)for(r=Math.max(en,t),u=tn;u>r;++r)k[V][i=J[r]]^=B,c.push(i);return en=e,tn=t,R.forEach(function(n){n(B,V,o,c)}),H}function s(n){return null==n?I():Array.isArray(n)?E(n):"function"==typeof n?T(n):l(n)}function l(n){return a((W=p(O,n))(_))}function E(n){return a((W=d(O,n))(_))}function I(){return a((W=v)(_))}function T(n){return W=v,C(G=n),en=0,tn=S,H}function C(n){var e,t,r,u=[],i=[];for(e=0;S>e;++e)!(k[V][t=J[e]]&B)^!!(r=n(_[e],e))&&(r?(k[V][t]&=K,u.push(t)):(k[V][t]|=B,i.push(t)));R.forEach(function(n){n(B,V,u,i)})}function P(n){for(var e,t=[],r=tn;--r>=en&&n>0;)k.zero(e=J[r])&&(t.push(L[e]),--n);return t}function F(n){for(var e,t=[],r=en;tn>r&&n>0;)k.zero(e=J[r])&&(t.push(L[e]),--n),r++;return t}function M(n){function t(e,t,r,u){function i(){++G===Y&&(g=N(g,Q<<=1),C=N(C,Q),Y=j(Q))}var s,l,p,d,v,m,y=T,g=w(G,Y),x=M,b=U,A=D,O=G,E=0,$=0;for(W&&(x=A=h),W&&(b=A=h),T=new Array(G),G=0,C=O>1?z(C,S):w(S,Y),O&&(p=(l=y[0]).key);u>$&&!((d=n(e[$]))>=d);)++$;for(;u>$;){for(l&&d>=p?(v=l,m=p,g[E]=G,(l=y[++E])&&(p=l.key)):(v={key:d,value:A()},m=d),T[G]=v;!(d>m||(C[s=t[$]+r]=G,v.value=x(v.value,L[s],!0),k.zeroExcept(s,V,K)||(v.value=b(v.value,L[s],!1)),++$>=u));)d=n(e[$]);i()}for(;O>E;)T[g[E]=G]=y[E++],i();if(G>E)for(E=0;r>E;++E)C[E]=g[C[E]];s=R.indexOf(H),G>1?(H=o,X=f):(!G&&en&&(G=1,T=[{key:null,value:A()}]),1===G?(H=c,X=a):(H=h,X=h),C=null),R[s]=H}function r(){if(G>1){for(var n=G,e=T,t=w(n,n),r=0,u=0;S>r;++r)k.zero(r)||(t[C[u]=C[r]]=1,++u);for(T=[],G=0,r=0;n>r;++r)t[r]&&(t[r]=G++,T.push(e[r]));if(G>1)for(var r=0;u>r;++r)C[r]=t[C[r]];else C=null;R[R.indexOf(H)]=G>1?(X=f,H=o):1===G?(X=a,H=c):X=H=h}else if(1===G){if(en)return;for(var r=0;S>r;++r)if(!k.zero(r))return;T=[],G=0,R[R.indexOf(H)]=H=X=h}}function o(n,e,t,r,u){if(!(n===B&&e===V||W)){var i,o,c,f;for(i=0,c=t.length;c>i;++i)k.zeroExcept(o=t[i],V,K)&&(f=T[C[o]],f.value=M(f.value,L[o]));for(i=0,c=r.length;c>i;++i)k.onlyExcept(o=r[i],V,K,e,n)&&(f=T[C[o]],f.value=U(f.value,L[o],u))}}function c(n,e,t,r,u){if(!(n===B&&e===V||W)){var i,o,c,f=T[0];for(i=0,c=t.length;c>i;++i)k.zeroExcept(o=t[i],V,K)&&(f.value=M(f.value,L[o]));for(i=0,c=r.length;c>i;++i)k.onlyExcept(o=r[i],V,K,e,n)&&(f.value=U(f.value,L[o],u))}}function f(){var n,e;for(n=0;G>n;++n)T[n].value=D();for(n=0;S>n;++n)e=T[C[n]],e.value=M(e.value,L[n],!0);for(n=0;S>n;++n)k.zeroExcept(n,V,K)||(e=T[C[n]],e.value=U(e.value,L[n],!1))}function a(){var n,e=T[0];for(e.value=D(),n=0;S>n;++n)e.value=M(e.value,L[n],!0);for(n=0;S>n;++n)k.zeroExcept(n,V,K)||(e.value=U(e.value,L[n],!1))}function s(){return W&&(X(),W=!1),T}function l(n){var e=P(s(),0,T.length,n);return F.sort(e,0,e.length)}function p(n,e,t){return M=n,U=e,D=t,W=!0,I}function d(){return p(y,g,m)}function v(n){return p(x(n),b(n),m)}function A(n){function e(e){return n(e.value)}return P=i(e),F=u(e),I}function O(){return A(e)}function E(){return G}function $(){var n=R.indexOf(H);return n>=0&&R.splice(n,1),n=Z.indexOf(t),n>=0&&Z.splice(n,1),n=q.indexOf(r),n>=0&&q.splice(n,1),I}var I={top:l,all:s,reduce:p,reduceCount:d,reduceSum:v,order:A,orderNatural:O,size:E,dispose:$,remove:$};nn.push(I);var T,C,P,F,M,U,D,Q=8,Y=j(Q),G=0,H=h,X=h,W=!0,en=n===h;return arguments.length<1&&(n=e),R.push(H),Z.push(t),q.push(r),t(_,J,0,S),d().orderNatural()}function U(){var n=M(h),e=n.all;return delete n.all,delete n.top,delete n.order,delete n.orderNatural,delete n.size,n.value=function(){return e()[0].value},n}function D(){nn.forEach(function(n){n.dispose()});var n=$.indexOf(r);return n>=0&&$.splice(n,1),n=$.indexOf(o),n>=0&&$.splice(n,1),n=q.indexOf(f),n>=0&&q.splice(n,1),k.masks[V]&=K,I()}var B,K,V,_,J,Q,Y,G,H={filter:s,filterExact:l,filterRange:E,filterFunction:T,filterAll:I,top:P,bottom:F,group:M,groupAll:U,dispose:D,remove:D},X=c(function(n){return Q[n]}),W=v,Z=[],nn=[],en=0,tn=0;$.unshift(r),$.push(o),q.push(f);var rn=k.add();return V=rn.offset,B=rn.one,K=~B,r(L,0,S),o(L,0,S),H}function f(){function n(n,e){var t;if(!d)for(t=e;S>t;++t)f=a(f,L[t],!0),k.zero(t)||(f=s(f,L[t],!1))}function e(n,e,t,r,u){var i,o,c;if(!d){for(i=0,c=t.length;c>i;++i)k.zero(o=t[i])&&(f=a(f,L[o],u));for(i=0,c=r.length;c>i;++i)k.only(o=r[i],e,n)&&(f=s(f,L[o],u))}}function t(){var n;for(f=l(),n=0;S>n;++n)f=a(f,L[n],!0),k.zero(n)||(f=s(f,L[n],!1))}function r(n,e,t){return a=n,s=e,l=t,d=!0,p}function u(){return r(y,g,m)}function i(n){return r(x(n),b(n),m)}function o(){return d&&(t(),d=!1),f}function c(){var t=R.indexOf(e);return t>=0&&R.splice(t),t=$.indexOf(n),t>=0&&$.splice(t),p}var f,a,s,l,p={reduce:r,reduceCount:u,reduceSum:i,value:o,dispose:c,remove:c},d=!0;return R.push(e),$.push(n),n(L,0,S),u()}function a(){return S}function s(){return L}var k,E={add:n,remove:r,dimension:o,groupAll:f,size:a,all:s},L=[],S=0,R=[],$=[],q=[];return k=new l(0),arguments.length?n(arguments[0]):E}function w(n,e){return(257>e?q:65537>e?I:T)(n)}function A(n){for(var e=w(n,n),t=-1;++t=e)return n;var t=new n.constructor(e);return t.set(n),t},N=function(n,e){var t;switch(e){case 16:t=I(n.length);break;case 32:t=T(n.length);break;default:throw new Error("invalid array width!")}return t.set(n),t}),l.prototype.lengthen=function(n){var e,t;for(e=0,t=this.subarrays;t>e;++e)this[e]=z(this[e],n);this.length=n},l.prototype.add=function(){var n,e,t,r,u;for(r=0,u=this.subarrays;u>r;++r)if(n=this.masks[r],e=this.width-32*r,t=~n&-~n,!(e>=32)||t)return 32>e&&t&1<t;++t)this[t][n]=this[t][e]},l.prototype.truncate=function(n){var e,t;for(e=0,t=this.subarrays;t>e;++e){for(var r=this.length-1;r>=n;r--)this[e][r]=0;this[e].length=n}this.length=n},l.prototype.zero=function(n){var e,t;for(e=0,t=this.subarrays;t>e;++e)if(this[e][n])return!1;return!0},l.prototype.zeroExcept=function(n,e,t){var r,u;for(r=0,u=this.subarrays;u>r;++r)if(r===e?this[r][n]&t:this[r][n])return!1;return!0},l.prototype.only=function(n,e,t){var r,u;for(r=0,u=this.subarrays;u>r;++r)if(this[r][n]!=(r===e?t:0))return!1;return!0},l.prototype.onlyExcept=function(n,e,t,r,u){var i,o,c;for(o=0,c=this.subarrays;c>o;++o)if(i=this[o][n],o===e&&(i&=t),i!=(o===r?u:0))return!1;return!0},n.crossfilter=k}("undefined"!=typeof t&&t||this)},{}],7:[function(n,e,t){arguments[4][3][0].apply(t,arguments)},{"./crossfilter":6,dup:3}],8:[function(n,e,t){function r(n,e){function t(n){if("string"==typeof n){var e=n,t=function(n){return n[e]};return t}return n}function i(n){if("string"==typeof n){var e=n,t=function(n){return+n[e]};return t}return n}n.count=function(t){return arguments.length?(e.count=t,n):e.count},n.sum=function(t){return arguments.length?(t=i(t),e.sum=t,n):e.sum},n.avg=function(t){return arguments.length?(t=i(t),"function"==typeof t?(e.sum&&console.warn("SUM aggregation is being overwritten by AVG aggregation"),e.sum=t,e.avg=!0,e.count=!0):e.avg=t,n):e.avg},n.exception=function(r){return arguments.length?(r=t(r),e.exceptionAccessor=r,n):e.exceptionAccessor},n.filter=function(t){return arguments.length?(e.filter=t,n):e.filter},n.valueList=function(r){return arguments.length?(r=t(r),e.valueList=r,n):e.valueList},n.median=function(t){return arguments.length?(t=i(t),"function"==typeof t&&(e.valueList&&console.warn("VALUELIST accessor is being overwritten by median aggregation"),e.valueList=t),e.median=t,n):e.median},n.min=function(t){return arguments.length?(t=i(t),"function"==typeof t&&(e.valueList&&console.warn("VALUELIST accessor is being overwritten by median aggregation"),e.valueList=t),e.min=t,n):e.min},n.max=function(t){return arguments.length?(t=i(t),"function"==typeof t&&(e.valueList&&console.warn("VALUELIST accessor is being overwritten by median aggregation"),e.valueList=t),e.max=t,n):e.max},n.exceptionCount=function(r){return arguments.length?(r=t(r),"function"==typeof r?(e.sum&&console.warn("EXCEPTION accessor is being overwritten by exception count aggregation"),e.exceptionAccessor=r,e.exceptionCount=!0):e.exceptionCount=r,n):e.exceptionCount},n.exceptionSum=function(t){return arguments.length?(t=i(t),e.exceptionSum=t,n):e.exceptionSum},n.histogramValue=function(t){return arguments.length?(t=i(t),e.histogramValue=t,n):e.histogramValue},n.histogramBins=function(t){return arguments.length?(e.histogramThresholds=t,n):e.histogramThresholds},n.std=function(t){return arguments.length?(t=i(t),"function"==typeof t?(e.sumOfSquares=t,e.sum=t,e.count=!0,e.std=!0):e.std=t,n):e.std},n.sumOfSq=function(t){return arguments.length?(t=i(t),e.sumOfSquares=t,n):e.sumOfSquares},n.value=function(n,t){return arguments.length&&"string"==typeof n?(e.values||(e.values={}),e.values[n]={},e.values[n].parameters=u(),r(e.values[n],e.values[n].parameters),t&&(e.values[n].accessor=t),e.values[n]):void console.error("'value' requires a string argument.")},n.nest=function(r){return arguments.length?(r.map(t),e.nestKeys=r,n):e.nestKeys},n.alias=function(t){return arguments.length?(e.aliasKeys=t,n):e.aliasKeys},n.aliasProp=function(t){return arguments.length?(e.aliasPropKeys=t,n):e.aliasPropKeys},n.groupAll=function(t){return arguments.length?(e.groupAll=t,n):e.groupAll},n.dataList=function(t){return arguments.length?(e.dataList=t,n):e.dataList}}var u=n("./parameters.js"),i={build:r};e.exports=i},{"./parameters.js":24}],9:[function(n,e,t){var r={initial:function(n,e,t){return function(r){n&&(r=n(r));for(var u in t)e(r)[u]=function(){return t[u](e(r))};return r}}};e.exports=r},{}],10:[function(n,e,t){var r={add:function(n,e,t){return function(r,u,i){e&&e(r,u,i);for(var o in n)t(r)[o]=n[o](t(r),u);return r}}};e.exports=r},{}],11:[function(n,e,t){var r={add:function(n,e,t){return function(n,r,u){return e&&e(n,r,u),t(n).count>0?t(n).avg=t(n).sum/t(n).count:t(n).avg=0,n}},remove:function(n,e,t){return function(n,r,u){return e&&e(n,r,u),t(n).count>0?t(n).avg=t(n).sum/t(n).count:t(n).avg=0,n}},initial:function(n,e){return function(t){return t=n(t),e(t).avg=0,t}}};e.exports=r},{}],12:[function(n,e,t){function r(n,e,t){t||(t=function(n){return n});var w={reduceAdd:e.reduceAdd,reduceRemove:e.reduceRemove,reduceInitial:e.reduceInitial};(n.count||n.std)&&(e.reduceAdd=i.add(e.reduceAdd,t),e.reduceRemove=i.remove(e.reduceRemove,t),e.reduceInitial=i.initial(e.reduceInitial,t)),n.sum&&(e.reduceAdd=o.add(n.sum,e.reduceAdd,t),e.reduceRemove=o.remove(n.sum,e.reduceRemove,t),e.reduceInitial=o.initial(e.reduceInitial,t)),n.avg&&(n.count&&n.sum?(e.reduceAdd=c.add(n.sum,e.reduceAdd,t),e.reduceRemove=c.remove(n.sum,e.reduceRemove,t),e.reduceInitial=c.initial(e.reduceInitial,t)):console.error("You must set .count(true) and define a .sum(accessor) to use .avg(true).")),n.exceptionCount&&(n.exceptionAccessor?(e.reduceAdd=d.add(n.exceptionAccessor,e.reduceAdd,t),e.reduceRemove=d.remove(n.exceptionAccessor,e.reduceRemove,t),e.reduceInitial=d.initial(e.reduceInitial,t)):console.error("You must define an .exception(accessor) to use .exceptionCount(true).")),n.exceptionSum&&(n.exceptionAccessor?(e.reduceAdd=v.add(n.exceptionAccessor,n.exceptionSum,e.reduceAdd,t),e.reduceRemove=v.remove(n.exceptionAccessor,n.exceptionSum,e.reduceRemove,t),e.reduceInitial=v.initial(e.reduceInitial,t)):console.error("You must define an .exception(accessor) to use .exceptionSum(accessor).")),(n.valueList||n.median||n.min||n.max)&&(e.reduceAdd=p.add(n.valueList,e.reduceAdd,t),e.reduceRemove=p.remove(n.valueList,e.reduceRemove,t),e.reduceInitial=p.initial(e.reduceInitial,t)),n.dataList&&(e.reduceAdd=k.add(n.dataList,e.reduceAdd,t),e.reduceRemove=k.remove(n.dataList,e.reduceRemove,t),e.reduceInitial=k.initial(e.reduceInitial,t)),n.median&&(e.reduceAdd=f.add(e.reduceAdd,t),e.reduceRemove=f.remove(e.reduceRemove,t),e.reduceInitial=f.initial(e.reduceInitial,t)),n.min&&(e.reduceAdd=a.add(e.reduceAdd,t),e.reduceRemove=a.remove(e.reduceRemove,t),e.reduceInitial=a.initial(e.reduceInitial,t)),n.max&&(e.reduceAdd=s.add(e.reduceAdd,t),e.reduceRemove=s.remove(e.reduceRemove,t),e.reduceInitial=s.initial(e.reduceInitial,t)),n.exceptionAccessor&&(e.reduceAdd=l.add(n.exceptionAccessor,e.reduceAdd,t),e.reduceRemove=l.remove(n.exceptionAccessor,e.reduceRemove,t),e.reduceInitial=l.initial(e.reduceInitial,t)),n.histogramValue&&n.histogramThresholds&&(e.reduceAdd=h.add(n.histogramValue,e.reduceAdd,t),e.reduceRemove=h.remove(n.histogramValue,e.reduceRemove,t),e.reduceInitial=h.initial(n.histogramThresholds,e.reduceInitial,t)),n.sumOfSquares&&(e.reduceAdd=m.add(n.sumOfSquares,e.reduceAdd,t),e.reduceRemove=m.remove(n.sumOfSquares,e.reduceRemove,t),e.reduceInitial=m.initial(e.reduceInitial,t)),n.std&&(n.sumOfSquares&&n.sum?(e.reduceAdd=y.add(e.reduceAdd,t),e.reduceRemove=y.remove(e.reduceRemove,t),e.reduceInitial=y.initial(e.reduceInitial,t)):console.error("You must set .sumOfSq(accessor) and define a .sum(accessor) to use .std(true). Or use .std(accessor).")),n.nestKeys&&(e.reduceAdd=g.add(n.nestKeys,e.reduceAdd,t),e.reduceRemove=g.remove(n.nestKeys,e.reduceRemove,t),e.reduceInitial=g.initial(e.reduceInitial,t)),n.aliasKeys&&(e.reduceInitial=x.initial(e.reduceInitial,t,n.aliasKeys)),n.aliasPropKeys&&(e.reduceAdd=b.add(n.aliasPropKeys,e.reduceAdd,t),e.reduceRemove=b.add(n.aliasPropKeys,e.reduceRemove,t)),n.filter&&(e.reduceAdd=u.add(n.filter,e.reduceAdd,w.reduceAdd,t),e.reduceRemove=u.remove(n.filter,e.reduceRemove,w.reduceRemove,t)),n.values&&Object.getOwnPropertyNames(n.values).forEach(function(u){var i=function(n){return function(e){return e=n(e),t(e)[u]={},e}};e.reduceInitial=i(e.reduceInitial),r(n.values[u].parameters,e,function(n){return n[u]})})}var u=n("./filter.js"),i=n("./count.js"),o=n("./sum.js"),c=n("./avg.js"),f=n("./median.js"),a=n("./min.js"),s=n("./max.js"),l=n("./value-count.js"),p=n("./value-list.js"),d=n("./exception-count.js"),v=n("./exception-sum.js"),h=n("./histogram.js"),m=n("./sum-of-squares.js"),y=n("./std.js"),g=n("./nest.js"),x=n("./alias.js"),b=n("./aliasProp.js"),k=n("./data-list.js"),w={build:r};e.exports=w},{"./alias.js":9,"./aliasProp.js":10,"./avg.js":11,"./count.js":14,"./data-list.js":15,"./exception-count.js":16,"./exception-sum.js":17,"./filter.js":18,"./histogram.js":19,"./max.js":20,"./median.js":21,"./min.js":22,"./nest.js":23,"./std.js":29,"./sum-of-squares.js":30,"./sum.js":31,"./value-count.js":32,"./value-list.js":33}],13:[function(n,e,t){var r=function(n){return function(e){return e[n]}};_grouper=function(n,e){return n||(n=function(n){return n}),function(t,r){e&&e(t,r);var u=n(t),i=n(r);return"undefined"!=typeof i.count&&(u.count+=i.count),"undefined"!=typeof i.sum&&(u.sum+=i.sum),"undefined"!=typeof i.avg&&(u.avg=u.sum/u.count),t}},reductio_cap=function(n,e,t){var u=(e.reduceInitial(),t.values?Object.keys(t.values):[]),i=_grouper();if(u.length)for(var o=0;oi;i++)s=o[i],r=l(n,s,0,n.length),n[r]&&n[r].key===s||n.splice(r,0,{key:s,value:t.reduceInitial()}),t.reduceAdd(n[r].value,u,c);return n},function(n,u,c){for(o=e.groupAll(u),a=o.length,i=0;a>i;i++)r=l(n,o[i],0,n.length),t.reduceRemove(n[r].value,u,c);return n},function(){return[]}),n.all||(n.all=function(){return this.value()})}else n.reduce(t.reduceAdd,t.reduceRemove,t.reduceInitial);return c(n,e,t),n}var e=o(),t={};return i.build(n,e),n}var u=n("./build.js"),i=n("./accessors.js"),o=n("./parameters.js"),c=n("./postprocess"),f=n("crossfilter");n("./postprocessors")(r),c=c(r),e.exports=r},{"./accessors.js":8,"./build.js":12,"./parameters.js":24,"./postprocess":25,"./postprocessors":26,crossfilter:7}],28:[function(n,e,t){function r(n,e){return e>n?-1:n>e?1:n>=e?0:NaN}var u=function(n){if("function"==typeof n)return n;if(~n.indexOf(".")){var e=n.split(".");return function(n){return e.reduce(function(n,e){return n[e]},n)}}return function(e){return e[n]}},i=function(n,e){return function(t,r){return e(n(t),n(r))}};({}).toString;e.exports=function(n){return function(e,t){return 1===arguments.length&&(t=r),n().sort(i(u(e),t))}}},{}],29:[function(n,e,t){var r={add:function(n,e){return function(t,r,u){if(n&&n(t,r,u),e(t).count>0){e(t).std=0;var i=e(t).sumOfSq-e(t).sum*e(t).sum/e(t).count;i>0&&(e(t).std=Math.sqrt(i/(e(t).count-1)))}else e(t).std=0;return t}},remove:function(n,e){return function(t,r,u){if(n&&n(t,r,u),e(t).count>0){e(t).std=0;var i=e(t).sumOfSq-e(t).sum*e(t).sum/e(t).count;i>0&&(e(t).std=Math.sqrt(i/(e(t).count-1)))}else e(t).std=0;return t}},initial:function(n,e){return function(t){return t=n(t),e(t).std=0,t}}};e.exports=r},{}],30:[function(n,e,t){var r={add:function(n,e,t){return function(r,u,i){return e&&e(r,u,i),t(r).sumOfSq=t(r).sumOfSq+n(u)*n(u),r}},remove:function(n,e,t){return function(r,u,i){return e&&e(r,u,i),t(r).sumOfSq=t(r).sumOfSq-n(u)*n(u),r}},initial:function(n,e){return function(t){return t=n(t),e(t).sumOfSq=0,t}}};e.exports=r},{}],31:[function(n,e,t){var r={add:function(n,e,t){return function(r,u,i){return e&&e(r,u,i),t(r).sum=t(r).sum+n(u),r}},remove:function(n,e,t){return function(r,u,i){return e&&e(r,u,i),t(r).sum=t(r).sum-n(u),r}},initial:function(n,e){return function(t){return t=n(t),e(t).sum=0,t}}};e.exports=r},{}],32:[function(n,e,t){var r=n("crossfilter"),u={add:function(n,e,t){var r,u;return function(i,o,c){return e&&e(i,o,c),r=t(i).bisect(t(i).values,n(o),0,t(i).values.length),u=t(i).values[r],u&&u[0]===n(o)?u[1]++:t(i).values.splice(r,0,[n(o),1]),i}},remove:function(n,e,t){var r;return function(u,i,o){return e&&e(u,i,o),r=t(u).bisect(t(u).values,n(i),0,t(u).values.length),t(u).values[r][1]--,u}},initial:function(n,e){return function(t){return t=n(t),e(t).values=[],e(t).bisect=r.bisect.by(function(n){return n[0]}).left,t}}};e.exports=u},{crossfilter:7}],33:[function(n,e,t){var r=n("crossfilter"),u={add:function(n,e,t){var u,i=r.bisect.by(function(n){return n}).left;return function(r,o,c){return e&&e(r,o,c),u=i(t(r).valueList,n(o),0,t(r).valueList.length),t(r).valueList.splice(u,0,n(o)),r}},remove:function(n,e,t){var u,i=r.bisect.by(function(n){return n}).left;return function(r,o,c){return e&&e(r,o,c),u=i(t(r).valueList,n(o),0,t(r).valueList.length),t(r).valueList.splice(u,1),r}},initial:function(n,e){return function(t){return t=n(t),e(t).valueList=[],t}}};e.exports=u},{crossfilter:7}],34:[function(n,e,t){"use strict";function r(n){var e=u(n).reverse();return function(n){return e.reduce(function(n,e){return e(n)},n)}}function u(n){var e=x.isObject(n)?i(n):n;if(x.isString(n))return function(e){return e[n]};if(x.isArray(n)){var t=x.map(n,u);return function(n){return t.map(function(e){return e(n)})}}if(e.key){if(k[e.key])return[k[e.key],u(e.value)];console.error("Could not find aggregration method",e)}return[]}function i(n){for(var e in n)if(n.hasOwnProperty(e))return{key:e,value:n[e]}}function o(n){var e=[],t=n.indexOf("("),r=n.indexOf(")"),u=t>-1?n.substring(0,t):n;return k[u]?(t>-1&&r>-1&&r>t&&(e=n.substring(t+1,r).split(",")),{aggregator:k[u],params:e}):!1}function c(n){return n.reduce(function(n,e){return n+e})}function f(n){return n.reduce(function(n,e){return n+e})/n.length}function a(n){return Math.max.apply(null,n)}function s(n){return Math.min.apply(null,n)}function l(n){return n.length}function p(n){return n[0]}function d(n){return n[n.length-1]}function v(n,e){return n[e]}function h(n,e){return n[n.length-e]}function m(n,e){return n[Math.round(n.length*(e/100))]}function y(n,e){return n.map(function(n){return n[e]})}function g(n,e){return x.isString(e)&&n.sort(function(n,t){return n[e]t[e]?1:0}),x.isNumber(e)&&n.sort(function(n,t){return n[e]-t[e]}),Array.prototype.slice.call(n).sort(b)}var x=n("./lodash"),b=n("javascript-natural-sort"),k={$sum:c,$avg:f,$max:a,$min:s,$count:l,$first:p,$last:d,$get:v,$nth:v,$nthLast:h,$nthPct:m,$map:y,$sort:g};e.exports={makeFunction:r,aggregators:k,parseAggregatorParams:o}},{"./lodash":41,"javascript-natural-sort":4}],35:[function(n,e,t){"use strict";var r=n("q"),u=n("./lodash");e.exports=function(n){return function(e){function t(e){var t=[];e.removeListeners&&(t=u.map(e.removeListeners,function(n){ -return r.resolve(n())}));var i=e.complex?JSON.stringify(e.key):e.key;return delete n.filters[i],e.dimension&&t.push(r.resolve(e.dimension.dispose())),r.all(t)}return e&&(e=u.isArray(e)?e:[e]),e?r.all(u.map(e,function(e){u.isObject(e)&&(e=e.key);var r=u.remove(n.columns,function(n){return u.isArray(e)?!u.xor(n.key,e).length:n.key===e?!n.dynamicReference:void 0})[0];r&&t(r)})).then(function(){return n}):r.all(u.map(n.columns,t)).then(function(){return n.columns=[],n})}}},{"./lodash":41,q:5}],36:[function(n,e,t){"use strict";var r=n("q"),u=n("./lodash");e.exports=function(e){function t(n){return u.isUndefined(n)&&(n=!0),u.isArray(n)||(n=[n]),r.all(u.map(n,c)).then(function(n){return e})}function i(n){return u.find(e.columns,function(e){return u.isArray(n)?!u.xor(e.key,n).length:e.key===n})}function o(n){return u.isNumber(n)?"number":u.isBoolean(n)?"bool":u.isArray(n)?"array":u.isObject(n)?"object":"string"}function c(n){var t=u.isObject(n)?n:{key:n},c=i(t.key);return c?(c=c,c.temporary=!1,c.dynamicReference&&(c.dynamicReference=!1),c.promise.then(function(){return e})):(e.columns.push(t),t.promise=r["try"](function(){return r.resolve(e.cf.all())}).then(function(n){var e;if(u.isArray(t.key)){if(t.complex=!0,e=u.values(u.pick(n[0],t.key)),e.length!==t.key.length)throw new Error("Column key does not exist in data!",t.key)}else e=n[0][t.key];if(!t.complex&&t.key!==!0&&"undefined"==typeof e)throw new Error("Column key does not exist in data!",t.key);return t.type=t.key===!0?"all":t.complex?"complex":t.array?"array":o(e),f.make(t.key,t.type)}).then(function(n){function i(n){return t.key===!0?r.resolve():r.resolve(t.dimension.bottom(1/0)).then(function(n){var e=f.makeAccessor(t.key);"complex"===t.type?t.values=u.uniq(u.flatten(u.map(n,e))):"array"===t.type?t.values=u.uniq(u.flatten(u.map(n,e))):t.values=u.uniq(u.map(n,e))})}t.dimension=n,t.filterCount=0;var o=e.onDataChange(i);return t.removeListeners=[o],i()}),t.promise.then(function(){return e}))}var f=n("./dimension")(e),a=t;return a.find=i,a}},{"./dimension":38,"./lodash":41,q:5}],37:[function(n,e,t){"use strict";var r=n("q"),u=n("crossfilter2"),i=n("./lodash");e.exports=function(n){function e(n){return i.isArray(n)?r.resolve(u(n)):n&&"function"==typeof n.dimension?r.resolve(n):r.reject(new Error("No Crossfilter data or instance found!"))}function t(e){return n.options.generatedColumns?i.map(e,function(e,t){return i.forEach(n.options.generatedColumns,function(n,t){e[t]=n(e)}),e}):e}function o(e){return e=t(e),r["try"](function(){return r.resolve(n.cf.add(e))}).then(function(){return r.serial(i.map(n.dataListeners,function(n){return function(){return n(!0)}}))}).then(function(){return n})}function c(){return r["try"](function(){return r.resolve(n.cf.remove())}).then(function(){return n})}return{build:e,generateColumns:t,add:o,remove:c}}},{"./lodash":41,crossfilter2:3,q:5}],38:[function(n,e,t){"use strict";var r=n("q"),u=n("./lodash");e.exports=function(n){function e(e,u){var i=t(e);return r.resolve(n.cf.dimension(i,"array"==u))}function t(n){var e;if(u.isArray(n)){var t=u.map(n,function(n){return"d['"+n+"']"});e=new Function("d","return "+JSON.stringify(t).replace(/\"/g,""))}else e=n===!0?function(n,e){return e}:function(e){return e[n]};return e}return{make:e,makeAccessor:t}}},{"./lodash":41,q:5}],39:[function(n,e,t){"use strict";function r(n,e){return n[e]}function u(n,e){e=e(n);for(var t=0;te()}function a(n,e){return n>=e()}function s(n,e){return n-1}function h(n,e){return-1===n.indexOf(e())}function m(n,e){return e().indexOf(n)>-1}function y(n,e){return-1===e().indexOf(n)}function g(n,e){return n.length===e()}e.exports={$field:r,$and:u,$or:i,$not:o,$eq:c,$gt:f,$gte:a,$lt:s,$lte:l,$ne:p,$type:d,$in:v,$nin:h,$contains:m,$excludes:y,$size:g}},{}],40:[function(n,e,t){"use strict";var r=n("q"),u=n("./lodash"),i=n("./expressions"),o=n("./aggregation");e.exports=function(n){function e(e,t,i,o){var a=n.column.find(e);return r["try"](function(){return a?a:n.column({key:e,temporary:!0}).then(function(){return n.column.find(e)})}).then(function(e){var r=u.clone(n.filters,!0),a=e.complex?JSON.stringify(e.key):e.key;return r[a]=c(t,i,o),f(r)})}function t(){return f({})}function c(n,e,t){return u.isUndefined(n)?!1:u.isFunction(n)?{value:n,"function":n,replace:!0,type:"function"}:u.isObject(n)?{value:n,"function":p(n),replace:!0,type:"function"}:u.isArray(n)?{value:n,replace:e||t,type:e?"range":"inclusive"}:{value:n,replace:t,type:"exact"}}function f(e){var t=u.map(e,function(t,i){var o=n.filters[i];if(t.replace&&o&&u.isEqual(t,o))return r.resolve();var c;return c="["===i.charAt(0)?n.column.find(JSON.parse(i)):n.column.find(i),t&&o&&!t.replace&&(e[i]=t=a(t,o)),t?"exact"===t.type?r.resolve(c.dimension.filterExact(t.value)):"range"===t.type?r.resolve(c.dimension.filterRange(t.value)):"inclusive"===t.type?r.resolve(c.dimension.filterFunction(function(n){return t.value.indexOf(n)>-1})):"function"===t.type?r.resolve(c.dimension.filterFunction(t["function"])):r.resolve(c.dimension.filterAll()):r.resolve(c.dimension.filterAll())});return r.all(t).then(function(){n.filters=e;var t=[];return u.forEach(n.filters,function(e,r){e||(t.push({key:r,val:e}),delete n.filters[r])}),r.all(u.map(t,function(e){var t=n.column.find("["===e.key.charAt(0)?JSON.parse(e.key):e.key);return t.temporary&&!t.dynamicReference?n.clear(t.key):void 0}))}).then(function(){return n})}function a(n,e){if("exact"===n.type&&"inclusive"===e.type)n.value=u.xor([n.value],e.value);else if("inclusive"===n.type&&"exact"===e.type)n.value=u.xor(n.value,[e.value]);else if("inclusive"===n.type&&"inclusive"===e.type)n.value=u.xor(n.value,e.value);else if("exact"===n.type&&"exact"===e.type){if(n.value===e.value)return!1;n.value=[n.value,e.value]}return n.value.length?1===n.value.length?(n.type="exact",n.value=n.value[0]):n.type="inclusive":n=!1,n}function s(n){function e(n){u.forEach(n,function(n,r){var i=l(n,r);i&&t.push(i),u.isString(n)&&(i=l(null,n),i&&t.push(i)),u.isObject(n)&&e(n)})}var t=[];return e(n.filter),t}function l(n,e){return"$data"===e?!0:e&&"$column"===e?u.isString(n)?n:(console.warn('The value for filter "$column" must be a valid column key',n),!1):void 0}function p(e,t){var r;if(u.isString(e)){var c=l(null,e);if(c){var f=n.cf.all();return function(n){return f}}}return u.isString(e)||u.isNumber(e)||u.isBoolean(e)?function(n){return"undefined"==typeof n?e:i.$eq(n,function(){return e})}:u.isArray(e)?(r=u.map(e,function(n){return p(n,t)}),function(n){return r.map(function(e){return e(n)})}):u.isObject(e)?(r=u.map(e,function(e,r){var u=p(e,t),c=l(e,r);if(c){var f=n.column.find(c),a=f.values;return function(n){return a}}if(i[r])return function(n){return i[r](n,u)};var s=o.parseAggregatorParams(r);return s?(t=!0,u=p(e,t),function(n){return s.aggregator.apply(null,[u()].concat(s.params))}):function(n){return n=n[r],u(n,u)}}),t?1===r.length?function(n){return r[0](n)}:function(n){return u.map(r,function(e){return e(n)})}:function(n){return i.$and(n,function(n){return u.map(r,function(e){return e(n)})})}):(console.log("no expression found for ",e),!1)}return{filter:e,filterAll:t,applyFilters:f,makeFunction:p,scanForDynamicFilters:s}}},{"./aggregation":34,"./expressions":39,"./lodash":41,q:5}],41:[function(n,e,t){"use strict";function r(n){n=n||{};for(var e=1;ee.value?1:n.valuer?n.splice(r,t-r):r>t&&n.push.apply(n,new Array(r-t)),h(n,function(t,r){n[r]=e[r]}),n}function w(n){var e=new Set;return n.filter(function(n){var t=!1;return e.has(n)||(e.add(n),t=!0),t})}function A(n){for(var e=[],t=0;tt;)n[r]=n[r-1],--r;n[r]=t}return n}function O(n){var e=[];for(var t in n)n.hasOwnProperty(t)&&e.push(n[t]);return e}n("javascript-natural-sort");e.exports={assign:r,find:u,remove:i,isArray:o,isObject:c,isBoolean:f,isString:a,isNumber:s,isFunction:l,get:p,map:d,sortBy:v,forEach:h,isUndefined:m,pick:y,xor:g,clone:x,isEqual:b,replaceArray:k,uniq:w,flatten:A,sort:j,values:O}},{"javascript-natural-sort":4}],42:[function(n,e,t){"use strict";function r(n){var e,t=new Error;return i.forEach(n,function(n,r){var i,c=n.success||n,f=n.fail,a=n.notify;if(e)i=e.then(function(n){if(!c)return n;var e=c(n);if(!o(e))throw t.message="Task "+r+" did not return a promise.",t;return e},function(n){if(!f)return u.reject(n);var e=f(n);if(!o(e))throw t.message="Fail for task "+r+" did not return a promise.",t;return e},a);else if(i=c(),!o(i))throw t.message="Task "+r+" did not return a promise.",t;e=i}),e||u.when()}var u=n("q"),i=n("./lodash");u.serial=r;var o=function(n){return n&&i.isFunction(n.then)}},{"./lodash":41,q:5}],43:[function(n,e,t){"use strict";var r=n("q"),u=n("./lodash");e.exports=function(e){var t=n("./reductiofy")(e),i=n("./filters")(e);return function(n){"undefined"==typeof n&&(n={}),"undefined"==typeof n.select&&(n.select={$count:!0}),n.groupBy=n.groupBy||!0;var o,c=e.column.find(n.groupBy);return r["try"](function(){return c?c:e.column({key:n.groupBy,type:u.isUndefined(n.type)?null:n.type,array:!!n.array}).then(function(){return e.column.find(n.groupBy)})}).then(function(n){return c=n,r.resolve(c.dimension.group())}).then(function(e){return o=e,i.scanForDynamicFilters(n)}).then(function(n){return n.length?r.all(u.map(n,function(n){return e.column({key:n,dynamicReference:o})})).then(function(){return!0}):!1}).then(function(u){function i(e,u){return t(n).then(function(n){return e.reducer=n,e.reducer(e.group),r.resolve(e.group.all())}).then(function(n){e.data=n})}var f,a={universe:e,crossfilter:e.cf,dimension:c.dimension,group:o,reducer:null};return u&&(f=e.onDataChange(function(n){return i(a,n)}),c.removeListeners.push(f)),i(a).then(function(){return a})})}}},{"./filters":40,"./lodash":41,"./reductiofy":45,q:5}],44:[function(n,e,t){"use strict";function r(n,e){return n.count(!0)}function u(n,e){return n.sum(e)}function i(n,e){return n.avg(e)}function o(n,e){return n.min(e)}function c(n,e){return n.max(e)}function f(n,e){return n.median(e)}function a(n,e){return n.sumOfSq(e)}function s(n,e){return n.std(e)}function l(n,e){return n.valueList(e)}function p(n,e){return n.dataList(e)}n("./lodash");e.exports={shorthandLabels:{$count:"count",$sum:"sum",$avg:"avg",$min:"min",$max:"max",$med:"med",$sumSq:"sumSq",$std:"std"},aggregators:{$count:r,$sum:u,$avg:i,$min:o,$max:c,$med:f,$sumSq:a,$std:s,$valueList:l,$dataList:p}}},{"./lodash":41}],45:[function(n,e,t){"use strict";var r=n("reductio"),u=n("./lodash"),i=n("./reductioAggregators"),o=(n("./expressions"),n("./aggregation"));e.exports=function(e){var t=n("./filters")(e);return function(n){function e(n,t){var r=u.sortBy(u.map(t,function(n,e){return{key:e,value:n}}),function(n){return i.aggregators[n.key]?0:1});return u.forEach(r,function(t){if(i.aggregators[t.key]){var r=c(t.value);return void(n=i.aggregators[t.key](n,r))}return u.isObject(t.value)?void(n=e(n.value(t.key),t.value)):void console.error("Nested selects must be an object",t.key)})}function c(n){return"string"==typeof n||"number"==typeof n?n+"":u.isObject(n)?o.makeFunction(n):void 0}var f=r();n.groupBy;if(e(f,n.select),n.filter){var a=t.makeFunction(n.filter);a&&f.filter(a)}return Promise.resolve(f)}}},{"./aggregation":34,"./expressions":39,"./filters":40,"./lodash":41,"./reductioAggregators":44,reductio:27}],46:[function(n,e,t){"use strict";function r(e,t){function r(n){return i.dataListeners.push(n),function(){i.dataListeners.splice(i.dataListeners.indexOf(n),1)}}var i={options:u.assign({},t),columns:[],filters:{},dataListeners:[]},o=n("./crossfilter")(i);return e=o.generateColumns(e),o.build(e).then(function(e){return i.cf=e,u.assign(i,{add:o.add,remove:o.remove,column:n("./column")(i),query:n("./query")(i),filter:n("./filters")(i).filter,clear:n("./clear")(i),onDataChange:r})})}n("./q.serial");var u=(n("q"),n("./lodash"));e.exports=r},{"./clear":35,"./column":36,"./crossfilter":37,"./filters":40,"./lodash":41,"./q.serial":42,"./query":43,q:5}]},{},[46])(46)}); \ No newline at end of file +return r.resolve(n())}));var i=e.complex?JSON.stringify(e.key):e.key;return delete n.filters[i],e.dimension&&t.push(r.resolve(e.dimension.dispose())),r.all(t)}return e&&(e=u.isArray(e)?e:[e]),e?r.all(u.map(e,function(e){u.isObject(e)&&(e=e.key);var r=u.remove(n.columns,function(n){return u.isArray(e)?!u.xor(n.key,e).length:n.key===e?!n.dynamicReference:void 0})[0];r&&t(r)})).then(function(){return n}):r.all(u.map(n.columns,t)).then(function(){return n.columns=[],n})}}},{"./lodash":41,q:5}],36:[function(n,e,t){"use strict";var r=n("q"),u=n("./lodash");e.exports=function(e){function t(n){return u.isUndefined(n)&&(n=!0),u.isArray(n)||(n=[n]),r.all(u.map(n,c)).then(function(n){return e})}function i(n){return u.find(e.columns,function(e){return u.isArray(n)?!u.xor(e.key,n).length:e.key===n})}function o(n){return u.isNumber(n)?"number":u.isBoolean(n)?"bool":u.isArray(n)?"array":u.isObject(n)?"object":"string"}function c(n){var t=u.isObject(n)?n:{key:n},c=i(t.key);return c?(c=c,c.temporary=!1,c.dynamicReference&&(c.dynamicReference=!1),c.promise.then(function(){return e})):(e.columns.push(t),t.promise=r["try"](function(){return r.resolve(e.cf.all())}).then(function(n){var e;if(u.isArray(t.key)){if(t.complex=!0,e=u.values(u.pick(n[0],t.key)),e.length!==t.key.length)throw new Error("Column key does not exist in data!",t.key)}else e=n[0][t.key];if(!t.complex&&t.key!==!0&&"undefined"==typeof e)throw new Error("Column key does not exist in data!",t.key);return t.type=t.key===!0?"all":t.complex?"complex":t.array?"array":o(e),f.make(t.key,t.type)}).then(function(n){function i(n){return t.key===!0?r.resolve():r.resolve(t.dimension.bottom(1/0)).then(function(n){var e=f.makeAccessor(t.key);"complex"===t.type?t.values=u.uniq(u.flatten(u.map(n,e))):"array"===t.type?t.values=u.uniq(u.flatten(u.map(n,e))):t.values=u.uniq(u.map(n,e))})}t.dimension=n,t.filterCount=0;var o=e.onDataChange(i);return t.removeListeners=[o],i()}),t.promise.then(function(){return e}))}var f=n("./dimension")(e),a=t;return a.find=i,a}},{"./dimension":38,"./lodash":41,q:5}],37:[function(n,e,t){"use strict";var r=n("q"),u=n("crossfilter2"),i=n("./lodash");e.exports=function(n){function e(n){return i.isArray(n)?r.resolve(u(n)):n&&"function"==typeof n.dimension?r.resolve(n):r.reject(new Error("No Crossfilter data or instance found!"))}function t(e){return n.options.generatedColumns?i.map(e,function(e,t){return i.forEach(n.options.generatedColumns,function(n,t){e[t]=n(e)}),e}):e}function o(e){return e=t(e),r["try"](function(){return r.resolve(n.cf.add(e))}).then(function(){return r.serial(i.map(n.dataListeners,function(n){return function(){return n(!0)}}))}).then(function(){return n})}function c(){return r["try"](function(){return r.resolve(n.cf.remove())}).then(function(){return n})}return{build:e,generateColumns:t,add:o,remove:c}}},{"./lodash":41,crossfilter2:3,q:5}],38:[function(n,e,t){"use strict";var r=n("q"),u=n("./lodash");e.exports=function(n){function e(e,u){var i=t(e);return r.resolve(n.cf.dimension(i,"array"==u))}function t(n){var e;if(u.isArray(n)){var t=u.map(n,function(n){return"d['"+n+"']"});e=new Function("d","return "+JSON.stringify(t).replace(/\"/g,""))}else e=n===!0?function(n,e){return e}:function(e){return e[n]};return e}return{make:e,makeAccessor:t}}},{"./lodash":41,q:5}],39:[function(n,e,t){"use strict";function r(n,e){return n[e]}function u(n,e){e=e(n);for(var t=0;te()}function a(n,e){return n>=e()}function s(n,e){return n-1}function h(n,e){return-1===n.indexOf(e())}function m(n,e){return e().indexOf(n)>-1}function y(n,e){return-1===e().indexOf(n)}function g(n,e){return n.length===e()}e.exports={$field:r,$and:u,$or:i,$not:o,$eq:c,$gt:f,$gte:a,$lt:s,$lte:l,$ne:p,$type:d,$in:v,$nin:h,$contains:m,$excludes:y,$size:g}},{}],40:[function(n,e,t){"use strict";var r=n("q"),u=n("./lodash"),i=n("./expressions"),o=n("./aggregation");e.exports=function(n){function e(e,t,i,o){var a=n.column.find(e);return r["try"](function(){return a?a:n.column({key:e,temporary:!0}).then(function(){return n.column.find(e)})}).then(function(e){var r=u.clone(n.filters,!0),a=e.complex?JSON.stringify(e.key):e.key;return r[a]=c(t,i,o),f(r)})}function t(){return f({})}function c(n,e,t){return u.isUndefined(n)?!1:u.isFunction(n)?{value:n,"function":n,replace:!0,type:"function"}:u.isObject(n)?{value:n,"function":p(n),replace:!0,type:"function"}:u.isArray(n)?{value:n,replace:e||t,type:e?"range":"inclusive"}:{value:n,replace:t,type:"exact"}}function f(e){var t=u.map(e,function(t,i){var o=n.filters[i];if(t.replace&&o&&u.isEqual(t,o))return r.resolve();var c;return c="["===i.charAt(0)?n.column.find(JSON.parse(i)):n.column.find(i),t&&o&&!t.replace&&(e[i]=t=a(t,o)),t?"exact"===t.type?r.resolve(c.dimension.filterExact(t.value)):"range"===t.type?r.resolve(c.dimension.filterRange(t.value)):"inclusive"===t.type?r.resolve(c.dimension.filterFunction(function(n){return t.value.indexOf(n)>-1})):"function"===t.type?r.resolve(c.dimension.filterFunction(t["function"])):r.resolve(c.dimension.filterAll()):r.resolve(c.dimension.filterAll())});return r.all(t).then(function(){n.filters=e;var t=[];return u.forEach(n.filters,function(e,r){e||(t.push({key:r,val:e}),delete n.filters[r])}),r.all(u.map(t,function(e){var t=n.column.find("["===e.key.charAt(0)?JSON.parse(e.key):e.key);return t.temporary&&!t.dynamicReference?n.clear(t.key):void 0}))}).then(function(){return n})}function a(n,e){if("exact"===n.type&&"inclusive"===e.type)n.value=u.xor([n.value],e.value);else if("inclusive"===n.type&&"exact"===e.type)n.value=u.xor(n.value,[e.value]);else if("inclusive"===n.type&&"inclusive"===e.type)n.value=u.xor(n.value,e.value);else if("exact"===n.type&&"exact"===e.type){if(n.value===e.value)return!1;n.value=[n.value,e.value]}return n.value.length?1===n.value.length?(n.type="exact",n.value=n.value[0]):n.type="inclusive":n=!1,n}function s(n){function e(n){u.forEach(n,function(n,r){var i=l(n,r);i&&t.push(i),u.isString(n)&&(i=l(null,n),i&&t.push(i)),u.isObject(n)&&e(n)})}var t=[];return e(n.filter),t}function l(n,e){return"$data"===e?!0:e&&"$column"===e?u.isString(n)?n:(console.warn('The value for filter "$column" must be a valid column key',n),!1):void 0}function p(e,t){var r;if(u.isString(e)){var c=l(null,e);if(c){var f=n.cf.all();return function(n){return f}}}return u.isString(e)||u.isNumber(e)||u.isBoolean(e)?function(n){return"undefined"==typeof n?e:i.$eq(n,function(){return e})}:u.isArray(e)?(r=u.map(e,function(n){return p(n,t)}),function(n){return r.map(function(e){return e(n)})}):u.isObject(e)?(r=u.map(e,function(e,r){var u=p(e,t),c=l(e,r);if(c){var f=n.column.find(c),a=f.values;return function(n){return a}}if(i[r])return function(n){return i[r](n,u)};var s=o.parseAggregatorParams(r);return s?(t=!0,u=p(e,t),function(n){return s.aggregator.apply(null,[u()].concat(s.params))}):function(n){return n=n[r],u(n,u)}}),t?1===r.length?function(n){return r[0](n)}:function(n){return u.map(r,function(e){return e(n)})}:function(n){return i.$and(n,function(n){return u.map(r,function(e){return e(n)})})}):(console.log("no expression found for ",e),!1)}return{filter:e,filterAll:t,applyFilters:f,makeFunction:p,scanForDynamicFilters:s}}},{"./aggregation":34,"./expressions":39,"./lodash":41,q:5}],41:[function(n,e,t){"use strict";function r(n){n=n||{};for(var e=1;ee.value?1:n.valuer?n.splice(r,t-r):r>t&&n.push.apply(n,new Array(r-t)),h(n,function(t,r){n[r]=e[r]}),n}function w(n){var e=new Set;return n.filter(function(n){var t=!1;return e.has(n)||(e.add(n),t=!0),t})}function A(n){for(var e=[],t=0;tt;)n[r]=n[r-1],--r;n[r]=t}return n}function O(n){var e=[];for(var t in n)n.hasOwnProperty(t)&&e.push(n[t]);return e}n("javascript-natural-sort");e.exports={assign:r,find:u,remove:i,isArray:o,isObject:c,isBoolean:f,isString:a,isNumber:s,isFunction:l,get:p,map:d,sortBy:v,forEach:h,isUndefined:m,pick:y,xor:g,clone:x,isEqual:b,replaceArray:k,uniq:w,flatten:A,sort:j,values:O}},{"javascript-natural-sort":4}],42:[function(n,e,t){"use strict";function r(n){var e,t=new Error;return i.forEach(n,function(n,r){var i,c=n.success||n,f=n.fail,a=n.notify;if(e)i=e.then(function(n){if(!c)return n;var e=c(n);if(!o(e))throw t.message="Task "+r+" did not return a promise.",t;return e},function(n){if(!f)return u.reject(n);var e=f(n);if(!o(e))throw t.message="Fail for task "+r+" did not return a promise.",t;return e},a);else if(i=c(),!o(i))throw t.message="Task "+r+" did not return a promise.",t;e=i}),e||u.when()}var u=n("q"),i=n("./lodash");u.serial=r;var o=function(n){return n&&i.isFunction(n.then)}},{"./lodash":41,q:5}],43:[function(n,e,t){"use strict";var r=n("q"),u=n("./lodash");e.exports=function(e){var t=n("./reductiofy")(e),i=n("./filters")(e);return function(n){"undefined"==typeof n&&(n={}),"undefined"==typeof n.select&&(n.select={$count:!0}),n.groupBy=n.groupBy||!0;var o,c=e.column.find(n.groupBy);return r["try"](function(){return c?c:e.column({key:n.groupBy,type:u.isUndefined(n.type)?null:n.type,array:!!n.array}).then(function(){return e.column.find(n.groupBy)})}).then(function(n){return c=n,r.resolve(c.dimension.group())}).then(function(e){return o=e,i.scanForDynamicFilters(n)}).then(function(n){return n.length?r.all(u.map(n,function(n){return e.column({key:n,dynamicReference:o})})).then(function(){return!0}):!1}).then(function(u){function i(e,u){return t(n).then(function(n){return e.reducer=n,e.reducer(e.group),r.resolve(e.group.all())}).then(function(n){e.data=n})}var f,a={universe:e,crossfilter:e.cf,dimension:c.dimension,group:o,reducer:null};return u&&(f=e.onDataChange(function(n){return i(a,n)}),c.removeListeners.push(f)),i(a).then(function(){return a})})}}},{"./filters":40,"./lodash":41,"./reductiofy":45,q:5}],44:[function(n,e,t){"use strict";function r(n,e){return n.count(!0)}function u(n,e){return n.sum(e)}function i(n,e){return n.avg(e)}function o(n,e){return n.min(e)}function c(n,e){return n.max(e)}function f(n,e){return n.median(e)}function a(n,e){return n.sumOfSq(e)}function s(n,e){return n.std(e)}function l(n,e){return n.valueList(e)}function p(n,e){return n.dataList(!0)}n("./lodash");e.exports={shorthandLabels:{$count:"count",$sum:"sum",$avg:"avg",$min:"min",$max:"max",$med:"med",$sumSq:"sumSq",$std:"std"},aggregators:{$count:r,$sum:u,$avg:i,$min:o,$max:c,$med:f,$sumSq:a,$std:s,$valueList:l,$dataList:p}}},{"./lodash":41}],45:[function(n,e,t){"use strict";var r=n("reductio"),u=n("./lodash"),i=n("./reductioAggregators"),o=(n("./expressions"),n("./aggregation"));e.exports=function(e){var t=n("./filters")(e);return function(n){function e(n,t){var r=u.sortBy(u.map(t,function(n,e){return{key:e,value:n}}),function(n){return i.aggregators[n.key]?0:1});return u.forEach(r,function(t){if(i.aggregators[t.key]){var r=c(t.value);return void(n=i.aggregators[t.key](n,r))}return u.isObject(t.value)?void(n=e(n.value(t.key),t.value)):void console.error("Nested selects must be an object",t.key)})}function c(n){return"string"==typeof n||"number"==typeof n?n+"":u.isObject(n)?o.makeFunction(n):void 0}var f=r();n.groupBy;if(e(f,n.select),n.filter){var a=t.makeFunction(n.filter);a&&f.filter(a)}return Promise.resolve(f)}}},{"./aggregation":34,"./expressions":39,"./filters":40,"./lodash":41,"./reductioAggregators":44,reductio:27}],46:[function(n,e,t){"use strict";function r(e,t){function r(n){return i.dataListeners.push(n),function(){i.dataListeners.splice(i.dataListeners.indexOf(n),1)}}var i={options:u.assign({},t),columns:[],filters:{},dataListeners:[]},o=n("./crossfilter")(i);return e=o.generateColumns(e),o.build(e).then(function(e){return i.cf=e,u.assign(i,{add:o.add,remove:o.remove,column:n("./column")(i),query:n("./query")(i),filter:n("./filters")(i).filter,clear:n("./clear")(i),onDataChange:r})})}n("./q.serial");var u=(n("q"),n("./lodash"));e.exports=r},{"./clear":35,"./column":36,"./crossfilter":37,"./filters":40,"./lodash":41,"./q.serial":42,"./query":43,q:5}]},{},[46])(46)}); \ No newline at end of file