summaryrefslogtreecommitdiff
path: root/vendor/github.com/minio/minio-go/v7/pkg/set/stringset.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/minio/minio-go/v7/pkg/set/stringset.go')
-rw-r--r--vendor/github.com/minio/minio-go/v7/pkg/set/stringset.go30
1 files changed, 27 insertions, 3 deletions
diff --git a/vendor/github.com/minio/minio-go/v7/pkg/set/stringset.go b/vendor/github.com/minio/minio-go/v7/pkg/set/stringset.go
index c265ce572..8aa92212b 100644
--- a/vendor/github.com/minio/minio-go/v7/pkg/set/stringset.go
+++ b/vendor/github.com/minio/minio-go/v7/pkg/set/stringset.go
@@ -21,7 +21,7 @@ import (
"fmt"
"sort"
- "github.com/goccy/go-json"
+ "github.com/minio/minio-go/v7/internal/json"
)
// StringSet - uses map as set of strings.
@@ -37,6 +37,30 @@ func (set StringSet) ToSlice() []string {
return keys
}
+// ToByteSlices - returns StringSet as a sorted
+// slice of byte slices, using only one allocation.
+func (set StringSet) ToByteSlices() [][]byte {
+ length := 0
+ for k := range set {
+ length += len(k)
+ }
+ // Preallocate the slice with the total length of all strings
+ // to avoid multiple allocations.
+ dst := make([]byte, length)
+
+ // Add keys to this...
+ keys := make([][]byte, 0, len(set))
+ for k := range set {
+ n := copy(dst, k)
+ keys = append(keys, dst[:n])
+ dst = dst[n:]
+ }
+ sort.Slice(keys, func(i, j int) bool {
+ return string(keys[i]) < string(keys[j])
+ })
+ return keys
+}
+
// IsEmpty - returns whether the set is empty or not.
func (set StringSet) IsEmpty() bool {
return len(set) == 0
@@ -178,7 +202,7 @@ func NewStringSet() StringSet {
// CreateStringSet - creates new string set with given string values.
func CreateStringSet(sl ...string) StringSet {
- set := make(StringSet)
+ set := make(StringSet, len(sl))
for _, k := range sl {
set.Add(k)
}
@@ -187,7 +211,7 @@ func CreateStringSet(sl ...string) StringSet {
// CopyStringSet - returns copy of given set.
func CopyStringSet(set StringSet) StringSet {
- nset := NewStringSet()
+ nset := make(StringSet, len(set))
for k, v := range set {
nset[k] = v
}