Was this page helpful?
TokenRange¶
TokenRange()
Represents a range of tokens on a Cassandra ring.
A range is start-exclusive and end-inclusive. It is empty when start and end are the same token, except if that is the minimum token, in which case the range covers the whole ring (this is consistent with the behavior of CQL range queries).
Note that CQL does not handle wrapping. To query all partitions in a range, see unwrap.
Constructor¶
new TokenRange()
Source
Methods¶
compare(other) → {Number}
Returns 0 if the values are equal, otherwise compares against start, if start is equal, compares against end.
Parameters:
| Name | Type | Description |
|---|---|---|
other |
TokenRange | Range to compare with. |
Source
Returns:
- Type
- Number
contains(token) → {boolean}
Whether this range contains a given Token.
Parameters:
| Name | Type | Description |
|---|---|---|
token |
* | Token to check for. |
Source
Returns:
Whether or not the Token is in this range.
- Type
- boolean
equals(other) → {boolean}
Determines if the input range is equivalent to this one.
Parameters:
| Name | Type | Description |
|---|---|---|
other |
TokenRange | Range to compare with. |
Source
Returns:
Whether or not the ranges are equal.
- Type
- boolean
isEmpty() → {boolean}
A range is empty when start and end are the same token, except if that is the minimum token, in which case the range covers the whole ring. This is consistent with the behavior of CQL range queries.
Source
Returns:
Whether this range is empty.
- Type
- boolean
isWrappedAround() → {boolean}
A range wraps around the end of the ring when the start token is greater than the end token and the end token is not the minimum token.
Source
Returns:
Whether this range wraps around.
- Type
- boolean
splitEvenly(numberOfSplits) → {Array:.<TokenRange:>}
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.
Parameters:
| Name | Type | Description |
|---|---|---|
numberOfSplits |
Number | Number of splits to make. |
Source
Throws:
-
If splitting an empty range.
- Type
- Error
Returns:
Split ranges.
- Type
- Array:.<TokenRange:>
unwrap() → {Array:.<TokenRange:>}
Splits this range into a list of two non-wrapping ranges.
This will return the range itself if it is non-wrapped, or two ranges otherwise.
This is useful for CQL range queries, which do not handle wrapping.
Source
Returns:
The list of non-wrapping ranges.
- Type
- Array:.<TokenRange:>