diff options
Diffstat (limited to 'vendor/github.com/ulikunitz/xz/internal/hash/roller.go')
-rw-r--r-- | vendor/github.com/ulikunitz/xz/internal/hash/roller.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/vendor/github.com/ulikunitz/xz/internal/hash/roller.go b/vendor/github.com/ulikunitz/xz/internal/hash/roller.go new file mode 100644 index 0000000..ab6a19c --- /dev/null +++ b/vendor/github.com/ulikunitz/xz/internal/hash/roller.go | |||
@@ -0,0 +1,29 @@ | |||
1 | // Copyright 2014-2017 Ulrich Kunitz. All rights reserved. | ||
2 | // Use of this source code is governed by a BSD-style | ||
3 | // license that can be found in the LICENSE file. | ||
4 | |||
5 | package hash | ||
6 | |||
7 | // Roller provides an interface for rolling hashes. The hash value will become | ||
8 | // valid after hash has been called Len times. | ||
9 | type Roller interface { | ||
10 | Len() int | ||
11 | RollByte(x byte) uint64 | ||
12 | } | ||
13 | |||
14 | // Hashes computes all hash values for the array p. Note that the state of the | ||
15 | // roller is changed. | ||
16 | func Hashes(r Roller, p []byte) []uint64 { | ||
17 | n := r.Len() | ||
18 | if len(p) < n { | ||
19 | return nil | ||
20 | } | ||
21 | h := make([]uint64, len(p)-n+1) | ||
22 | for i := 0; i < n-1; i++ { | ||
23 | r.RollByte(p[i]) | ||
24 | } | ||
25 | for i := range h { | ||
26 | h[i] = r.RollByte(p[i+n-1]) | ||
27 | } | ||
28 | return h | ||
29 | } | ||