Top Description Fields Constructors Methods
net.jpountz.xxhash

public final Class XXHashFactory

extends Object
Class Inheritance
Imports
java.lang.reflect.Field, java.util.Random, net.jpountz.util.Native, .Utils

Entry point to get XXHash32 and StreamingXXHash32 instances.

This class has 3 instances

Only the safe instance is guaranteed to work on your JVM, as a consequence it is advised to use the fastestInstance() or fastestJavaInstance() to pull a XXHashFactory instance.

All methods from this class are very costly, so you should get an instance once, and then reuse it whenever possible. This is typically done by storing a XXHashFactory instance in a static field.

Field Summary

Modifier and TypeField and Description
private final XXHash32
private final XXHash64
private final String
private static XXHashFactory
private static XXHashFactory
private static XXHashFactory
private final StreamingXXHash32.Factory
private final StreamingXXHash64.Factory

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static <T> T
public static XXHashFactory
fastestInstance()

Return the fastest available XXHashFactory instance.

public static XXHashFactory
fastestJavaInstance()

Return the fastest available XXHashFactory instance which does not rely on JNI bindings.

public XXHash32
hash32()

Return a XXHash32 instance.

public XXHash64
hash64()

Return a XXHash64 instance.

private static XXHashFactory
public static void
main(String[] args)

Prints the fastest instance.

public static synchronized XXHashFactory
nativeInstance()

Return a XXHashFactory that returns XXHash32 instances that are native bindings to the original C API.

public StreamingXXHash32
newStreamingHash32(int seed)

Return a new StreamingXXHash32 instance.

public StreamingXXHash64
newStreamingHash64(long seed)

Return a new StreamingXXHash64 instance.

public static synchronized XXHashFactory
safeInstance()

Return a XXHashFactory that returns XXHash32 instances that are written with Java's official API.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public static synchronized XXHashFactory
unsafeInstance()

Return a XXHashFactory that returns XXHash32 instances that may use sun.misc.Unsafe to speed up hashing.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

hash32back to summary
private final XXHash32 hash32
hash64back to summary
private final XXHash64 hash64
implback to summary
private final String impl
JAVA_SAFE_INSTANCEback to summary
private static XXHashFactory JAVA_SAFE_INSTANCE
JAVA_UNSAFE_INSTANCEback to summary
private static XXHashFactory JAVA_UNSAFE_INSTANCE
NATIVE_INSTANCEback to summary
private static XXHashFactory NATIVE_INSTANCE
streamingHash32Factoryback to summary
private final StreamingXXHash32.Factory streamingHash32Factory
streamingHash64Factoryback to summary
private final StreamingXXHash64.Factory streamingHash64Factory

Constructor Detail

XXHashFactoryback to summary
private XXHashFactory(String impl) throws ClassNotFoundException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException

Method Detail

classInstanceback to summary
private static <T> T classInstance(String cls) throws NoSuchFieldException, SecurityException, ClassNotFoundException, IllegalArgumentException, IllegalAccessException
Annotations
@SuppressWarnings:unchecked
fastestInstanceback to summary
public static XXHashFactory fastestInstance()

Return the fastest available XXHashFactory instance. If the class loader is the system class loader and if the native instance loads successfully, then the native instance is returned, otherwise the fastest Java instance is returned.

Please read javadocs of nativeInstance() before using this method.

fastestJavaInstanceback to summary
public static XXHashFactory fastestJavaInstance()

Return the fastest available XXHashFactory instance which does not rely on JNI bindings. It first tries to load the unsafe instance, and then the safe Java instance if the JVM doesn't have a working sun.misc.Unsafe.

hash32back to summary
public XXHash32 hash32()

Return a XXHash32 instance.

hash64back to summary
public XXHash64 hash64()

Return a XXHash64 instance.

instanceback to summary
private static XXHashFactory instance(String impl)
mainback to summary
public static void main(String[] args)

Prints the fastest instance.

nativeInstanceback to summary
public static synchronized XXHashFactory nativeInstance()

Return a XXHashFactory that returns XXHash32 instances that are native bindings to the original C API.

Please note that this instance has some traps you should be aware of:

  1. Upon loading this instance, files will be written to the temporary directory of the system. Although these files are supposed to be deleted when the JVM exits, they might remain on systems that don't support removal of files being used such as Windows.
  2. The instance can only be loaded once per JVM. This can be a problem if your application uses multiple class loaders (such as most servlet containers): this instance will only be available to the children of the class loader which has loaded it. As a consequence, it is advised to either not use this instance in webapps or to put this library in the lib directory of your servlet container so that it is loaded by the system class loader.
newStreamingHash32back to summary
public StreamingXXHash32 newStreamingHash32(int seed)

Return a new StreamingXXHash32 instance.

newStreamingHash64back to summary
public StreamingXXHash64 newStreamingHash64(long seed)

Return a new StreamingXXHash64 instance.

safeInstanceback to summary
public static synchronized XXHashFactory safeInstance()

Return a XXHashFactory that returns XXHash32 instances that are written with Java's official API.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
unsafeInstanceback to summary
public static synchronized XXHashFactory unsafeInstance()

Return a XXHashFactory that returns XXHash32 instances that may use sun.misc.Unsafe to speed up hashing.