MCPcopy Create free account
hub / github.com/apache/cassandra-nodejs-driver / splitBase

Method splitBase

lib/tokenizer.js:92–114  ·  view source on GitHub ↗

* Common implementation for splitting token ranges when start is in * a shared Integer format. * * @param {Integer} start Starting token * @param {Integer} range How large the range of the split is * @param {Integer} ringEnd The end point of the ring so we know where to wrap * @par

(start, range, ringEnd, ringLength, numberOfSplits)

Source from the content-addressed store, hash-verified

90 * @returns {Array<Integer>} The evenly-split points on the range
91 */
92 splitBase(start, range, ringEnd, ringLength, numberOfSplits) {
93 const numberOfSplitsInt = Integer.fromInt(numberOfSplits);
94 const divider = range.divide(numberOfSplitsInt);
95 let remainder = range.modulo(numberOfSplitsInt);
96
97 const results = [];
98 let current = start;
99 const dividerPlusOne = divider.add(Integer.ONE);
100
101 for(let i = 1; i < numberOfSplits; i++) {
102 if (remainder.greaterThan(Integer.ZERO)) {
103 current = current.add(dividerPlusOne);
104 } else {
105 current = current.add(divider);
106 }
107 if (ringLength && current.greaterThan(ringEnd)) {
108 current = current.subtract(ringLength);
109 }
110 results.push(current);
111 remainder = remainder.subtract(Integer.ONE);
112 }
113 return results;
114 }
115
116 /**
117 * Return internal string based representation of a Token.

Callers 3

splitMethod · 0.80
splitMethod · 0.80
splitMethod · 0.80

Calls 2

addMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected