1/*
2Copyright 2011 Google Inc. All Rights Reserved.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15
16Author: lode.vandevenne@gmail.com (Lode Vandevenne)
17Author: jyrki.alakuijala@gmail.com (Jyrki Alakuijala)
18*/
19
20/*
21The hash for ZopfliFindLongestMatch of lz77.c.
22*/
23
24#ifndef ZOPFLI_HASH_H_
25#define ZOPFLI_HASH_H_
26
27#include "util.h"
28
29typedef struct ZopfliHash {
30  int* head;  /* Hash value to index of its most recent occurance. */
31  unsigned short* prev;  /* Index to index of prev. occurance of same hash. */
32  int* hashval;  /* Index to hash value at this index. */
33  int val;  /* Current hash value. */
34
35#ifdef ZOPFLI_HASH_SAME_HASH
36  /* Fields with similar purpose as the above hash, but for the second hash with
37  a value that is calculated differently.  */
38  int* head2;  /* Hash value to index of its most recent occurance. */
39  unsigned short* prev2;  /* Index to index of prev. occurance of same hash. */
40  int* hashval2;  /* Index to hash value at this index. */
41  int val2;  /* Current hash value. */
42#endif
43
44#ifdef ZOPFLI_HASH_SAME
45  unsigned short* same;  /* Amount of repetitions of same byte after this .*/
46#endif
47} ZopfliHash;
48
49/* Allocates and initializes all fields of ZopfliHash. */
50void ZopfliInitHash(size_t window_size, ZopfliHash* h);
51
52/* Frees all fields of ZopfliHash. */
53void ZopfliCleanHash(ZopfliHash* h);
54
55/*
56Updates the hash values based on the current position in the array. All calls
57to this must be made for consecutive bytes.
58*/
59void ZopfliUpdateHash(const unsigned char* array, size_t pos, size_t end,
60                      ZopfliHash* h);
61
62/*
63Prepopulates hash:
64Fills in the initial values in the hash, before ZopfliUpdateHash can be used
65correctly.
66*/
67void ZopfliWarmupHash(const unsigned char* array, size_t pos, size_t end,
68                      ZopfliHash* h);
69
70#endif  /* ZOPFLI_HASH_H_ */
71