You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

lrc.go 997 B

123456789101112131415161718192021222324252627282930313233343536
  1. package lrc
  2. import "github.com/klauspost/reedsolomon"
  3. type LRC struct {
  4. n int // 总块数,包括局部块
  5. k int // 数据块数量
  6. groups []int // 分组校验块生成时使用的数据块
  7. l *reedsolomon.LRC
  8. }
  9. func New(n int, k int, groups []int) (*LRC, error) {
  10. lrc := &LRC{
  11. n: n,
  12. k: k,
  13. groups: groups,
  14. }
  15. l, err := reedsolomon.NewLRC(k, n-len(groups)-k, groups)
  16. if err != nil {
  17. return nil, err
  18. }
  19. lrc.l = l
  20. return lrc, nil
  21. }
  22. // 根据全局修复的原理,生成根据输入修复指定块的矩阵。要求input内元素的值<n-len(r),且至少包含k个。
  23. func (l *LRC) GenerateMatrix(inputIdxs []int, outputIdxs []int) ([][]byte, error) {
  24. return l.l.GenerateMatrix(inputIdxs, outputIdxs)
  25. }
  26. // 生成修复组内某个块的矩阵。只支持组内缺少一个块的情况,且默认组内的其他块都存在。
  27. func (l *LRC) GenerateGroupMatrix(outputIdx int) ([][]byte, error) {
  28. return l.l.GenerateGroupMatrix(outputIdx)
  29. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。