net.jpountz.xxhash
Class XXHashFactory
- java.lang.Object
-
- net.jpountz.xxhash.XXHashFactory
-
public final class XXHashFactory extends java.lang.ObjectEntry point to getXXHash32andStreamingXXHash32instances.This class has 3 instances
- a
nativeinstance which is a JNI binding to the original LZ4 C implementation. - a
safe Javainstance which is a pure Java port of the original C library, - an
unsafe Javainstance which is a Java port using the unofficialUnsafeAPI.
Only the
safe instanceis guaranteed to work on your JVM, as a consequence it is advised to use thefastestInstance()orfastestJavaInstance()to pull aXXHashFactoryinstance.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
XXHashFactoryinstance in a static field. - a
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description static XXHashFactoryfastestInstance()Return the fastest availableXXHashFactoryinstance.static XXHashFactoryfastestJavaInstance()Return the fastest availableXXHashFactoryinstance which does not rely on JNI bindings.XXHash32hash32()Return aXXHash32instance.XXHash64hash64()Return aXXHash64instance.static voidmain(java.lang.String[] args)Prints the fastest instance.static XXHashFactorynativeInstance()Return aXXHashFactorythat returnsXXHash32instances that are native bindings to the original C API.StreamingXXHash32newStreamingHash32(int seed)Return a newStreamingXXHash32instance.StreamingXXHash64newStreamingHash64(long seed)Return a newStreamingXXHash64instance.static XXHashFactorysafeInstance()Return aXXHashFactorythat returnsXXHash32instances that are written with Java's official API.java.lang.StringtoString()static XXHashFactoryunsafeInstance()
-
-
-
Method Detail
-
nativeInstance
public static XXHashFactory nativeInstance()
Return aXXHashFactorythat returnsXXHash32instances that are native bindings to the original C API.Please note that this instance has some traps you should be aware of:
- 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.
- 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.
-
safeInstance
public static XXHashFactory safeInstance()
Return aXXHashFactorythat returnsXXHash32instances that are written with Java's official API.
-
unsafeInstance
public static XXHashFactory unsafeInstance()
-
fastestJavaInstance
public static XXHashFactory fastestJavaInstance()
Return the fastest availableXXHashFactoryinstance which does not rely on JNI bindings. It first tries to load theunsafe instance, and then thesafe Java instanceif the JVM doesn't have a workingUnsafe.
-
fastestInstance
public static XXHashFactory fastestInstance()
Return the fastest availableXXHashFactoryinstance. If the class loader is the system class loader and if thenative instanceloads successfully, then thenative instanceis returned, otherwise thefastest Java instanceis returned.Please read
javadocs of nativeInstance()before using this method.
-
newStreamingHash32
public StreamingXXHash32 newStreamingHash32(int seed)
Return a newStreamingXXHash32instance.
-
newStreamingHash64
public StreamingXXHash64 newStreamingHash64(long seed)
Return a newStreamingXXHash64instance.
-
main
public static void main(java.lang.String[] args)
Prints the fastest instance.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-
DMelt 3.0 © DataMelt by jWork.ORG