]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.lz4/src/net/jpountz/xxhash/package.html
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.lz4 / src / net / jpountz / xxhash / package.html
1 <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
2 <!--
3    Licensed under the Apache License, Version 2.0 (the "License");
4    you may not use this file except in compliance with the License.
5    You may obtain a copy of the License at
6
7        http://www.apache.org/licenses/LICENSE-2.0
8
9    Unless required by applicable law or agreed to in writing, software
10    distributed under the License is distributed on an "AS IS" BASIS,
11    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12    See the License for the specific language governing permissions and
13    limitations under the License.
14 -->
15 <html>
16 <head>
17    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
18 </head>
19 <body>
20 <p>xxhash hashing. This package supports both block hashing via
21 {@link net.jpountz.xxhash.XXHash32} and streaming hashing via
22 {@link net.jpountz.xxhash.StreamingXXHash32}. Have a look at
23 {@link net.jpountz.xxhash.XXHashFactory} to know how to get instances of these
24 interfaces.</p>
25
26 <p>Streaming hashing is a little slower but doesn't require to load the whole
27 stream into memory.</p>
28
29 <p>Sample block usage:</p>
30
31 <pre class="prettyprint">
32     XXHashFactory factory = XXHashFactory.fastestInstance();
33
34     byte[] data = "12345345234572".getBytes("UTF-8");
35
36     XXHash32 hash32 = factory.hash32();
37     int seed = 0x9747b28c; // used to initialize the hash value, use whatever
38                            // value you want, but always the same
39     int hash = hash32.hash(data, 0, data.length, seed);
40 </pre>
41
42 <p>Sample streaming usage:</p>
43
44 <pre class="prettyprint">
45     XXHashFactory factory = XXHashFactory.fastestInstance();
46
47     byte[] data = "12345345234572".getBytes("UTF-8");
48     ByteArrayInputStream in = new ByteArrayInputStream(data);
49
50     int seed = 0x9747b28c; // used to initialize the hash value, use whatever
51                            // value you want, but always the same
52     StreamingXXHash32 hash32 = factory.newStreamingHash32(seed);
53     byte[] buf = new byte[8]; // for real-world usage, use a larger buffer, like 8192 bytes
54     for (;;) {
55       int read = in.read(buf);
56       if (read == -1) {
57         break;
58       }
59       hash32.update(buf, 0, read);
60     }
61     int hash = hash32.getValue();
62 </pre>
63
64 </body>
65 </html>