diff options
Diffstat (limited to 'vendor/github.com/ulikunitz/xz/lzma/matchalgorithm.go')
-rw-r--r-- | vendor/github.com/ulikunitz/xz/lzma/matchalgorithm.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/vendor/github.com/ulikunitz/xz/lzma/matchalgorithm.go b/vendor/github.com/ulikunitz/xz/lzma/matchalgorithm.go new file mode 100644 index 0000000..4a244eb --- /dev/null +++ b/vendor/github.com/ulikunitz/xz/lzma/matchalgorithm.go | |||
@@ -0,0 +1,52 @@ | |||
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 lzma | ||
6 | |||
7 | import "errors" | ||
8 | |||
9 | // MatchAlgorithm identifies an algorithm to find matches in the | ||
10 | // dictionary. | ||
11 | type MatchAlgorithm byte | ||
12 | |||
13 | // Supported matcher algorithms. | ||
14 | const ( | ||
15 | HashTable4 MatchAlgorithm = iota | ||
16 | BinaryTree | ||
17 | ) | ||
18 | |||
19 | // maStrings are used by the String method. | ||
20 | var maStrings = map[MatchAlgorithm]string{ | ||
21 | HashTable4: "HashTable4", | ||
22 | BinaryTree: "BinaryTree", | ||
23 | } | ||
24 | |||
25 | // String returns a string representation of the Matcher. | ||
26 | func (a MatchAlgorithm) String() string { | ||
27 | if s, ok := maStrings[a]; ok { | ||
28 | return s | ||
29 | } | ||
30 | return "unknown" | ||
31 | } | ||
32 | |||
33 | var errUnsupportedMatchAlgorithm = errors.New( | ||
34 | "lzma: unsupported match algorithm value") | ||
35 | |||
36 | // verify checks whether the matcher value is supported. | ||
37 | func (a MatchAlgorithm) verify() error { | ||
38 | if _, ok := maStrings[a]; !ok { | ||
39 | return errUnsupportedMatchAlgorithm | ||
40 | } | ||
41 | return nil | ||
42 | } | ||
43 | |||
44 | func (a MatchAlgorithm) new(dictCap int) (m matcher, err error) { | ||
45 | switch a { | ||
46 | case HashTable4: | ||
47 | return newHashTable(dictCap, 4) | ||
48 | case BinaryTree: | ||
49 | return newBinTree(dictCap) | ||
50 | } | ||
51 | return nil, errUnsupportedMatchAlgorithm | ||
52 | } | ||