1
0
mirror of synced 2024-11-15 10:27:41 +01:00
bemaniutils/bemani/frontend/static/merge.js
2019-12-08 21:43:49 +00:00

26 lines
750 B
JavaScript

function MergeManager (hash_function, merge_policy) {
this.merge_policy = merge_policy;
this.hash_function = hash_function;
this.data = {};
this.add = function(newdata) {
newdata.map(function(val) {
var hash = this.hash_function(val);
if (hash in this.data) {
if (this.merge_policy == MergeManager.MERGE_POLICY_REPLACE) {
this.data[hash] = val;
}
} else {
this.data[hash] = val;
}
}.bind(this));
return Object.keys(this.data).map(function(hash) {
return this.data[hash];
}.bind(this));
};
};
MergeManager.MERGE_POLICY_DROP = 0;
MergeManager.MERGE_POLICY_REPLACE = 1;