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

Method splitEvenly

lib/token.js:155–174  ·  view source on GitHub ↗

* Splits this range into a number of smaller ranges of equal "size" * (referring to the number of tokens, not the actual amount of data). * * Splitting an empty range is not permitted. But not that, in edge * cases, splitting a range might produce one or more empty ranges. * * @pa

(numberOfSplits)

Source from the content-addressed store, hash-verified

153 * @throws {Error} If splitting an empty range.
154 */
155 splitEvenly(numberOfSplits) {
156 if (numberOfSplits < 1) {
157 throw new Error(util.format("numberOfSplits (%d) must be greater than 0.", numberOfSplits));
158 }
159 if (this.isEmpty()) {
160 throw new Error("Can't split empty range " + this.toString());
161 }
162
163 const tokenRanges = [];
164 const splitPoints = this._tokenizer.split(this.start, this.end, numberOfSplits);
165 let splitStart = this.start;
166 let splitEnd;
167 for (let splitIndex = 0; splitIndex < splitPoints.length; splitIndex++) {
168 splitEnd = splitPoints[splitIndex];
169 tokenRanges.push(new TokenRange(splitStart, splitEnd, this._tokenizer));
170 splitStart = splitEnd;
171 }
172 tokenRanges.push(new TokenRange(splitStart, this.end, this._tokenizer));
173 return tokenRanges;
174 }
175
176 /**
177 * A range is empty when start and end are the same token, except if

Callers

nothing calls this directly

Calls 4

isEmptyMethod · 0.95
toStringMethod · 0.95
splitMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected