diff --git a/sdks/storage/models.go b/sdks/storage/models.go index 12647bf..2af3c4d 100644 --- a/sdks/storage/models.go +++ b/sdks/storage/models.go @@ -33,24 +33,45 @@ type Redundancy interface { } var RedundancyUnion = serder.UseTypeUnionInternallyTagged(types.Ref(types.NewTypeUnion[Redundancy]( + (*NoneRedundancy)(nil), (*RepRedundancy)(nil), (*ECRedundancy)(nil), )), "type") +type NoneRedundancy struct { + serder.Metadata `union:"none"` + Type string `json:"type"` +} + +func NewNoneRedundancy() *NoneRedundancy { + return &NoneRedundancy{ + Type: "none", + } +} +func (b *NoneRedundancy) Value() (driver.Value, error) { + return serder.ObjectToJSONEx[Redundancy](b) +} + +var DefaultRepRedundancy = *NewRepRedundancy(2) + type RepRedundancy struct { serder.Metadata `union:"rep"` Type string `json:"type"` + RepCount int `json:"repCount"` } -func NewRepRedundancy() *RepRedundancy { +func NewRepRedundancy(repCount int) *RepRedundancy { return &RepRedundancy{ - Type: "rep", + Type: "rep", + RepCount: repCount, } } func (b *RepRedundancy) Value() (driver.Value, error) { return serder.ObjectToJSONEx[Redundancy](b) } +var DefaultECRedundancy = *NewECRedundancy(2, 3, 1024*1024*5) + type ECRedundancy struct { serder.Metadata `union:"ec"` Type string `json:"type"` diff --git a/utils/sort/sort.go b/utils/sort/sort.go index b9774e1..f469e0b 100644 --- a/utils/sort/sort.go +++ b/utils/sort/sort.go @@ -26,15 +26,17 @@ func (s sorter[T]) Swap(i int, j int) { s.arr[i], s.arr[j] = s.arr[j], s.arr[i] } -func Sort[T any](arr []T, cmp Comparer[T]) { +func Sort[T any](arr []T, cmp Comparer[T]) []T { st := sorter[T]{ arr: arr, cmp: cmp, } sort.Sort(st) + return arr } +// false < true func CmpBool(left, right bool) int { leftVal := 0 if left {