1 package net.jpountz.xxhash;
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 import static net.jpountz.util.ByteBufferUtils.checkRange;
18 import static net.jpountz.util.SafeUtils.checkRange;
20 import java.nio.ByteBuffer;
22 final class XXHash64JNI extends XXHash64 {
24 public static final XXHash64 INSTANCE = new XXHash64JNI();
25 private static XXHash64 SAFE_INSTANCE;
28 public long hash(byte[] buf, int off, int len, long seed) {
29 checkRange(buf, off, len);
30 return XXHashJNI.XXH64(buf, off, len, seed);
34 public long hash(ByteBuffer buf, int off, int len, long seed) {
36 checkRange(buf, off, len);
37 return XXHashJNI.XXH64BB(buf, off, len, seed);
38 } else if (buf.hasArray()) {
39 return hash(buf.array(), off + buf.arrayOffset(), len, seed);
41 XXHash64 safeInstance = SAFE_INSTANCE;
42 if (safeInstance == null) {
43 safeInstance = SAFE_INSTANCE = XXHashFactory.safeInstance().hash64();
45 return safeInstance.hash(buf, off, len, seed);