Browse Source

增加none备份类型

pull/34/head
Sydonian 1 year ago
parent
commit
8c0534e552
2 changed files with 26 additions and 3 deletions
  1. +23
    -2
      sdks/storage/models.go
  2. +3
    -1
      utils/sort/sort.go

+ 23
- 2
sdks/storage/models.go View File

@@ -33,24 +33,45 @@ type Redundancy interface {
} }


var RedundancyUnion = serder.UseTypeUnionInternallyTagged(types.Ref(types.NewTypeUnion[Redundancy]( var RedundancyUnion = serder.UseTypeUnionInternallyTagged(types.Ref(types.NewTypeUnion[Redundancy](
(*NoneRedundancy)(nil),
(*RepRedundancy)(nil), (*RepRedundancy)(nil),
(*ECRedundancy)(nil), (*ECRedundancy)(nil),
)), "type") )), "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 { type RepRedundancy struct {
serder.Metadata `union:"rep"` serder.Metadata `union:"rep"`
Type string `json:"type"` Type string `json:"type"`
RepCount int `json:"repCount"`
} }


func NewRepRedundancy() *RepRedundancy {
func NewRepRedundancy(repCount int) *RepRedundancy {
return &RepRedundancy{ return &RepRedundancy{
Type: "rep",
Type: "rep",
RepCount: repCount,
} }
} }
func (b *RepRedundancy) Value() (driver.Value, error) { func (b *RepRedundancy) Value() (driver.Value, error) {
return serder.ObjectToJSONEx[Redundancy](b) return serder.ObjectToJSONEx[Redundancy](b)
} }


var DefaultECRedundancy = *NewECRedundancy(2, 3, 1024*1024*5)

type ECRedundancy struct { type ECRedundancy struct {
serder.Metadata `union:"ec"` serder.Metadata `union:"ec"`
Type string `json:"type"` Type string `json:"type"`


+ 3
- 1
utils/sort/sort.go View File

@@ -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] 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]{ st := sorter[T]{
arr: arr, arr: arr,
cmp: cmp, cmp: cmp,
} }


sort.Sort(st) sort.Sort(st)
return arr
} }


// false < true
func CmpBool(left, right bool) int { func CmpBool(left, right bool) int {
leftVal := 0 leftVal := 0
if left { if left {


Loading…
Cancel
Save