Skip to content

Commit

Permalink
Merge pull request #26 from prometheus/feature/fingerprinting/set
Browse files Browse the repository at this point in the history
Add formal fingerprint sets for intersection ops.
  • Loading branch information
matttproud committed Aug 12, 2013
2 parents b92fd1c + 90425cb commit 28445c8
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions model/fingerprinting.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,44 @@ func (f Fingerprints) Less(i, j int) bool {
func (f Fingerprints) Swap(i, j int) {
f[i], f[j] = f[j], f[i]
}

type FingerprintSet map[Fingerprint]bool

func (s FingerprintSet) Equal(o FingerprintSet) bool {
if len(s) != len(o) {
return false
}

for k := range s {
if _, ok := o[k]; !ok {
return false
}
}

return true
}

func (s FingerprintSet) Intersection(o FingerprintSet) FingerprintSet {
myLength, otherLength := len(s), len(o)
if myLength == 0 || otherLength == 0 {
return FingerprintSet{}
}

subSet := s
superSet := o

if otherLength < myLength {
subSet = o
superSet = s
}

out := FingerprintSet{}

for k := range subSet {
if _, ok := superSet[k]; ok {
out[k] = true
}
}

return out
}

0 comments on commit 28445c8

Please sign in to comment.