forked from pachyderm/pachyderm
/
hash.go
31 lines (25 loc) · 784 Bytes
/
hash.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
package pps
import (
"hash/adler32"
ppsclient "github.com/pachyderm/pachyderm/src/client/pps"
)
// A Hasher represents a job/pipeline hasher.
type Hasher struct {
JobModulus uint64
PipelineModulus uint64
}
// NewHasher creates a hasher.
func NewHasher(jobModulus uint64, pipelineModulus uint64) *Hasher {
return &Hasher{
JobModulus: jobModulus,
PipelineModulus: pipelineModulus,
}
}
// HashJob computes and returns a hash of a job.
func (s *Hasher) HashJob(job *ppsclient.Job) uint64 {
return uint64(adler32.Checksum([]byte(job.ID))) % s.PipelineModulus
}
// HashPipeline computes and returns a hash of a pipeline.
func (s *Hasher) HashPipeline(pipeline *ppsclient.Pipeline) uint64 {
return uint64(adler32.Checksum([]byte(pipeline.Name))) % s.JobModulus
}