From 32433430c0cef85e176bc78241e14e0a0bcadb01 Mon Sep 17 00:00:00 2001 From: Ben Ye Date: Fri, 19 Apr 2024 02:04:36 +0000 Subject: [PATCH] cleanup unused functions Signed-off-by: Ben Ye --- pkg/chunk/opts.go | 60 ------------------------------------------ pkg/chunk/opts_test.go | 50 ----------------------------------- 2 files changed, 110 deletions(-) delete mode 100644 pkg/chunk/opts.go delete mode 100644 pkg/chunk/opts_test.go diff --git a/pkg/chunk/opts.go b/pkg/chunk/opts.go deleted file mode 100644 index 3384ecd7a43..00000000000 --- a/pkg/chunk/opts.go +++ /dev/null @@ -1,60 +0,0 @@ -package chunk - -import ( - "strings" - "unicode/utf8" -) - -// Bitmap used by func isRegexMetaCharacter to check whether a character needs to be escaped. -var regexMetaCharacterBytes [16]byte - -// isRegexMetaCharacter reports whether byte b needs to be escaped. -func isRegexMetaCharacter(b byte) bool { - return b < utf8.RuneSelf && regexMetaCharacterBytes[b%16]&(1<<(b/16)) != 0 -} - -func init() { - for _, b := range []byte(`.+*?()|[]{}^$`) { - regexMetaCharacterBytes[b%16] |= 1 << (b / 16) - } -} - -// FindSetMatches returns list of values that can be equality matched on. -// copied from Prometheus querier.go, removed check for Prometheus wrapper. -func FindSetMatches(pattern string) []string { - escaped := false - sets := []*strings.Builder{{}} - for i := 0; i < len(pattern); i++ { - if escaped { - switch { - case isRegexMetaCharacter(pattern[i]): - sets[len(sets)-1].WriteByte(pattern[i]) - case pattern[i] == '\\': - sets[len(sets)-1].WriteByte('\\') - default: - return nil - } - escaped = false - } else { - switch { - case isRegexMetaCharacter(pattern[i]): - if pattern[i] == '|' { - sets = append(sets, &strings.Builder{}) - } else { - return nil - } - case pattern[i] == '\\': - escaped = true - default: - sets[len(sets)-1].WriteByte(pattern[i]) - } - } - } - matches := make([]string, 0, len(sets)) - for _, s := range sets { - if s.Len() > 0 { - matches = append(matches, s.String()) - } - } - return matches -} diff --git a/pkg/chunk/opts_test.go b/pkg/chunk/opts_test.go deleted file mode 100644 index 01d05407e6d..00000000000 --- a/pkg/chunk/opts_test.go +++ /dev/null @@ -1,50 +0,0 @@ -package chunk - -import ( - "testing" - - "github.com/stretchr/testify/require" -) - -// Refer to https://github.com/prometheus/prometheus/issues/2651. -func TestFindSetMatches(t *testing.T) { - cases := []struct { - pattern string - exp []string - }{ - // Simple sets. - { - pattern: "foo|bar|baz", - exp: []string{ - "foo", - "bar", - "baz", - }, - }, - // Simple sets containing escaped characters. - { - pattern: "fo\\.o|bar\\?|\\^baz", - exp: []string{ - "fo.o", - "bar?", - "^baz", - }, - }, - // Simple sets containing special characters without escaping. - { - pattern: "fo.o|bar?|^baz", - exp: nil, - }, - { - pattern: "foo\\|bar\\|baz", - exp: []string{ - "foo|bar|baz", - }, - }, - } - - for _, c := range cases { - matches := FindSetMatches(c.pattern) - require.Equal(t, c.exp, matches) - } -}