From 92b0833444f85927d0414f19c1ce2be28da30b66 Mon Sep 17 00:00:00 2001 From: Liam Stanley Date: Sat, 27 Jan 2018 06:58:54 -0500 Subject: [PATCH] add Tags.Equals() and Tags.Keys() methods --- cap.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cap.go b/cap.go index 1d50460..31ce6c6 100644 --- a/cap.go +++ b/cap.go @@ -441,6 +441,28 @@ func (t Tags) Len() (length int) { return len(t.Bytes()) } +// Equals compares two Tags for equality. +func (t Tags) Equals(tt Tags) bool { + if t.Count() != tt.Count() { + return false + } + for k, v := range t { + if vv, ok := tt[k]; !ok || v != vv { + return false + } + } + return true +} + +// Keys returns a slice of (unsorted) tag keys. +func (t Tags) Keys() (keys []string) { + keys = make([]string, 0, t.Count()) + for key := range t { + keys = append(keys, key) + } + return keys +} + // Count finds how many total tags that there are. func (t Tags) Count() int { if t == nil {