Initial QSfera import

This commit is contained in:
Курнат Андрей
2026-06-07 10:20:04 +03:00
commit 2315f25754
16485 changed files with 4826827 additions and 0 deletions
+127
View File
@@ -0,0 +1,127 @@
/*
* MinIO Go Library for Amazon S3 Compatible Cloud Storage
* Copyright 2015-2026 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package set
import (
"encoding/json"
"fmt"
)
// IntSet - uses map as set of ints.
// This is now implemented using the generic Set[int] type.
type IntSet Set[int]
// ToSlice - returns IntSet as int slice.
func (set IntSet) ToSlice() []int {
return ToSliceOrdered(Set[int](set))
}
// IsEmpty - returns whether the set is empty or not.
func (set IntSet) IsEmpty() bool {
return Set[int](set).IsEmpty()
}
// Add - adds int to the set.
func (set IntSet) Add(i int) {
Set[int](set).Add(i)
}
// Remove - removes int in the set. It does nothing if int does not exist in the set.
func (set IntSet) Remove(i int) {
Set[int](set).Remove(i)
}
// Contains - checks if int is in the set.
func (set IntSet) Contains(i int) bool {
return Set[int](set).Contains(i)
}
// FuncMatch - returns new set containing each value who passes match function.
// A 'matchFn' should accept element in a set as first argument and
// 'matchInt' as second argument. The function can do any logic to
// compare both the arguments and should return true to accept element in
// a set to include in output set else the element is ignored.
func (set IntSet) FuncMatch(matchFn func(int, int) bool, matchInt int) IntSet {
return IntSet(Set[int](set).FuncMatch(matchFn, matchInt))
}
// ApplyFunc - returns new set containing each value processed by 'applyFn'.
// A 'applyFn' should accept element in a set as a argument and return
// a processed int. The function can do any logic to return a processed
// int.
func (set IntSet) ApplyFunc(applyFn func(int) int) IntSet {
return IntSet(Set[int](set).ApplyFunc(applyFn))
}
// Equals - checks whether given set is equal to current set or not.
func (set IntSet) Equals(iset IntSet) bool {
return Set[int](set).Equals(Set[int](iset))
}
// Intersection - returns the intersection with given set as new set.
func (set IntSet) Intersection(iset IntSet) IntSet {
return IntSet(Set[int](set).Intersection(Set[int](iset)))
}
// Difference - returns the difference with given set as new set.
func (set IntSet) Difference(iset IntSet) IntSet {
return IntSet(Set[int](set).Difference(Set[int](iset)))
}
// Union - returns the union with given set as new set.
func (set IntSet) Union(iset IntSet) IntSet {
return IntSet(Set[int](set).Union(Set[int](iset)))
}
// MarshalJSON - converts to JSON data.
func (set IntSet) MarshalJSON() ([]byte, error) {
return json.Marshal(set.ToSlice())
}
// UnmarshalJSON - parses JSON data and creates new set with it.
func (set *IntSet) UnmarshalJSON(data []byte) error {
sl := []int{}
var err error
if err = json.Unmarshal(data, &sl); err == nil {
*set = make(IntSet)
for _, i := range sl {
set.Add(i)
}
}
return err
}
// String - returns printable string of the set.
func (set IntSet) String() string {
return fmt.Sprintf("%v", set.ToSlice())
}
// NewIntSet - creates new int set.
func NewIntSet() IntSet {
return IntSet(New[int]())
}
// CreateIntSet - creates new int set with given int values.
func CreateIntSet(il ...int) IntSet {
return IntSet(Create(il...))
}
// CopyIntSet - returns copy of given set.
func CopyIntSet(set IntSet) IntSet {
return IntSet(Copy(Set[int](set)))
}
+131
View File
@@ -0,0 +1,131 @@
/*
* MinIO Go Library for Amazon S3 Compatible Cloud Storage
* Copyright 2015-2026 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package set
import (
"github.com/tinylib/msgp/msgp"
"github.com/tinylib/msgp/msgp/setof"
)
// EncodeMsg encodes the message to the writer.
// Values are stored as a slice of strings or nil.
func (s StringSet) EncodeMsg(writer *msgp.Writer) error {
return setof.StringSorted(s).EncodeMsg(writer)
}
// MarshalMsg encodes the message to the bytes.
// Values are stored as a slice of strings or nil.
func (s StringSet) MarshalMsg(bytes []byte) ([]byte, error) {
return setof.StringSorted(s).MarshalMsg(bytes)
}
// DecodeMsg decodes the message from the reader.
func (s *StringSet) DecodeMsg(reader *msgp.Reader) error {
var ss setof.String
if err := ss.DecodeMsg(reader); err != nil {
return err
}
*s = StringSet(ss)
return nil
}
// UnmarshalMsg decodes the message from the bytes.
func (s *StringSet) UnmarshalMsg(bytes []byte) ([]byte, error) {
var ss setof.String
bytes, err := ss.UnmarshalMsg(bytes)
if err != nil {
return nil, err
}
*s = StringSet(ss)
return bytes, nil
}
// Msgsize returns the maximum size of the message.
func (s StringSet) Msgsize() int {
return setof.String(s).Msgsize()
}
// MarshalBinary encodes the receiver into a binary form and returns the result.
func (s StringSet) MarshalBinary() ([]byte, error) {
return s.MarshalMsg(nil)
}
// AppendBinary appends the binary representation of itself to the end of b
func (s StringSet) AppendBinary(b []byte) ([]byte, error) {
return s.MarshalMsg(b)
}
// UnmarshalBinary decodes the binary representation of itself from b
func (s *StringSet) UnmarshalBinary(b []byte) error {
_, err := s.UnmarshalMsg(b)
return err
}
// EncodeMsg encodes the message to the writer.
// Values are stored as a slice of ints or nil.
func (s IntSet) EncodeMsg(writer *msgp.Writer) error {
return setof.IntSorted(s).EncodeMsg(writer)
}
// MarshalMsg encodes the message to the bytes.
// Values are stored as a slice of ints or nil.
func (s IntSet) MarshalMsg(bytes []byte) ([]byte, error) {
return setof.IntSorted(s).MarshalMsg(bytes)
}
// DecodeMsg decodes the message from the reader.
func (s *IntSet) DecodeMsg(reader *msgp.Reader) error {
var is setof.Int
if err := is.DecodeMsg(reader); err != nil {
return err
}
*s = IntSet(is)
return nil
}
// UnmarshalMsg decodes the message from the bytes.
func (s *IntSet) UnmarshalMsg(bytes []byte) ([]byte, error) {
var is setof.Int
bytes, err := is.UnmarshalMsg(bytes)
if err != nil {
return nil, err
}
*s = IntSet(is)
return bytes, nil
}
// Msgsize returns the maximum size of the message.
func (s IntSet) Msgsize() int {
return setof.Int(s).Msgsize()
}
// MarshalBinary encodes the receiver into a binary form and returns the result.
func (s IntSet) MarshalBinary() ([]byte, error) {
return s.MarshalMsg(nil)
}
// AppendBinary appends the binary representation of itself to the end of b
func (s IntSet) AppendBinary(b []byte) ([]byte, error) {
return s.MarshalMsg(b)
}
// UnmarshalBinary decodes the binary representation of itself from b
func (s *IntSet) UnmarshalBinary(b []byte) error {
_, err := s.UnmarshalMsg(b)
return err
}
+190
View File
@@ -0,0 +1,190 @@
/*
* MinIO Go Library for Amazon S3 Compatible Cloud Storage
* Copyright 2015-2026 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package set
import (
"cmp"
"slices"
)
// Set - uses map as a set of comparable elements.
//
// Important Caveats:
// - Sets are unordered by nature. Map iteration order is non-deterministic in Go.
// - When converting to slices, use ToSlice() with a comparison function or
// ToSliceOrdered() for ordered types to get deterministic, sorted results.
// - Comparison functions must provide total ordering: if your comparison returns 0
// for different elements, their relative order in the result is undefined.
// - For deterministic ordering when elements may compare equal, use secondary
// sort criteria (e.g., sort by length first, then alphabetically for ties).
type Set[T comparable] map[T]struct{}
// ToSlice - returns Set as a slice sorted using the provided comparison function.
// If cmpFn is nil, the slice order is undefined (non-deterministic).
//
// Important: The comparison function should provide total ordering. If it returns 0
// for elements that are not identical, their relative order in the result is undefined.
// For deterministic results, use secondary sort criteria for tie-breaking.
func (set Set[T]) ToSlice(cmpFn func(a, b T) int) []T {
keys := make([]T, 0, len(set))
for k := range set {
keys = append(keys, k)
}
if cmpFn != nil {
slices.SortFunc(keys, cmpFn)
}
return keys
}
// ToSliceOrdered - returns Set as a sorted slice for ordered types.
// This is a convenience method for types that implement cmp.Ordered.
// The result is deterministic and always sorted in ascending order.
func ToSliceOrdered[T cmp.Ordered](set Set[T]) []T {
keys := make([]T, 0, len(set))
for k := range set {
keys = append(keys, k)
}
slices.Sort(keys)
return keys
}
// IsEmpty - returns whether the set is empty or not.
func (set Set[T]) IsEmpty() bool {
return len(set) == 0
}
// Add - adds element to the set.
func (set Set[T]) Add(s T) {
set[s] = struct{}{}
}
// Remove - removes element from the set. It does nothing if element does not exist in the set.
func (set Set[T]) Remove(s T) {
delete(set, s)
}
// Contains - checks if element is in the set.
func (set Set[T]) Contains(s T) bool {
_, ok := set[s]
return ok
}
// FuncMatch - returns new set containing each value that passes match function.
// A 'matchFn' should accept element in a set as first argument and
// 'matchValue' as second argument. The function can do any logic to
// compare both the arguments and should return true to accept element in
// a set to include in output set else the element is ignored.
func (set Set[T]) FuncMatch(matchFn func(T, T) bool, matchValue T) Set[T] {
nset := New[T]()
for k := range set {
if matchFn(k, matchValue) {
nset.Add(k)
}
}
return nset
}
// ApplyFunc - returns new set containing each value processed by 'applyFn'.
// A 'applyFn' should accept element in a set as an argument and return
// a processed value. The function can do any logic to return a processed value.
func (set Set[T]) ApplyFunc(applyFn func(T) T) Set[T] {
nset := New[T]()
for k := range set {
nset.Add(applyFn(k))
}
return nset
}
// Equals - checks whether given set is equal to current set or not.
func (set Set[T]) Equals(sset Set[T]) bool {
// If length of set is not equal to length of given set, the
// set is not equal to given set.
if len(set) != len(sset) {
return false
}
// As both sets are equal in length, check each elements are equal.
for k := range set {
if _, ok := sset[k]; !ok {
return false
}
}
return true
}
// Intersection - returns the intersection with given set as new set.
func (set Set[T]) Intersection(sset Set[T]) Set[T] {
nset := New[T]()
for k := range set {
if _, ok := sset[k]; ok {
nset.Add(k)
}
}
return nset
}
// Difference - returns the difference with given set as new set.
func (set Set[T]) Difference(sset Set[T]) Set[T] {
nset := New[T]()
for k := range set {
if _, ok := sset[k]; !ok {
nset.Add(k)
}
}
return nset
}
// Union - returns the union with given set as new set.
func (set Set[T]) Union(sset Set[T]) Set[T] {
nset := New[T]()
for k := range set {
nset.Add(k)
}
for k := range sset {
nset.Add(k)
}
return nset
}
// New - creates new set.
func New[T comparable]() Set[T] {
return make(Set[T])
}
// Create - creates new set with given values.
func Create[T comparable](sl ...T) Set[T] {
set := make(Set[T], len(sl))
for _, k := range sl {
set.Add(k)
}
return set
}
// Copy - returns copy of given set.
func Copy[T comparable](set Set[T]) Set[T] {
nset := make(Set[T], len(set))
for k, v := range set {
nset[k] = v
}
return nset
}
+159
View File
@@ -0,0 +1,159 @@
/*
* MinIO Go Library for Amazon S3 Compatible Cloud Storage
* Copyright 2015-2026 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package set
import (
"encoding/json"
"fmt"
"sort"
)
// StringSet - uses map as set of strings.
// This is now implemented using the generic Set[string] type.
type StringSet Set[string]
// ToSlice - returns StringSet as string slice.
func (set StringSet) ToSlice() []string {
return ToSliceOrdered(Set[string](set))
}
// 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 Set[string](set).IsEmpty()
}
// Add - adds string to the set.
func (set StringSet) Add(s string) {
Set[string](set).Add(s)
}
// Remove - removes string in the set. It does nothing if string does not exist in the set.
func (set StringSet) Remove(s string) {
Set[string](set).Remove(s)
}
// Contains - checks if string is in the set.
func (set StringSet) Contains(s string) bool {
return Set[string](set).Contains(s)
}
// FuncMatch - returns new set containing each value who passes match function.
// A 'matchFn' should accept element in a set as first argument and
// 'matchString' as second argument. The function can do any logic to
// compare both the arguments and should return true to accept element in
// a set to include in output set else the element is ignored.
func (set StringSet) FuncMatch(matchFn func(string, string) bool, matchString string) StringSet {
return StringSet(Set[string](set).FuncMatch(matchFn, matchString))
}
// ApplyFunc - returns new set containing each value processed by 'applyFn'.
// A 'applyFn' should accept element in a set as a argument and return
// a processed string. The function can do any logic to return a processed
// string.
func (set StringSet) ApplyFunc(applyFn func(string) string) StringSet {
return StringSet(Set[string](set).ApplyFunc(applyFn))
}
// Equals - checks whether given set is equal to current set or not.
func (set StringSet) Equals(sset StringSet) bool {
return Set[string](set).Equals(Set[string](sset))
}
// Intersection - returns the intersection with given set as new set.
func (set StringSet) Intersection(sset StringSet) StringSet {
return StringSet(Set[string](set).Intersection(Set[string](sset)))
}
// Difference - returns the difference with given set as new set.
func (set StringSet) Difference(sset StringSet) StringSet {
return StringSet(Set[string](set).Difference(Set[string](sset)))
}
// Union - returns the union with given set as new set.
func (set StringSet) Union(sset StringSet) StringSet {
return StringSet(Set[string](set).Union(Set[string](sset)))
}
// MarshalJSON - converts to JSON data.
func (set StringSet) MarshalJSON() ([]byte, error) {
return json.Marshal(set.ToSlice())
}
// UnmarshalJSON - parses JSON data and creates new set with it.
func (set *StringSet) UnmarshalJSON(data []byte) error {
sl := []interface{}{}
var err error
if err = json.Unmarshal(data, &sl); err == nil {
*set = make(StringSet)
for _, s := range sl {
set.Add(fmt.Sprintf("%v", s))
}
} else {
var s interface{}
if err = json.Unmarshal(data, &s); err == nil {
*set = make(StringSet)
set.Add(fmt.Sprintf("%v", s))
}
}
return err
}
// String - returns printable string of the set.
func (set StringSet) String() string {
return fmt.Sprintf("%s", set.ToSlice())
}
// NewStringSet - creates new string set.
func NewStringSet() StringSet {
return StringSet(New[string]())
}
// CreateStringSet - creates new string set with given string values.
func CreateStringSet(sl ...string) StringSet {
return StringSet(Create(sl...))
}
// CopyStringSet - returns copy of given set.
func CopyStringSet(set StringSet) StringSet {
return StringSet(Copy(Set[string](set)))
}