feat: 支持件数组数据按照指定数量进行分片
This commit is contained in:
@ -144,3 +144,16 @@ func DeepClone[Value any](dataList []Value) []Value {
|
|||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Shard 将数组按照指定数量进行分片
|
||||||
|
func Shard[Value any](dataList []Value, itemShardCount int) [][]Value {
|
||||||
|
res := make([][]Value, 0)
|
||||||
|
for i := 0; i < len(dataList); i += itemShardCount {
|
||||||
|
tmpList := make([]Value, 0)
|
||||||
|
for j := 0; j < itemShardCount; j++ {
|
||||||
|
tmpList = append(tmpList, dataList[i+j])
|
||||||
|
}
|
||||||
|
res = append(res, tmpList)
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user