### Install Python Dependencies with Hash Pinning Source: https://github.com/dynatrace-oss/hash4j/blob/main/README.md Install Python dependencies using pip, ensuring hash-pinned installs and rejecting source distributions for security. This command enforces reproducible builds. ```bash python -m pip install --only-binary :all: --require-hashes -r requirements.txt ``` -------------------------------- ### Consistent Bucket Hashing with Jump Back Hash Source: https://github.com/dynatrace-oss/hash4j/blob/main/README.md Use ConsistentBucketHasher for stateless, consistent random assignment of keys to a fixed number of buckets. This example demonstrates mapping keys to 2 and 3 buckets. ```java List keys = asList(0x7f7487ee708c8a96L, 0x6265648fbc797f25L, 0x85ef23a0b545d53bL); // create a consistent bucket hasher var consistentBucketHasher = ConsistentHashing.jumpBackHash(PseudoRandomGeneratorProvider.splitMix64_V1()); // determine mapping of keys to 2 buckets var mapping2 = keys.stream().collect(groupingBy(k -> consistentBucketHasher.getBucket(k, 2), mapping(Long::toHexString, toList()))); // gives {0=[6265648fbc797f25, 85ef23a0b545d53b], 1=[7f7487ee708c8a96]} // determine mapping of keys to 3 buckets var mapping3 = keys.stream().collect(groupingBy(k -> consistentBucketHasher.getBucket(k, 3), mapping(Long::toHexString, toList()))); // gives {0=[6265648fbc797f25], 1=[7f7487ee708c8a96], 2=[85ef23a0b545d53b]} // key 85ef23a0b545d53b got reassigned from bucket 0 to bucket 2 // probability of reassignment is equal to 1/3 ``` -------------------------------- ### Consistent Bucket Set Hashing with Dynamic Buckets Source: https://github.com/dynatrace-oss/hash4j/blob/main/README.md Utilize ConsistentBucketSetHasher for scenarios where buckets can be added or removed dynamically. This requires managing the hasher's state for distributed consistency. Examples show adding buckets, removing a bucket, and re-initializing a hasher from its state. ```java List keys = asList(0x48ac502166f761a8L, 0x9b7193f97ec9cb79L, 0x6ce88bf7de8c06c2L); // create a consistent bucket set hasher var hasher = ConsistentHashing.jumpBackAnchorHash(PseudoRandomGeneratorProvider.splitMix64_V1()); // add 3 buckets int bucket1 = hasher.addBucket(); // == 0 int bucket2 = hasher.addBucket(); // == 1 int bucket3 = hasher.addBucket(); // == 2 // determine mapping of keys to the 3 buckets var mapping3 = keys.stream().collect(groupingBy(k -> hasher.getBucket(k), mapping(Long::toHexString, toList()))); // gives {0=[9b7193f97ec9cb79], 1=[48ac502166f761a8], 2=[6ce88bf7de8c06c2]} // remove bucket 2 hasher.removeBucket(bucket2); // determine mapping of keys to remaining 2 buckets var mapping2 = keys.stream().collect(groupingBy(k -> hasher.getBucket(k), mapping(Long::toHexString, toList()))); // gives {0=[9b7193f97ec9cb79], 2=[48ac502166f761a8, 6ce88bf7de8c06c2]} // key 48ac502166f761a8 got reassigned from bucket 1 to bucket 2 // get state of hasher byte[] state = hasher.getState(); // create another instance with same mapping var otherHasher = ConsistentHashing.jumpBackAnchorHash(PseudoRandomGeneratorProvider.splitMix64_V1()).setState(state); // determine mapping of keys using other instance var otherMapping2 = keys.stream().collect(groupingBy(k -> otherHasher.getBucket(k), mapping(Long::toHexString, toList()))); // gives again {0=[9b7193f97ec9cb79], 2=[48ac502166f761a8, 6ce88bf7de8c06c2]} ``` -------------------------------- ### com.dynatrace.hash4j.hashing.HashStream Interface Source: https://github.com/dynatrace-oss/hash4j/blob/main/doc/apidiffs/v0.3.1___v0.4.0.txt Details about the HashStream interface, including new methods for getting hash values and putting data. ```APIDOC ## INTERFACE com.dynatrace.hash4j.hashing.HashStream ### Description This interface represents a stream for hashing data. ### Methods - **get()** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashValue128 - **getAsInt()** - PUBLIC ABSTRACT int - **getAsLong()** - PUBLIC ABSTRACT long - **getHashBitSize()** - PUBLIC ABSTRACT int - **put(java.lang.Object, com.dynatrace.hash4j.hashing.HashFunnel)** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashStream - **putBoolean(boolean)** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashStream - **putBooleanArray(boolean[])** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashStream - **putBooleans(boolean[])** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashStream - **putBooleans(boolean[], int, int)** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashStream ### Superclass - java.lang.Object ### Implements - com.dynatrace.hash4j.hashing.HashSink ``` -------------------------------- ### Create and Use UltraLogLog Sketch Source: https://github.com/dynatrace-oss/hash4j/blob/main/README.md Demonstrates how to create an UltraLogLog sketch, add elements using a hasher, and retrieve the distinct count estimate. The sketch is initialized with a precision parameter determining its standard error and memory usage. ```java Hasher64 hasher = Hashing.komihash5_0(); // create a hasher instance UltraLogLog sketch = UltraLogLog.create(12); // corresponds to a standard error of 1.2% and requires 4kB sketch.add(hasher.hashCharsToLong("foo")); sketch.add(hasher.hashCharsToLong("bar")); sketch.add(hasher.hashCharsToLong("foo")); double distinctCountEstimate = sketch.getDistinctCountEstimate(); // gives a value close to 2 ``` -------------------------------- ### Hash a File using Imohash Source: https://github.com/dynatrace-oss/hash4j/blob/main/README.md This snippet demonstrates how to hash a file using the Imohash algorithm provided by the library. Ensure the file exists before hashing. ```java // create some file in the given path File file = path.resolve("test.txt").toFile(); try (FileWriter fileWriter = new FileWriter(file, StandardCharsets.UTF_8)) { fileWriter.write("this is the file content"); } // use ImoHash to hash that file HashValue128 hash = FileHashing.imohash1_0_2().hashFileTo128Bits(file); // returns 0xd317f2dad6ea7ae56ff7fdb517e33918 ``` -------------------------------- ### New Interface: ConsistentBucketSetHasher Source: https://github.com/dynatrace-oss/hash4j/blob/main/doc/apidiffs/v0.21.0___v0.22.0.txt Details the newly added abstract interface ConsistentBucketSetHasher and its methods. ```APIDOC ## New Interface: PUBLIC(+) ABSTRACT(+) com.dynatrace.hash4j.consistent.ConsistentBucketSetHasher ### Description This interface defines methods for managing a set of buckets in a consistent hashing context. ### Methods - `int addBucket()`: Adds a new bucket and returns its identifier. - `int getBucket(long)`: Retrieves the bucket identifier for a given long value. - `int[] getBuckets()`: Returns an array of all current bucket identifiers. - `int getNumBuckets()`: Gets the total number of buckets. - `byte[] getState()`: Retrieves the current state of the hasher as a byte array. - `boolean removeBucket(int)`: Removes a bucket by its identifier. - `com.dynatrace.hash4j.consistent.ConsistentBucketSetHasher setState(byte[])`: Sets the state of the hasher from a byte array. ``` -------------------------------- ### HashStream64 Methods Source: https://github.com/dynatrace-oss/hash4j/blob/main/doc/apidiffs/v0.6.2___v0.7.0.txt Methods for putting data into a 64-bit hash stream. ```APIDOC ## HashStream64 Methods ### Description Methods for adding primitive types, arrays, and objects to a 64-bit hash stream. ### Methods - `getAsLong()` - `put(java.lang.Object, com.dynatrace.hash4j.hashing.HashFunnel)` - `putBoolean(boolean)` - `putBooleanArray(boolean[])` - `putBooleans(boolean[])` - `putBooleans(boolean[], int, int)` - `putByte(byte)` - `putByteArray(byte[])` - `putBytes(byte[])` - `putBytes(byte[], int, int)` - `putChar(char)` - `putCharArray(char[])` - `putChars(char[])` - `putChars(char[], int, int)` - `putChars(java.lang.CharSequence)` - `putDouble(double)` - `putDoubleArray(double[])` - `putDoubles(double[])` - `putDoubles(double[], int, int)` - `putFloat(float)` - `putFloatArray(float[]) ``` -------------------------------- ### HashStream32 Methods Source: https://github.com/dynatrace-oss/hash4j/blob/main/doc/apidiffs/v0.6.2___v0.7.0.txt Methods for putting data into a 32-bit hash stream. ```APIDOC ## HashStream32 Methods ### Description Methods for adding primitive types, arrays, and objects to a 32-bit hash stream. ### Methods - `putLong(long)` - `putLongArray(long[])` - `putLongs(long[])` - `putLongs(long[], int, int)` - `putNullable(java.lang.Object, com.dynatrace.hash4j.hashing.HashFunnel)` - `putOptional(java.util.Optional, com.dynatrace.hash4j.hashing.HashFunnel)` - `putOptionalDouble(java.util.OptionalDouble)` - `putOptionalInt(java.util.OptionalInt)` - `putOptionalLong(java.util.OptionalLong)` - `putShort(short)` - `putShortArray(short[])` - `putShorts(short[])` - `putShorts(short[], int, int)` - `putString(java.lang.String)` - `putUnorderedIterable(java.lang.Iterable, java.util.function.ToLongFunction)` - `putUnorderedIterable(java.lang.Iterable, com.dynatrace.hash4j.hashing.HashFunnel, com.dynatrace.hash4j.hashing.Hasher64)` - `putUUID(java.util.UUID)` - `reset() ``` -------------------------------- ### ConsistentHashing Class Source: https://github.com/dynatrace-oss/hash4j/blob/main/doc/apidiffs/v0.8.0___v0.9.0.txt Introduces the new ConsistentHashing class and its static factory method. ```APIDOC ## Class com.dynatrace.hash4j.consistent.ConsistentHashing ### Description Provides utilities for consistent hashing. ### Methods - **jumpHash**(com.dynatrace.hash4j.random.PseudoRandomGeneratorProvider provider): com.dynatrace.hash4j.consistent.ConsistentBucketHasher - Creates a new ConsistentBucketHasher using the jump consistent hash algorithm. ``` -------------------------------- ### New Interface: ByteAccess Source: https://github.com/dynatrace-oss/hash4j/blob/main/doc/apidiffs/v0.25.0___v0.26.0.txt Introduces the new ByteAccess interface with methods for accessing byte data. ```APIDOC ## New Interface: PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.ByteAccess ### Description This interface provides methods for accessing byte data from an object. ### Methods - **copyToByteArray**(java.lang.Object, long, byte[], int, int): Copies bytes from the source object to a byte array. - **getByte**(java.lang.Object, long): Retrieves a single byte from the source object at the specified offset. - **getByteAsUnsignedInt**(java.lang.Object, long): Retrieves a single byte as an unsigned integer. - **getByteAsUnsignedLong**(java.lang.Object, long): Retrieves a single byte as an unsigned long. - **getInt**(java.lang.Object, long): Retrieves an integer from the source object at the specified offset. - **getIntAsUnsignedLong**(java.lang.Object, long): Retrieves an integer as an unsigned long. - **getLong**(java.lang.Object, long): Retrieves a long from the source object at the specified offset. ``` -------------------------------- ### Hasher64 Interface Source: https://github.com/dynatrace-oss/hash4j/blob/main/doc/apidiffs/v0.1.0___v0.2.0.txt Details the methods available for 64-bit hashing. ```APIDOC ## INTERFACE com.dynatrace.hash4j.hashing.Hasher64 ### Description Interface for 64-bit hashing operations. ### Methods - **hashBytesToLong**(byte[] data) - Returns a 64-bit long hash value for the given byte array. - **hashBytesToLong**(byte[] data, int offset, int length) - Returns a 64-bit long hash value for a portion of the byte array. ``` -------------------------------- ### com.dynatrace.hash4j.hashing.Hasher64 Interface Source: https://github.com/dynatrace-oss/hash4j/blob/main/doc/apidiffs/v0.3.1___v0.4.0.txt Details about the Hasher64 interface, including new methods. ```APIDOC ## INTERFACE com.dynatrace.hash4j.hashing.Hasher64 ### Description This interface extends Hasher and provides 64-bit hashing capabilities. ### Methods - **hashCharsToLong(java.lang.CharSequence)** - PUBLIC ABSTRACT long ``` -------------------------------- ### Preconditions Utility Class Source: https://github.com/dynatrace-oss/hash4j/blob/main/doc/apidiffs/v0.5.0___v0.6.0.txt Documentation for the Preconditions utility class, used for argument and state validation. ```APIDOC ## Preconditions Utility Class ### Description A utility class for enforcing preconditions on method arguments and object states. ### Static Methods #### `public static void checkArgument(boolean expression)` Checks if the expression is true, throwing an `IllegalArgumentException` if it is false. #### `public static void checkArgument(boolean expression, String errorMessage)` Checks if the expression is true, throwing an `IllegalArgumentException` with the given error message if it is false. #### `public static void checkArgument(boolean expression, String errorMessage, long value)` Checks if the expression is true, throwing an `IllegalArgumentException` with the given error message and value if it is false. #### `public static void checkState(boolean expression)` Checks if the expression is true, throwing an `IllegalStateException` if it is false. ``` -------------------------------- ### com.dynatrace.hash4j.hashing.Hasher32 Interface Source: https://github.com/dynatrace-oss/hash4j/blob/main/doc/apidiffs/v0.3.1___v0.4.0.txt Details about the Hasher32 interface, including new methods. ```APIDOC ## INTERFACE com.dynatrace.hash4j.hashing.Hasher32 ### Description This interface extends Hasher and provides 32-bit hashing capabilities. ### Methods - **hashCharsToInt(java.lang.CharSequence)** - PUBLIC ABSTRACT int ``` -------------------------------- ### Hashing Java Objects with hash4j Source: https://github.com/dynatrace-oss/hash4j/blob/main/README.md Demonstrates multiple ways to hash Java objects using hash4j's streaming API and funnels. This approach minimizes memory allocations and is efficient for large objects. ```java class TestClass { int a = 42; long b = 1234567890L; String c = "Hello world!"; } TestClass obj = new TestClass(); // create an instance of some test class var hasher = Hashing.komihash5_0(); // create a hasher instance (can be static) // variant 1: hash object by passing data into a hash stream long hash1 = hasher.hashStream().putInt(obj.a).putLong(obj.b).putString(obj.c).getAsLong(); // gives 0x90553fd9c675dfb2L // variant 2: hash object by defining a funnel HashFunnel funnel = (o, sink) -> sink.putInt(o.a).putLong(o.b).putString(o.c); long hash2 = hasher.hashToLong(obj, funnel); // gives 0x90553fd9c675dfb2L // create a hash stream instance (can be static or thread-local) var hashStream = Hashing.komihash5_0().hashStream(); // variant 3: allocation-free by reusing a pre-allocated hash stream instance long hash3 = hashStream.reset().putInt(obj.a).putLong(obj.b).putString(obj.c).getAsLong(); // gives 0x90553fd9c675dfb2L // variant 4: allocation-free and using a funnel long hash4 = hashStream.resetAndHashToLong(obj, funnel); // gives 0x90553fd9c675dfb2L ``` -------------------------------- ### Hasher32 Interface Source: https://github.com/dynatrace-oss/hash4j/blob/main/doc/apidiffs/v0.1.0___v0.2.0.txt Details the methods available for 32-bit hashing. ```APIDOC ## INTERFACE com.dynatrace.hash4j.hashing.Hasher32 ### Description Interface for 32-bit hashing operations. ### Methods - **hashBytesToInt**(byte[] data) - Returns a 32-bit integer hash value for the given byte array. - **hashBytesToInt**(byte[] data, int offset, int length) - Returns a 32-bit integer hash value for a portion of the byte array. ``` -------------------------------- ### Compute and Compare SuperMinHash Signatures Source: https://github.com/dynatrace-oss/hash4j/blob/main/README.md This snippet shows how to compute SuperMinHash signatures for two sets and estimate their Jaccard similarity. It requires setting up a hashing function, defining the policy for SuperMinHash, and then computing and comparing the signatures. ```java ToLongFunction stringHashFunc = s -> Hashing.komihash5_0().hashCharsToLong(s); Set setA = IntStream.range(0, 90000).mapToObj(Integer::toString).collect(toSet()); Set setB = IntStream.range(10000, 100000).mapToObj(Integer::toString).collect(toSet()); // intersection size = 80000, union size = 100000 // => exact Jaccard similarity of sets A and B is J = 80000 / 100000 = 0.8 int numberOfComponents = 1024; int bitsPerComponent = 1; // => each signature will take 1 * 1024 bits = 128 bytes SimilarityHashPolicy policy = SimilarityHashing.superMinHash(numberOfComponents, bitsPerComponent); SimilarityHasher simHasher = policy.createHasher(); byte[] signatureA = simHasher.compute(ElementHashProvider.ofCollection(setA, stringHashFunc)); byte[] signatuerB = simHasher.compute(ElementHashProvider.ofCollection(setB, stringHashFunc)); double fractionOfEqualComponents = policy.getFractionOfEqualComponents(signatureA, signatuerB); // this formula estimates the Jaccard similarity from the fraction of equal components double estimatedJaccardSimilarity = (fractionOfEqualComponents - Math.pow(2., -bitsPerComponent)) / (1. - Math.pow(2., -bitsPerComponent)); // gives a value close to 0.8 ``` -------------------------------- ### HashStream32 Methods Source: https://github.com/dynatrace-oss/hash4j/blob/main/doc/apidiffs/v0.6.2___v0.7.0.txt This section details the methods available on the HashStream32 interface for hashing various data types. ```APIDOC ## HashStream32 API ### Description Provides methods to hash primitive data types, arrays, and other objects. ### Methods #### `put(Object, HashFunnel)` - **Description**: Puts an object into the hash stream using a provided HashFunnel. - **Parameters**: - `Object` (Object) - Required - The object to hash. - `HashFunnel` (com.dynatrace.hash4j.hashing.HashFunnel) - Required - The funnel to use for hashing the object. #### `putBoolean(boolean)` - **Description**: Puts a boolean value into the hash stream. - **Parameters**: - `boolean` (boolean) - Required - The boolean value. #### `putBooleanArray(boolean[])` - **Description**: Puts a boolean array into the hash stream. - **Parameters**: - `boolean[]` (boolean[]) - Required - The boolean array. #### `putBooleans(boolean[])` - **Description**: Puts a boolean array into the hash stream. - **Parameters**: - `boolean[]` (boolean[]) - Required - The boolean array. #### `putBooleans(boolean[], int, int)` - **Description**: Puts a portion of a boolean array into the hash stream. - **Parameters**: - `boolean[]` (boolean[]) - Required - The boolean array. - `int` (int) - Required - The offset. - `int` (int) - Required - The length. #### `putByte(byte)` - **Description**: Puts a byte value into the hash stream. - **Parameters**: - `byte` (byte) - Required - The byte value. #### `putByteArray(byte[])` - **Description**: Puts a byte array into the hash stream. - **Parameters**: - `byte[]` (byte[]) - Required - The byte array. #### `putBytes(byte[])` - **Description**: Puts a byte array into the hash stream. - **Parameters**: - `byte[]` (byte[]) - Required - The byte array. #### `putBytes(byte[], int, int)` - **Description**: Puts a portion of a byte array into the hash stream. - **Parameters**: - `byte[]` (byte[]) - Required - The byte array. - `int` (int) - Required - The offset. - `int` (int) - Required - The length. #### `putChar(char)` - **Description**: Puts a character value into the hash stream. - **Parameters**: - `char` (char) - Required - The character value. #### `putCharArray(char[])` - **Description**: Puts a character array into the hash stream. - **Parameters**: - `char[]` (char[]) - Required - The character array. #### `putChars(char[])` - **Description**: Puts a character array into the hash stream. - **Parameters**: - `char[]` (char[]) - Required - The character array. #### `putChars(char[], int, int)` - **Description**: Puts a portion of a character array into the hash stream. - **Parameters**: - `char[]` (char[]) - Required - The character array. - `int` (int) - Required - The offset. - `int` (int) - Required - The length. #### `putChars(CharSequence)` - **Description**: Puts a character sequence into the hash stream. - **Parameters**: - `CharSequence` (java.lang.CharSequence) - Required - The character sequence. #### `putDouble(double)` - **Description**: Puts a double value into the hash stream. - **Parameters**: - `double` (double) - Required - The double value. #### `putDoubleArray(double[])` - **Description**: Puts a double array into the hash stream. - **Parameters**: - `double[]` (double[]) - Required - The double array. #### `putDoubles(double[])` - **Description**: Puts a double array into the hash stream. - **Parameters**: - `double[]` (double[]) - Required - The double array. #### `putDoubles(double[], int, int)` - **Description**: Puts a portion of a double array into the hash stream. - **Parameters**: - `double[]` (double[]) - Required - The double array. - `int` (int) - Required - The offset. - `int` (int) - Required - The length. #### `putFloat(float)` - **Description**: Puts a float value into the hash stream. - **Parameters**: - `float` (float) - Required - The float value. #### `putFloatArray(float[])` - **Description**: Puts a float array into the hash stream. - **Parameters**: - `float[]` (float[]) - Required - The float array. #### `putFloats(float[])` - **Description**: Puts a float array into the hash stream. - **Parameters**: - `float[]` (float[]) - Required - The float array. #### `putFloats(float[], int, int)` - **Description**: Puts a portion of a float array into the hash stream. - **Parameters**: - `float[]` (float[]) - Required - The float array. - `int` (int) - Required - The offset. - `int` (int) - Required - The length. #### `putInt(int)` - **Description**: Puts an integer value into the hash stream. - **Parameters**: - `int` (int) - Required - The integer value. #### `putIntArray(int[])` - **Description**: Puts an integer array into the hash stream. - **Parameters**: - `int[]` (int[]) - Required - The integer array. #### `putInts(int[])` - **Description**: Puts an integer array into the hash stream. - **Parameters**: - `int[]` (int[]) - Required - The integer array. #### `putInts(int[], int, int)` - **Description**: Puts a portion of an integer array into the hash stream. - **Parameters**: - `int[]` (int[]) - Required - The integer array. - `int` (int) - Required - The offset. - `int` (int) - Required - The length. ### Response - **Success Response (200)**: Returns the `HashStream32` instance for chaining. ### Request Example ```java HashStream32 hashStream = ...; hashStream.putInt(123); hashStream.putString("hello"); ``` ### Response Example ```java // The method returns the HashStream32 instance itself for chaining. ``` ``` -------------------------------- ### ConsistentBucketHasher Interface Source: https://github.com/dynatrace-oss/hash4j/blob/main/doc/apidiffs/v0.8.0___v0.9.0.txt Details the new ConsistentBucketHasher interface and its methods. ```APIDOC ## Interface com.dynatrace.hash4j.consistent.ConsistentBucketHasher ### Description Represents a consistent bucket hasher. ### Methods - **getBucket**(long key, int numBuckets): int - Calculates the bucket for a given key and number of buckets. ``` -------------------------------- ### HashStream32 Methods Source: https://github.com/dynatrace-oss/hash4j/blob/main/doc/apidiffs/v0.6.2___v0.7.0.txt Methods for adding data to a 32-bit hash stream. ```APIDOC ## HashStream32 Methods ### Description Methods for adding various data types to a 32-bit hash stream. ### Methods - `putLongArray(long[])` - `putLongs(long[])` - `putLongs(long[], int, int)` - `putNullable(java.lang.Object, com.dynatrace.hash4j.hashing.HashFunnel)` - `putOptional(java.util.Optional, com.dynatrace.hash4j.hashing.HashFunnel)` - `putOptionalDouble(java.util.OptionalDouble)` - `putOptionalInt(java.util.OptionalInt)` - `putOptionalLong(java.util.OptionalLong)` - `putOrderedIterable(java.lang.Iterable, com.dynatrace.hash4j.hashing.HashFunnel)` - `putShort(short)` - `putShortArray(short[])` - `putShorts(short[])` - `putShorts(short[], int, int)` - `putString(java.lang.String)` - `putUnorderedIterable(java.lang.Iterable, com.dynatrace.hash4j.hashing.HashFunnel, com.dynatrace.hash4j.hashing.Hasher64)` - `putUnorderedIterable(java.lang.Iterable, java.util.function.ToLongFunction)` - `putUUID(java.util.UUID)` ``` -------------------------------- ### HashStream Put Methods Source: https://github.com/dynatrace-oss/hash4j/blob/main/doc/apidiffs/v0.3.1___v0.4.0.txt This section details the various `put` methods available in the HashStream interface for adding different data types to the hash computation. ```APIDOC ## HashStream Put Methods ### Description Methods for adding primitive types, arrays, and other data structures to the hash stream. ### Methods #### `putByte(byte)` Adds a single byte to the hash stream. #### `putByteArray(byte[])` Adds an array of bytes to the hash stream. #### `putBytes(byte[])` Adds a byte array to the hash stream. #### `putBytes(byte[], int, int)` Adds a portion of a byte array to the hash stream. #### `putChar(char)` Adds a single character to the hash stream. #### `putCharArray(char[])` Adds an array of characters to the hash stream. #### `putChars(char[])` Adds a character array to the hash stream. #### `putChars(char[], int, int)` Adds a portion of a character array to the hash stream. #### `putChars(java.lang.CharSequence)` Adds a character sequence (e.g., String) to the hash stream. #### `putDouble(double)` Adds a double-precision floating-point number to the hash stream. #### `putDoubleArray(double[])` Adds an array of double-precision floating-point numbers to the hash stream. #### `putDoubles(double[])` Adds a double array to the hash stream. #### `putDoubles(double[], int, int)` Adds a portion of a double array to the hash stream. #### `putFloat(float)` Adds a single-precision floating-point number to the hash stream. #### `putFloatArray(float[])` Adds an array of single-precision floating-point numbers to the hash stream. #### `putFloats(float[])` Adds a float array to the hash stream. #### `putFloats(float[], int, int)` Adds a portion of a float array to the hash stream. #### `putInt(int)` Adds an integer to the hash stream. #### `putIntArray(int[])` Adds an array of integers to the hash stream. #### `putInts(int[])` Adds an integer array to the hash stream. #### `putInts(int[], int, int)` Adds a portion of an integer array to the hash stream. #### `putLong(long)` Adds a long integer to the hash stream. #### `putLongArray(long[])` Adds an array of long integers to the hash stream. #### `putLongs(long[])` Adds a long array to the hash stream. #### `putLongs(long[], int, int)` Adds a portion of a long array to the hash stream. #### `putNullable(java.lang.Object, com.dynatrace.hash4j.hashing.HashFunnel)` Adds a nullable object to the hash stream using a provided HashFunnel. #### `putOptional(java.util.Optional, com.dynatrace.hash4j.hashing.HashFunnel)` Adds an Optional object to the hash stream using a provided HashFunnel. #### `putOptionalDouble(java.util.OptionalDouble)` Adds an OptionalDouble to the hash stream. #### `putOptionalInt(java.util.OptionalInt)` Adds an OptionalInt to the hash stream. #### `putOptionalLong(java.util.OptionalLong)` Adds an OptionalLong to the hash stream. #### `putOrderedIterable(java.lang.Iterable, com.dynatrace.hash4j.hashing.HashFunnel)` Adds elements from an ordered iterable to the hash stream using a provided HashFunnel. #### `putShort(short)` Adds a short integer to the hash stream. #### `putShortArray(short[])` Adds an array of short integers to the hash stream. #### `putShorts(short[])` Adds a short array to the hash stream. #### `putShorts(short[], int, int)` Adds a portion of a short array to the hash stream. #### `putString(java.lang.String)` Adds a string to the hash stream. #### `putUnorderedIterable(java.lang.Iterable, java.util.function.ToLongFunction)` Adds elements from an unordered iterable to the hash stream using a ToLongFunction. #### `putUnorderedIterable(java.lang.Iterable, com.dynatrace.hash4j.hashing.HashFunnel, java.util.function.Supplier)` Adds elements from an unordered iterable to the hash stream using a HashFunnel and a Hasher64 supplier. #### `putUUID(java.util.UUID)` Adds a UUID to the hash stream. ### Parameters - **byte b**: The byte value to add. - **byte[] arr**: The byte array to add. - **int offset**: The starting offset in the array. - **int length**: The number of elements to add. - **char c**: The character value to add. - **char[] arr**: The character array to add. - **java.lang.CharSequence cs**: The character sequence to add. - **double d**: The double value to add. - **double[] arr**: The double array to add. - **float f**: The float value to add. - **float[] arr**: The float array to add. - **int i**: The integer value to add. - **int[] arr**: The integer array to add. - **long l**: The long value to add. - **long[] arr**: The long array to add. - **java.lang.Object obj**: The nullable object to add. - **com.dynatrace.hash4j.hashing.HashFunnel funnel**: The HashFunnel to use for hashing the object. - **java.util.Optional optional**: The Optional object to add. - **com.dynatrace.hash4j.hashing.HashFunnel optionalFunnel**: The HashFunnel for the Optional's content. - **java.util.OptionalDouble optionalDouble**: The OptionalDouble to add. - **java.util.OptionalInt optionalInt**: The OptionalInt to add. - **java.util.OptionalLong optionalLong**: The OptionalLong to add. - **java.lang.Iterable iterable**: The iterable to add. - **com.dynatrace.hash4j.hashing.HashFunnel iterableFunnel**: The HashFunnel for the iterable's elements. - **short s**: The short value to add. - **short[] arr**: The short array to add. - **java.lang.String str**: The string to add. - **java.util.function.ToLongFunction toLongFunction**: The function to convert elements to long. - **java.util.function.Supplier hasherSupplier**: Supplier for the Hasher64. - **java.util.UUID uuid**: The UUID to add. ### Return Value Each method returns the `HashStream` instance itself to allow for method chaining. ### Example ```java // Example for putByte HashStream stream = ...; byte data = 10; stream.putByte(data); // Example for putString stream.putString("Hello Hash4j"); // Example for putIntArray int[] numbers = {1, 2, 3}; stream.putIntArray(numbers); // Example for putNullable Object obj = null; HashFunnel objectFunnel = ...; stream.putNullable(obj, objectFunnel); // Example for putOrderedIterable List list = Arrays.asList("a", "b", "c"); HashFunnel stringFunnel = ...; stream.putOrderedIterable(list, stringFunnel); ``` ``` -------------------------------- ### New Class: com.dynatrace.hash4j.distinctcount.HyperLogLog Source: https://github.com/dynatrace-oss/hash4j/blob/main/doc/apidiffs/v0.6.2___v0.7.0.txt Details the new HyperLogLog class and its methods, including creation, state management, and distinct count estimation. ```APIDOC ## New Class: com.dynatrace.hash4j.distinctcount.HyperLogLog ### Description This class represents a HyperLogLog data structure for distinct count estimation. It is not serializable. ### Methods - **add(long)**: Adds a long value to the HyperLogLog structure. - **add(HyperLogLog)**: Merges another HyperLogLog structure into this one. - **copy()**: Creates a copy of the current HyperLogLog structure. - **create(int)**: Creates a new HyperLogLog structure with a specified precision parameter `p`. - **create(UltraLogLog)**: Creates a new HyperLogLog structure from an UltraLogLog structure. - **downsize(int)**: Reduces the precision of the HyperLogLog structure to a new value `p`. - **getDistinctCountEstimate()**: Returns the estimated number of distinct elements. - **getP()**: Returns the precision parameter `p` of the HyperLogLog structure. - **getState()**: Returns the internal state of the HyperLogLog structure as a byte array. - **merge(HyperLogLog, HyperLogLog)**: Static method to merge two HyperLogLog structures. - **reset()**: Resets the HyperLogLog structure, clearing all added elements. - **wrap(byte[])**: Creates a HyperLogLog structure from a given byte array representing its state. ``` -------------------------------- ### AbstractHashStream64 Methods Source: https://github.com/dynatrace-oss/hash4j/blob/main/doc/apidiffs/v0.6.2___v0.7.0.txt Methods for adding data to a 64-bit hash stream and retrieving hash values. ```APIDOC ## AbstractHashStream64 Methods ### Description Methods for initializing and interacting with a 64-bit abstract hash stream. ### Constructor - `AbstractHashStream64()` ### Methods - `getAsInt()`: Retrieves the hash value as an integer. - `getHashBitSize()`: Returns the bit size of the hash. - `put(java.lang.Object, com.dynatrace.hash4j.hashing.HashFunnel)`: Puts an object into the stream using a provided HashFunnel. - `putBoolean(boolean)`: Puts a boolean value. - `putBooleanArray(boolean[])`: Puts a boolean array. - `putBooleans(boolean[])`: Puts a boolean array. - `putBooleans(boolean[], int, int)`: Puts a portion of a boolean array. - `putByteArray(byte[])`: Puts a byte array. - `putBytes(byte[])`: Puts a byte array. - `putBytes(byte[], int, int)`: Puts a portion of a byte array. - `putChar(char)`: Puts a character. - `putCharArray(char[])`: Puts a character array. - `putChars(char[])`: Puts a character array. - `putChars(char[], int, int)`: Puts a portion of a character array. - `putChars(java.lang.CharSequence)`: Puts a character sequence. - `putDouble(double)`: Puts a double value. - `putDoubleArray(double[])`: Puts a double array. - `putDoubles(double[])`: Puts a double array. - `putDoubles(double[], int, int)`: Puts a portion of a double array. - `putFloat(float)`: Puts a float value. - `putFloatArray(float[])`: Puts a float array. - `putFloats(float[])`: Puts a float array. - `putFloats(float[], int, int)`: Puts a portion of a float array. - `putInt(int)`: Puts an integer value. ``` -------------------------------- ### HashStream64 Methods Source: https://github.com/dynatrace-oss/hash4j/blob/main/doc/apidiffs/v0.6.2___v0.7.0.txt Methods for adding data to a HashStream64 for hashing. ```APIDOC ## HashStream64 Methods ### Description Methods for adding various data types to a `HashStream64` for hashing purposes. ### Methods - `putIntArray(int[])`: Adds an array of integers. - `putInts(int[])`: Adds multiple integers from an array. - `putInts(int[], int, int)`: Adds a range of integers from an array. - `putLong(long)`: Adds a single long value. - `putLongArray(long[])`: Adds an array of long values. - `putLongs(long[])`: Adds multiple long values from an array. - `putLongs(long[], int, int)`: Adds a range of long values from an array. - `putNullable(java.lang.Object, com.dynatrace.hash4j.hashing.HashFunnel)`: Adds a nullable object with a provided HashFunnel. - `putOptional(java.util.Optional, com.dynatrace.hash4j.hashing.HashFunnel)`: Adds an Optional object with a provided HashFunnel. - `putOptionalDouble(java.util.OptionalDouble)`: Adds an OptionalDouble. - `putOptionalInt(java.util.OptionalInt)`: Adds an OptionalInt. - `putOptionalLong(java.util.OptionalLong)`: Adds an OptionalLong. - `putOrderedIterable(java.lang.Iterable, com.dynatrace.hash4j.hashing.HashFunnel)`: Adds elements from an ordered iterable. - `putShort(short)`: Adds a single short value. - `putShortArray(short[])`: Adds an array of short values. - `putShorts(short[])`: Adds multiple short values from an array. - `putShorts(short[], int, int)`: Adds a range of short values from an array. - `putString(java.lang.String)`: Adds a string. - `putUnorderedIterable(java.lang.Iterable, com.dynatrace.hash4j.hashing.HashFunnel, com.dynatrace.hash4j.hashing.Hasher64)`: Adds elements from an unordered iterable with a specified Hasher64. - `putUnorderedIterable(java.lang.Iterable, java.util.function.ToLongFunction)`: Adds elements from an unordered iterable using a ToLongFunction. - `putUUID(java.util.UUID)`: Adds a UUID. ``` -------------------------------- ### Hashing Class Source: https://github.com/dynatrace-oss/hash4j/blob/main/doc/apidiffs/v0.1.0___v0.2.0.txt Provides static methods to obtain instances of different hashers. ```APIDOC ## CLASS com.dynatrace.hash4j.hashing.Hashing ### Description Provides factory methods for creating Hasher instances. ### Methods - **murmur3_32**() - Returns a new instance of a 32-bit Murmur3 hasher. - **murmur3_32**(int seed) - Returns a new instance of a 32-bit Murmur3 hasher with a specified seed. - **wyhashFinal3**() - Returns a new instance of a 64-bit Wyhash Final 3 hasher. - **wyhashFinal3**(long seed) - Returns a new instance of a 64-bit Wyhash Final 3 hasher with a specified seed. - **wyhashFinal3**(long seed1, long seed2) - Returns a new instance of a 64-bit Wyhash Final 3 hasher with two specified seeds. ``` -------------------------------- ### Regenerate Python Requirements with Hash Pinning Source: https://github.com/dynatrace-oss/hash4j/blob/main/README.md Regenerate the hash-pinned requirements.txt file from requirements.in using pip-tools. This command should be run when requirements.in is modified to update dependencies and their hashes. ```bash python -m pip install pip-tools pip-compile --generate-hashes --allow-unsafe --no-strip-extras --output-file requirements.txt requirements.in ``` -------------------------------- ### com.dynatrace.hash4j.similarity.MinHashVersion Source: https://github.com/dynatrace-oss/hash4j/blob/main/doc/apidiffs/v0.5.0___v0.6.0.txt Details the new MinHashVersion enum. ```APIDOC ## NEW ENUM: PUBLIC ABSTRACT com.dynatrace.hash4j.similarity.MinHashVersion ### Description Enumeration for different versions of MinHash. ### Fields - **V1**: PUBLIC STATIC FINAL com.dynatrace.hash4j.similarity.MinHashVersion - The first version of MinHash. - **DEFAULT**: PUBLIC STATIC FINAL com.dynatrace.hash4j.similarity.MinHashVersion - The default version of MinHash. ### Methods - **valueOf**(java.lang.String) - static com.dynatrace.hash4j.similarity.MinHashVersion - Returns the enum constant with the specified name. - **values**() - static com.dynatrace.hash4j.similarity.MinHashVersion[] - Returns an array containing the constants of this enum type. ``` -------------------------------- ### com.dynatrace.hash4j.hashing.HashSink Interface Source: https://github.com/dynatrace-oss/hash4j/blob/main/doc/apidiffs/v0.3.1___v0.4.0.txt Details about the HashSink interface, including newly added methods for various data types. ```APIDOC ## INTERFACE com.dynatrace.hash4j.hashing.HashSink ### Description This interface defines methods for sinking hash data. ### Methods - **putBooleanArray(boolean[])** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashSink - **putBooleans(boolean[])** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashSink - **putBooleans(boolean[], int, int)** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashSink - **putByteArray(byte[])** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashSink - **putCharArray(char[])** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashSink - **putChars(char[])** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashSink - **putChars(char[], int, int)** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashSink - **putDoubleArray(double[])** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashSink - **putDoubles(double[])** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashSink - **putDoubles(double[], int, int)** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashSink - **putFloatArray(float[])** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashSink - **putFloats(float[])** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashSink - **putFloats(float[], int, int)** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashSink - **putIntArray(int[])** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashSink - **putInts(int[])** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashSink - **putInts(int[], int, int)** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashSink - **putLongArray(long[])** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashSink - **putLongs(long[])** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashSink - **putLongs(long[], int, int)** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashSink - **putShortArray(short[])** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashSink - **putShorts(short[])** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashSink - **putShorts(short[], int, int)** - PUBLIC ABSTRACT com.dynatrace.hash4j.hashing.HashSink ``` -------------------------------- ### com.dynatrace.hash4j.random.PseudoRandomGeneratorProvider Source: https://github.com/dynatrace-oss/hash4j/blob/main/doc/apidiffs/v0.5.0___v0.6.0.txt Details the new PseudoRandomGeneratorProvider interface and its methods. ```APIDOC ## NEW INTERFACE: PUBLIC ABSTRACT com.dynatrace.hash4j.random.PseudoRandomGeneratorProvider ### Description Interface for providing pseudo-random number generators. ### Methods - **create**() - com.dynatrace.hash4j.random.PseudoRandomGenerator - Creates a new pseudo-random generator. - **splitMix64_V1**() - static com.dynatrace.hash4j.random.PseudoRandomGeneratorProvider - Returns a provider for the SplitMix64 algorithm version 1. ```