From 8c0534e552cc7148afe43429ca511cf9dea32f54 Mon Sep 17 00:00:00 2001 From: Sydonian <794346190@qq.com> Date: Tue, 12 Dec 2023 09:40:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0none=E5=A4=87=E4=BB=BD?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sdks/storage/models.go | 25 +++++++++++++++++++++++-- utils/sort/sort.go | 4 +++- 2 files changed, 26 insertions(+), 3 deletions(-) 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 {