/
algorithm.go
64 lines (48 loc) · 1.15 KB
/
algorithm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package git
import (
"hash"
"io"
"github.com/starter-go/afs"
)
// AlgorithmType 表示算法的类型
type AlgorithmType int
// 定义几种算法的类型
const (
AlgorithmCompression AlgorithmType = 1
AlgorithmDigest AlgorithmType = 2
AlgorithmPathMapping AlgorithmType = 3
)
// Algorithm 表示抽象的算法
type Algorithm interface {
GetInfo() *AlgorithmRegistration
}
// AlgorithmRegistration ...
type AlgorithmRegistration struct {
Name string
Type AlgorithmType
Provider Algorithm
}
// AlgorithmRegistry ...
// [inject:".git-algorithm-registry"]
type AlgorithmRegistry interface {
ListRegistrations() []*AlgorithmRegistration
}
////////////////////////////////////////////////////////////////////////////////
// Compression 压缩算法
type Compression interface {
Algorithm
NewReader(r io.Reader) (io.ReadCloser, error)
NewWriter(w io.Writer) (io.WriteCloser, error)
}
// Digest 摘要算法
type Digest interface {
Algorithm
Size() HashSize
New() hash.Hash
}
// PathMapping 路径映射算法
type PathMapping interface {
Algorithm
WithPattern(pattern string) PathMapping
Map(base afs.Path, id ObjectID) afs.Path
}