@omneedia/socketcluster
Version:
SocketCluster - A Highly parallelized WebSocket server cluster to make the most of multi-core machines/instances.
24 lines (18 loc) • 507 B
JavaScript
var Hasher = require('../hasher');
function SimpleMapper() {
this.hasher = new Hasher();
this.sites = [];
}
SimpleMapper.prototype.setSites = function (sites) {
this.sites = sites;
};
SimpleMapper.prototype.getSites = function () {
return this.sites;
};
SimpleMapper.prototype.findSite = function (key) {
key = this.hasher.hashToHex(key);
var sites = this.sites;
var targetIndex = this.hasher.hashToIndex(key, sites.length);
return sites[targetIndex];
};
module.exports = SimpleMapper;