Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

converted key to string to be safeside #870

Merged
merged 1 commit into from
Feb 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions lib/partitioner.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
var util = require('util');
var _ = require('lodash');

var Partitioner = function () {};
var Partitioner = function () { };

var DefaultPartitioner = function () {};
var DefaultPartitioner = function () { };
util.inherits(DefaultPartitioner, Partitioner);

DefaultPartitioner.prototype.getPartition = function (partitions) {
Expand All @@ -23,27 +23,29 @@ util.inherits(CyclicPartitioner, Partitioner);

CyclicPartitioner.prototype.getPartition = function (partitions) {
if (_.isEmpty(partitions)) return 0;
return partitions[ this.c++ % partitions.length ];
return partitions[this.c++ % partitions.length];
};

var RandomPartitioner = function () {};
var RandomPartitioner = function () { };
util.inherits(RandomPartitioner, Partitioner);

RandomPartitioner.prototype.getPartition = function (partitions) {
return partitions[Math.floor(Math.random() * partitions.length)];
};

var KeyedPartitioner = function () {};
var KeyedPartitioner = function () { };
util.inherits(KeyedPartitioner, Partitioner);

// Taken from oid package (Dan Bornstein)
// Copyright The Obvious Corporation.
KeyedPartitioner.prototype.hashCode = function (string) {
var hash = 0;
var length = string.length;
if (string) {
var length = string.toString().length;

for (var i = 0; i < length; i++) {
hash = ((hash * 31) + string.charCodeAt(i)) & 0x7fffffff;
for (var i = 0; i < length; i++) {
hash = ((hash * 31) + string.charCodeAt(i)) & 0x7fffffff;
}
}

return (hash === 0) ? 1 : hash;
Expand Down