github.com/pachyderm/pachyderm@v1.13.4/src/server/pps/hash.go (about) 1 package pps 2 3 import ( 4 "hash/adler32" 5 ) 6 7 // A Hasher represents a job/pipeline hasher. 8 type Hasher struct { 9 JobModulus uint64 10 PipelineModulus uint64 11 } 12 13 // NewHasher creates a hasher. 14 func NewHasher(jobModulus uint64, pipelineModulus uint64) *Hasher { 15 return &Hasher{ 16 JobModulus: jobModulus, 17 PipelineModulus: pipelineModulus, 18 } 19 } 20 21 // HashJob computes and returns the hash of a job. 22 func (s *Hasher) HashJob(jobID string) uint64 { 23 return uint64(adler32.Checksum([]byte(jobID))) % s.JobModulus 24 } 25 26 // HashPipeline computes and returns the hash of a pipeline. 27 func (s *Hasher) HashPipeline(pipelineName string) uint64 { 28 return uint64(adler32.Checksum([]byte(pipelineName))) % s.PipelineModulus 29 }