Package com.apple.foundationdb.tuple
Class TupleHelpers
java.lang.Object
com.apple.foundationdb.tuple.TupleHelpers
Helper methods for working with
Tuples.-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic intCompare two tuples lexicographically, that is, the same way they would sort when used as keys.static booleanDetermine if twoTuples have the same contents.static booleanGet whether one tuple is a prefix of another.static NumberNegate a number used as an element of aTuple.static intpackedSizeAsTupleItem(Object item) Get the number of bytes that an object would occupy as an element of an encodedTuple.static intprefixLengthOfSize(byte[] bytes, int size) Get the index of a prefix of an encoded tuple that decodes as a sub-tuple of the given size.static Tuplestatic Tuple
-
Field Details
-
EMPTY
-
-
Method Details
-
set
-
subTuple
-
compare
Compare two tuples lexicographically, that is, the same way they would sort when used as keys. Note that this is currently WAY more efficient than callingTuple.equals(java.lang.Object), and slightly more efficient than callingTuple.compareTo(com.apple.foundationdb.tuple.Tuple). -
equals
Determine if twoTuples have the same contents. Unfortunately, the implementation ofTuple.equals()serializes bothTuples to byte arrays, so it is fairly expensive. This method avoids serializing eitherTuple, and it also adds a short-circuit to return early if the twoTuples are pointer-equal. -
negate
Negate a number used as an element of aTuple.- Parameters:
number- the number to be negated- Returns:
- a negated number suitable for use in a new
Tuple
-
packedSizeAsTupleItem
Get the number of bytes that an object would occupy as an element of an encodedTuple. UnlikeTuple.getPackedSize(), this does not include the extra space an incompleteVersionstampwould add to the end to record its position.- Parameters:
item- an item of a tuple- Returns:
- the number of bytes in the encoded form of the item
-
isPrefix
Get whether one tuple is a prefix of another.- Parameters:
t1- the potential prefixt2- the whole tuple- Returns:
trueift1is a prefix oft2
-
prefixLengthOfSize
public static int prefixLengthOfSize(@Nonnull byte[] bytes, int size) Get the index of a prefix of an encoded tuple that decodes as a sub-tuple of the given size.- Parameters:
bytes- encoded tuplesize- size of desired subtuple- Returns:
- the index into
bytesthat ends the sub-tuple or-1ifbytesis too short or decoding fails
-