Class Util
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe seed 9001 used in the sketch update methods is a prime number that was chosen very early on in experimental testing.static final doubleThe inverse golden ratio as a fraction.static final longThe inverse golden ratio as an unsigned long.static final doubleThe natural logarithm of 2.0.static final doubleLong.MAX_VALUE as a double.static final StringThe java line separator character as a String.static final charThe tab character -
Method Summary
Modifier and TypeMethodDescriptionstatic MemorySegmentalignedHeapSegment(int capacityBytes, boolean aligned) Request a new heap MemorySegment with the given capacityBytes and either 8-byte aligned or one byte aligned.static intbitAt(long number, int bitPos) Returns a one if the bit at bitPos is a one, otherwise zero.static intbytesToInt(byte[] arr) Returns an int extracted from a Little-Endian byte array.static longbytesToLong(byte[] arr) Returns a long extracted from a Little-Endian byte array.static StringbytesToString(byte[] arr, boolean signed, boolean littleEndian, String sep) Returns a string view of a byte arraystatic longceilingMultiple2expK(long n, int k) This is a long integer equivalent to Math.ceil(n / (double)(1 << k)) where: 0 < k ≤ 6 and n is a non-negative long.static doubleceilingPowerBaseOfDouble(double base, double n) Returns the ceiling of a given n given a base, where the ceiling is an integral power of the base.static intceilingPowerOf2(int n) Computes the int ceiling power of 2 within the range [1, 2^30].static longceilingPowerOf2(long n) Computes the long ceiling power of 2 within the range [1, 2^62].static StringcharacterPad(String s, int fieldLength, char padChar, boolean postpend) Prepend or postpend the given string with the given character to fill the given field length.static voidcheckBounds(long reqOff, long reqLen, long allocSize) Check the requested offset and length against the allocated size.static voidcheckIfMultipleOf8AndGT0(long v, String argName) Checks if parameter v is a multiple of 8 and greater than zero.static voidcheckIfPowerOf2(long n, String argName) Checks the given long argument if it is a positive integer power of 2.static voidcheckProbability(double p, String argName) Checks the given parameter to make sure it is positive and between 0.0 inclusive and 1.0 inclusive.static shortcheckSeedHashes(short seedHashA, short seedHashB) Check if the two seed hashes are equal.static voidclear(MemorySegment seg) Clears all bytes of this MemorySegment to zero.static voidclear(MemorySegment seg, long offsetBytes, long lengthBytes) Clears a portion of this MemorySegment to zero.static voidclearBits(MemorySegment seg, long offsetBytes, byte bitMask) Clears the bits defined by the bitMaskstatic shortcomputeSeedHash(long seed) Computes and checks the 16-bit seed hash from the given long seed.static booleanequalContents(MemorySegment seg1, long seg1offsetBytes, MemorySegment seg2, long seg2offsetBytes, long lengthBytes) Returns true if both segments have the same content for the specified region.static booleanequalContents(MemorySegment seg1, MemorySegment seg2) Returns true if both segments have the same contents and the same length.static intexactLog2OfInt(int powerOf2) Returns the log2 of the given int value if it is an exact power of 2 and greater than zero.static intexactLog2OfInt(int powerOf2, String argName) Returns the log2 of the given int value if it is an exact power of 2 and greater than zero.static intexactLog2OfLong(long powerOf2) Returns the log2 of the given long value if it is an exact power of 2 and greater than zero.static intexactLog2OfLong(long powerOf2, String argName) Returns the log2 of the given long value if it is an exact power of 2 and greater than zero.static voidfill(MemorySegment seg, long offsetBytes, long lengthBytes, byte value) Fills a portion of this Memory region to the given byte value.static doublefloorPowerBaseOfDouble(double base, double n) Computes the floor of a given n given base, where the floor is an integral power of the base.static intfloorPowerOf2(int n) Computes the floor power of 2 given n is in the range [1, 2^31-1].static longfloorPowerOf2(long n) Computes the floor power of 2 given n is in the range [1, 2^63-1].static byte[]intToBytes(int v, byte[] arr) Returns a Little-Endian byte array extracted from the given int.static doubleinvPow2(int e) Computes the inverse integer power of 2: 1/(2^e) = 2^(-e).static booleanisEven(long n) Returns true if given n is even.static booleanisLessThanUnsigned(long n1, long n2) Unsigned compare with longs.static booleanisMultipleOf8AndGT0(long v) Returns true if v is a multiple of 8 and greater than zerostatic booleanisOdd(long n) Returns true if given n is odd.static booleanisPowerOf2(long n) Returns true if given long argument is exactly a positive power of 2.static <T> booleanle(Object item1, Object item2, Comparator<? super T> c) Is item1 Less-Than-Or-Equal-To item2?static doublelog2(double value) The log2(value)static doublelogBaseOfX(double base, double x) Returns the logbase(x).static byte[]longToBytes(long v, byte[] arr) Returns a Little-Endian byte array extracted from the given long.static StringlongToFixedLengthString(long number, int length) Converts the given number to a string prepended with spaces, if necessary, to match the given length.static StringlongToHexBytes(long v) Returns a string of spaced hex bytes in Big-Endian order.static <T> booleanlt(Object item1, Object item2, Comparator<? super T> c) Is item1 Less-Than item2?static <T> ObjectmaxT(Object item1, Object item2, Comparator<? super T> c) Finds the maximum of two generic itemsstatic StringmilliSecToString(long mS) Returns the given time in milliseconds formatted as Hours:Min:Sec.mSecstatic <T> ObjectminT(Object item1, Object item2, Comparator<? super T> c) Finds the minimum of two generic itemsstatic StringnanoSecToString(long nS) Returns the given time in nanoseconds formatted as Sec.mSec_uSec_nSecstatic intnumberOfLeadingOnes(long v) Returns the number of one bits preceding the highest-order ("leftmost") zero-bit in the two's complement binary representation of the specified long value, or 64 if the value is equal to minus one.static intnumberOfTrailingOnes(long v) Returns the number of one bits following the lowest-order ("rightmost") zero-bit in the two's complement binary representation of the specified long value, or 64 if the value is equal to minus one.static intnumDigits(long n) Computes the number of decimal digits of the number nstatic doublepowerSeriesNextDouble(int ppb, double curPoint, boolean roundToLong, double logBase) Computes the next larger double in the power series point = logBase( i / ppb ) given the current point in the series.static longpwr2SeriesNext(int ppo, long curPoint) Computes the next larger integer point in the power series point = 2( i / ppo ) given the current point in the series.static intpwr2SeriesPrev(int ppo, int curPoint) Computes the previous, smaller integer point in the power series point = 2( i / ppo ) given the current point in the series.static voidsetBits(MemorySegment seg, long offsetBytes, byte bitMask) Sets the bits defined by the bitMaskstatic StringPrepend the given string with zeros.
-
Field Details
-
LS
The java line separator character as a String. -
TAB
public static final char TABThe tab character- See Also:
-
LOG2
public static final double LOG2The natural logarithm of 2.0. -
INVERSE_GOLDEN_U64
public static final long INVERSE_GOLDEN_U64The inverse golden ratio as an unsigned long.- See Also:
-
INVERSE_GOLDEN
public static final double INVERSE_GOLDENThe inverse golden ratio as a fraction. This has more precision than using the formula: (Math.sqrt(5.0) - 1.0) / 2.0.- See Also:
-
LONG_MAX_VALUE_AS_DOUBLE
public static final double LONG_MAX_VALUE_AS_DOUBLELong.MAX_VALUE as a double.- See Also:
-
DEFAULT_UPDATE_SEED
public static final long DEFAULT_UPDATE_SEEDThe seed 9001 used in the sketch update methods is a prime number that was chosen very early on in experimental testing. Choosing a seed is somewhat arbitrary, and the author cannot prove that this particular seed is somehow superior to other seeds. There was some early Internet discussion that a seed of 0 did not produce as clean avalanche diagrams as non-zero seeds, but this may have been more related to the MurmurHash2 release, which did have some issues. As far as the author can determine, MurmurHash3 does not have these problems.In order to perform set operations on two sketches it is critical that the same hash function and seed are identical for both sketches, otherwise the assumed 1:1 relationship between the original source key value and the hashed bit string would be violated. Once you have developed a history of stored sketches you are stuck with it.
WARNING: This seed is used internally by library sketches in different packages and thus must be declared public. However, this seed value must not be used by library users with the MurmurHash3 function. It should be viewed as existing for exclusive, private use by the library.
- See Also:
-
-
Method Details
-
bytesToInt
public static int bytesToInt(byte[] arr) Returns an int extracted from a Little-Endian byte array.- Parameters:
arr- the given byte array- Returns:
- an int extracted from a Little-Endian byte array.
-
bytesToLong
public static long bytesToLong(byte[] arr) Returns a long extracted from a Little-Endian byte array.- Parameters:
arr- the given byte array- Returns:
- a long extracted from a Little-Endian byte array.
-
intToBytes
public static byte[] intToBytes(int v, byte[] arr) Returns a Little-Endian byte array extracted from the given int.- Parameters:
v- the given intarr- a given array of 4 bytes that will be returned with the data- Returns:
- a Little-Endian byte array extracted from the given int.
-
longToBytes
public static byte[] longToBytes(long v, byte[] arr) Returns a Little-Endian byte array extracted from the given long.- Parameters:
v- the given longarr- a given array of 8 bytes that will be returned with the data- Returns:
- a Little-Endian byte array extracted from the given long.
-
longToHexBytes
Returns a string of spaced hex bytes in Big-Endian order.- Parameters:
v- the given long- Returns:
- string of spaced hex bytes in Big-Endian order.
-
bytesToString
Returns a string view of a byte array- Parameters:
arr- the given byte arraysigned- set true if you want the byte values signed.littleEndian- set true if you want Little-Endian ordersep- the separator string between bytes- Returns:
- a string view of a byte array
-
nanoSecToString
Returns the given time in nanoseconds formatted as Sec.mSec_uSec_nSec- Parameters:
nS- the given nanoseconds- Returns:
- the given time in nanoseconds formatted as Sec.mSec_uSec_nSec
-
milliSecToString
Returns the given time in milliseconds formatted as Hours:Min:Sec.mSec- Parameters:
mS- the given milliseconds- Returns:
- the given time in milliseconds formatted as Hours:Min:Sec.mSec
-
zeroPad
Prepend the given string with zeros. If the given string is equal or greater than the given field length, it will be returned without modification.- Parameters:
s- the given stringfieldLength- desired total field length including the given string- Returns:
- the given string prepended with zeros.
-
characterPad
Prepend or postpend the given string with the given character to fill the given field length. If the given string is equal to or greater than the given field length, it will be returned without modification.- Parameters:
s- the given stringfieldLength- the desired field lengthpadChar- the desired pad characterpostpend- if true append the pacCharacters to the end of the string.- Returns:
- prepended or postpended given string with the given character to fill the given field length.
-
checkIfMultipleOf8AndGT0
Checks if parameter v is a multiple of 8 and greater than zero.- Parameters:
v- The parameter to checkargName- This name will be part of the error message if the check fails.
-
isMultipleOf8AndGT0
public static boolean isMultipleOf8AndGT0(long v) Returns true if v is a multiple of 8 and greater than zero- Parameters:
v- The parameter to check- Returns:
- true if v is a multiple of 8 and greater than zero
-
isPowerOf2
public static boolean isPowerOf2(long n) Returns true if given long argument is exactly a positive power of 2.- Parameters:
n- The input argument.- Returns:
- true if argument is exactly a positive power of 2.
-
checkIfPowerOf2
Checks the given long argument if it is a positive integer power of 2. If not, it throws an exception with the user supplied local argument name, if not null.- Parameters:
n- The input long argument must be a positive integer power of 2.argName- Used in the thrown exception. It may be null.- Throws:
SketchesArgumentException- if not a positive integer power of 2.
-
ceilingPowerOf2
public static int ceilingPowerOf2(int n) Computes the int ceiling power of 2 within the range [1, 2^30]. This is the smallest positive power of 2 that is equal to or greater than the given n and a positive integer.For:
- n ≤ 1: returns 1
- 2^30 ≤ n ≤ 2^31 -1 : returns 2^30
- n == an exact power of 2 : returns n
- otherwise returns the smallest power of 2 ≥ n and equal to a positive integer
- Parameters:
n- The input int argument.- Returns:
- the ceiling power of 2.
-
ceilingPowerOf2
public static long ceilingPowerOf2(long n) Computes the long ceiling power of 2 within the range [1, 2^62]. This is the smallest positive power of 2 that is equal to or greater than the given n and a positive long.For:
- n ≤ 1: returns 1
- 2^62 ≤ n ≤ 2^63 -1 : returns 2^62
- n == an exact power of 2 : returns n
- otherwise returns the smallest power of 2 ≥ n and equal to a positive long
- Parameters:
n- The input long argument.- Returns:
- the ceiling power of 2.
-
floorPowerOf2
public static int floorPowerOf2(int n) Computes the floor power of 2 given n is in the range [1, 2^31-1]. This is the largest positive power of 2 that equal to or less than the given n and equal to a positive integer.For:
- n ≤ 1: returns 1
- 2^30 ≤ n ≤ 2^31 -1 : returns 2^30
- n == a power of 2 : returns n
- otherwise returns the largest power of 2 less than n and equal to a mathematical integer.
- Parameters:
n- The given int argument.- Returns:
- the floor power of 2 as an int.
-
floorPowerOf2
public static long floorPowerOf2(long n) Computes the floor power of 2 given n is in the range [1, 2^63-1]. This is the largest positive power of 2 that is equal to or less than the given n and equal to a positive integer.For:
- n ≤ 1: returns 1
- 2^62 ≤ n ≤ 2^63 -1 : returns 2^62
- n == a power of 2 : returns n
- otherwise returns the largest power of 2 less than n and equal to a mathematical integer.
- Parameters:
n- The given long argument.- Returns:
- the floor power of 2 as a long
-
ceilingMultiple2expK
public static long ceilingMultiple2expK(long n, int k) This is a long integer equivalent to Math.ceil(n / (double)(1 << k)) where: 0 < k ≤ 6 and n is a non-negative long. These limits are not checked for speed reasons.- Parameters:
n- the input dividend as a positive long greater than zero.k- the input divisor exponent of 2 as a positive integer where 0 < k ≤ 6.- Returns:
- the long integer equivalent to Math.ceil(n / 2^k).
-
invPow2
public static double invPow2(int e) Computes the inverse integer power of 2: 1/(2^e) = 2^(-e).- Parameters:
e- a positive value between 0 and 1023 inclusive- Returns:
- the inverse integer power of 2: 1/(2^e) = 2^(-e)
-
pwr2SeriesNext
public static long pwr2SeriesNext(int ppo, long curPoint) Computes the next larger integer point in the power series point = 2( i / ppo ) given the current point in the series. For illustration, this can be used in a loop as follows:int maxP = 1024; int minP = 1; int ppo = 2; for (int p = minP; p <= maxP; p = pwr2SeriesNext(ppo, p)) { System.out.print(p + " "); } //generates the following series: //1 2 3 4 6 8 11 16 23 32 45 64 91 128 181 256 362 512 724 1024- Parameters:
ppo- Points-Per-Octave, or the number of points per integer powers of 2 in the series.curPoint- the current point of the series. Must be ≥ 1.- Returns:
- the next point in the power series.
-
pwr2SeriesPrev
public static int pwr2SeriesPrev(int ppo, int curPoint) Computes the previous, smaller integer point in the power series point = 2( i / ppo ) given the current point in the series. For illustration, this can be used in a loop as follows:int maxP = 1024; int minP = 1; int ppo = 2; for (int p = maxP; p >= minP; p = pwr2SeriesPrev(ppo, p)) { System.out.print(p + " "); } //generates the following series: //1024 724 512 362 256 181 128 91 64 45 32 23 16 11 8 6 4 3 2 1- Parameters:
ppo- Points-Per-Octave, or the number of points per integer powers of 2 in the series.curPoint- the current point of the series. Must be ≥ 1.- Returns:
- the previous, smaller point in the power series. A returned value of zero terminates the series.
-
powerSeriesNextDouble
public static double powerSeriesNextDouble(int ppb, double curPoint, boolean roundToLong, double logBase) Computes the next larger double in the power series point = logBase( i / ppb ) given the current point in the series. For illustration, this can be used in a loop as follows:double maxP = 1024.0; double minP = 1.0; int ppb = 2; double logBase = 2.0; for (double p = minP; p <= maxP; p = powerSeriesNextDouble(ppb, p, true, logBase)) { System.out.print(p + " "); } //generates the following series: //1 2 3 4 6 8 11 16 23 32 45 64 91 128 181 256 362 512 724 1024- Parameters:
ppb- Points-Per-Base, or the number of points per integer powers of base in the series.curPoint- the current point of the series. Must be ≥ 1.0.roundToLong- if true the output will be rounded to the nearest long.logBase- the desired base of the logarithms- Returns:
- the next point in the power series.
-
ceilingPowerBaseOfDouble
public static double ceilingPowerBaseOfDouble(double base, double n) Returns the ceiling of a given n given a base, where the ceiling is an integral power of the base. This is the smallest positive power of base that is equal to or greater than the given n and equal to a mathematical integer. The result of this function is consistent withceilingPowerOf2(int)for values less than one. I.e., if n < 1, the result is 1.The formula is: baseceiling(logbase(x))
- Parameters:
base- The number in the expression ⌈basen⌉.n- The input argument.- Returns:
- the ceiling power of base as a double and equal to a mathematical integer.
-
floorPowerBaseOfDouble
public static double floorPowerBaseOfDouble(double base, double n) Computes the floor of a given n given base, where the floor is an integral power of the base. This is the largest positive power of base that is equal to or less than the given n and equal to a mathematical integer. The result of this function is consistent withfloorPowerOf2(int)for values less than one. I.e., if n < 1, the result is 1.The formula is: basefloor(logbase(x))
- Parameters:
base- The number in the expression ⌊basen⌋.n- The input argument.- Returns:
- the floor power of 2 and equal to a mathematical integer.
-
log2
public static double log2(double value) The log2(value)- Parameters:
value- the given value- Returns:
- log2(value)
-
logBaseOfX
public static double logBaseOfX(double base, double x) Returns the logbase(x). Example, if base = 2.0: logB(2.0, x) = log(x) / log(2.0).- Parameters:
base- The number in the expression log(x) / log(base).x- the given value- Returns:
- the logbase(x)
-
numberOfTrailingOnes
public static int numberOfTrailingOnes(long v) Returns the number of one bits following the lowest-order ("rightmost") zero-bit in the two's complement binary representation of the specified long value, or 64 if the value is equal to minus one.- Parameters:
v- the value whose number of trailing ones is to be computed.- Returns:
- the number of one bits following the lowest-order ("rightmost") zero-bit in the two's complement binary representation of the specified long value, or 64 if the value is equal to minus one.
-
numberOfLeadingOnes
public static int numberOfLeadingOnes(long v) Returns the number of one bits preceding the highest-order ("leftmost") zero-bit in the two's complement binary representation of the specified long value, or 64 if the value is equal to minus one.- Parameters:
v- the value whose number of leading ones is to be computed.- Returns:
- the number of one bits preceding the lowest-order ("rightmost") zero-bit in the two's complement binary representation of the specified long value, or 64 if the value is equal to minus one.
-
exactLog2OfInt
Returns the log2 of the given int value if it is an exact power of 2 and greater than zero. If not, it throws an exception with the user supplied local argument name.- Parameters:
powerOf2- must be a power of 2 and greater than zero.argName- the argument name used in the exception if thrown.- Returns:
- the log2 of the given value if it is an exact power of 2 and greater than zero.
- Throws:
SketchesArgumentException- if not a power of 2 nor greater than zero.
-
exactLog2OfLong
Returns the log2 of the given long value if it is an exact power of 2 and greater than zero. If not, it throws an exception with the user supplied local argument name.- Parameters:
powerOf2- must be a power of 2 and greater than zero.argName- the argument name used in the exception if thrown.- Returns:
- the log2 of the given value if it is an exact power of 2 and greater than zero.
- Throws:
SketchesArgumentException- if not a power of 2 nor greater than zero.
-
exactLog2OfInt
public static int exactLog2OfInt(int powerOf2) Returns the log2 of the given int value if it is an exact power of 2 and greater than zero. If not, it throws an exception.- Parameters:
powerOf2- must be a power of 2 and greater than zero.- Returns:
- the log2 of the given int value if it is an exact power of 2 and greater than zero.
-
exactLog2OfLong
public static int exactLog2OfLong(long powerOf2) Returns the log2 of the given long value if it is an exact power of 2 and greater than zero. If not, it throws an exception.- Parameters:
powerOf2- must be a power of 2 and greater than zero.- Returns:
- the log2 of the given long value if it is an exact power of 2 and greater than zero.
-
checkBounds
public static void checkBounds(long reqOff, long reqLen, long allocSize) Check the requested offset and length against the allocated size. The invariants equation is:0 <= reqOff <= reqLen <= reqOff + reqLen <= allocSize. If this equation is violated anSketchesArgumentExceptionwill be thrown.- Parameters:
reqOff- the requested offsetreqLen- the requested lengthallocSize- the allocated size.
-
checkProbability
Checks the given parameter to make sure it is positive and between 0.0 inclusive and 1.0 inclusive.- Parameters:
p- See Sampling Probability, pargName- Used in the thrown exception.
-
isLessThanUnsigned
public static boolean isLessThanUnsigned(long n1, long n2) Unsigned compare with longs.- Parameters:
n1- A long to be treated as if unsigned.n2- A long to be treated as if unsigned.- Returns:
- true if n1 > n2.
-
isEven
public static boolean isEven(long n) Returns true if given n is even.- Parameters:
n- the given n- Returns:
- true if given n is even.
-
isOdd
public static boolean isOdd(long n) Returns true if given n is odd.- Parameters:
n- the given n- Returns:
- true if given n is odd.
-
bitAt
public static int bitAt(long number, int bitPos) Returns a one if the bit at bitPos is a one, otherwise zero.- Parameters:
number- the number to examinebitPos- the given zero-based bit position, where the least significant bit is at position zero.- Returns:
- a one if the bit at bitPos is a one, otherwise zero.
-
numDigits
public static int numDigits(long n) Computes the number of decimal digits of the number n- Parameters:
n- the given number- Returns:
- the number of decimal digits of the number n
-
longToFixedLengthString
Converts the given number to a string prepended with spaces, if necessary, to match the given length.For example, assume a sequence of integers from 1 to 1000. The largest value has four decimal digits. Convert the entire sequence of strings to the form " 1" to "1000". When these strings are sorted they will be in numerical sequence: " 1", " 2", ... "1000".
- Parameters:
number- the given numberlength- the desired string length.- Returns:
- the given number to a string prepended with spaces
-
minT
Finds the minimum of two generic items- Type Parameters:
T- the type- Parameters:
item1- item oneitem2- item twoc- the given comparator- Returns:
- the minimum value
-
maxT
Finds the maximum of two generic items- Type Parameters:
T- the type- Parameters:
item1- item oneitem2- item twoc- the given comparator- Returns:
- the maximum value
-
lt
Is item1 Less-Than item2?- Type Parameters:
T- the type- Parameters:
item1- item oneitem2- item twoc- the given comparator- Returns:
- true if item1 Less-Than item2
-
le
Is item1 Less-Than-Or-Equal-To item2?- Type Parameters:
T- the type- Parameters:
item1- item oneitem2- item twoc- the given comparator- Returns:
- true if item1 Less-Than-Or-Equal-To item2
-
clear
Clears all bytes of this MemorySegment to zero.- Parameters:
seg- the given MemorySegment
-
clear
Clears a portion of this MemorySegment to zero.- Parameters:
seg- the given MemorySegmentoffsetBytes- offset bytes relative to this MemorySegment startlengthBytes- the length in bytes
-
clearBits
Clears the bits defined by the bitMask- Parameters:
seg- the given MemorySegmentoffsetBytes- offset bytes relative to this Memory start.bitMask- the bits set to one will be cleared
-
equalContents
Returns true if both segments have the same contents and the same length.- Parameters:
seg1- the given MemorySegment #1seg2- the given MemorySegment #2- Returns:
- true if both segments have the same contents and the same length.
-
equalContents
public static boolean equalContents(MemorySegment seg1, long seg1offsetBytes, MemorySegment seg2, long seg2offsetBytes, long lengthBytes) Returns true if both segments have the same content for the specified region.- Parameters:
seg1- the given MemorySegment #1seg1offsetBytes- the starting offset for MemorySegment #1 in bytes.seg2- the given MemorySegment #2seg2offsetBytes- the starting offset for MemorySegment #2 in bytes.lengthBytes- the length of the region to be compared, in bytes.- Returns:
- true, if both segments have the content for the specified region.
-
fill
Fills a portion of this Memory region to the given byte value.- Parameters:
seg- the given MemorySegmentoffsetBytes- offset bytes relative to this Memory startlengthBytes- the length in bytesvalue- the given byte value
-
alignedHeapSegment
Request a new heap MemorySegment with the given capacityBytes and either 8-byte aligned or one byte aligned.If aligned is true, the returned MemorySegment will be constructed from a long[] array, and, as a result, it will have a memory alignment of 8 bytes. If the requested capacity is not exactly divisible by eight, the returned size will be rolled up to the next multiple of eight bytes.
If aligned is false, the returned MemorySegment will be constructed from a byte[] array, and have a memory alignment of 1 byte.
- Parameters:
capacityBytes- The new capacity being requested. It must not be negative and cannot exceed Integer.MAX_VALUE.aligned- if true, the new heap segment will have an alignment of 8 bytes, otherwise the alignment will be 1 byte.- Returns:
- a new MemorySegment with the requested capacity and alignment.
-
setBits
Sets the bits defined by the bitMask- Parameters:
seg- the given MemorySegmentoffsetBytes- offset bytes relative to this MemorySegment startbitMask- the bits set to one will be set
-
computeSeedHash
public static short computeSeedHash(long seed) Computes and checks the 16-bit seed hash from the given long seed. The seed hash may not be zero in order to maintain compatibility with older serialized versions that did not have this concept.- Parameters:
seed- See Update Hash Seed- Returns:
- the seed hash.
-
checkSeedHashes
public static short checkSeedHashes(short seedHashA, short seedHashB) Check if the two seed hashes are equal. If not, throw an SketchesArgumentException.- Parameters:
seedHashA- the seedHash AseedHashB- the seedHash B- Returns:
- seedHashA if they are equal
-