]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.lz4/src/net/jpountz/xxhash/XXHash32.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.lz4 / src / net / jpountz / xxhash / XXHash32.java
1 package net.jpountz.xxhash;
2
3 import java.nio.ByteBuffer;
4
5 /*
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 /**
20  * A 32-bits hash.
21  * <p>
22  * Instances of this class are thread-safe.
23  */
24 public abstract class XXHash32 {
25
26   /**
27    * Compute the 32-bits hash of <code>buf[off:off+len]</code> using seed
28    * <code>seed</code>.
29    */
30   public abstract int hash(byte[] buf, int off, int len, int seed);
31
32   /**
33    * Compute the hash of the given slice of the {@link ByteBuffer}.
34    * {@link ByteBuffer#position() position} and {@link ByteBuffer#limit() limit}
35    * are not modified. 
36    */
37   public abstract int hash(ByteBuffer buf, int off, int len, int seed);
38
39   /**
40    * Compute the hash of the given {@link ByteBuffer}. The
41    * {@link ByteBuffer#position() position} is moved in order to reflect bytes
42    * which have been read.
43    */
44   public final int hash(ByteBuffer buf, int seed) {
45     final int hash = hash(buf, buf.position(), buf.remaining(), seed);
46     buf.position(buf.limit());
47     return hash;
48   }
49
50   @Override
51   public String toString() {
52     return getClass().getSimpleName();
53   }
54
55 }