MCPcopy
hub / github.com/perkeep/perkeep / SetStaticSetMembers

Method SetStaticSetMembers

pkg/schema/schema.go:576–632  ·  view source on GitHub ↗

SetStaticSetMembers sets the given members as the static-set members of this builder. If the members are so numerous that they would not fit on a schema blob, they are spread (recursively, if needed) onto sub static-sets. In which case, these subsets are set as "mergeSets" of this builder. All the c

(members []blob.Ref)

Source from the content-addressed store, hash-verified

574// static-set created from this builder.
575// SetStaticSetMembers panics if bb isn't a "static-set" claim type.
576func (bb *Builder) SetStaticSetMembers(members []blob.Ref) []*Blob {
577 if bb.Type() != TypeStaticSet {
578 panic("called SetStaticSetMembers on non static-set")
579 }
580
581 if len(members) <= maxStaticSetMembers {
582 ms := make([]string, len(members))
583 for i := range members {
584 ms[i] = members[i].String()
585 }
586 bb.m["members"] = ms
587 return nil
588 }
589
590 // too many members to fit in one static-set, so we spread them in
591 // several sub static-sets.
592 subsetsNumber := len(members) / maxStaticSetMembers
593 var perSubset int
594 if subsetsNumber < maxStaticSetMembers {
595 // this means we can fill each subset up to maxStaticSetMembers,
596 // and stash the rest in one last subset.
597 perSubset = maxStaticSetMembers
598 } else {
599 // otherwise we need to divide the members evenly in
600 // (maxStaticSetMembers - 1) subsets, and each of these subsets
601 // will also (recursively) have subsets of its own. There might
602 // also be a rest in one last subset, as above.
603 subsetsNumber = maxStaticSetMembers - 1
604 perSubset = len(members) / subsetsNumber
605 }
606 // only the subsets at this level
607 subsets := make([]*Blob, 0, subsetsNumber)
608 // subsets at this level, plus all the children subsets.
609 allSubsets := make([]*Blob, 0, subsetsNumber)
610 for i := 0; i < subsetsNumber; i++ {
611 ss := NewStaticSet()
612 subss := ss.SetStaticSetMembers(members[i*perSubset : (i+1)*perSubset])
613 subsets = append(subsets, ss.Blob())
614 allSubsets = append(allSubsets, ss.Blob())
615 allSubsets = append(allSubsets, subss...)
616 }
617
618 // Deal with the rest (of the euclidean division)
619 if perSubset*subsetsNumber < len(members) {
620 ss := NewStaticSet()
621 ss.SetStaticSetMembers(members[perSubset*subsetsNumber:])
622 allSubsets = append(allSubsets, ss.Blob())
623 subsets = append(subsets, ss.Blob())
624 }
625
626 mss := make([]string, len(subsets))
627 for i := range subsets {
628 mss[i] = subsets[i].BlobRef().String()
629 }
630 bb.m["mergeSets"] = mss
631 return allSubsets
632}
633

Callers 5

UploadDirMethod · 0.80
testLargeDirFunction · 0.80
testReadDirFunction · 0.80
RunCommandMethod · 0.80
directoryStaticSetMethod · 0.80

Calls 5

TypeMethod · 0.95
NewStaticSetFunction · 0.85
BlobMethod · 0.65
BlobRefMethod · 0.65
StringMethod · 0.45

Tested by 2

testLargeDirFunction · 0.64
testReadDirFunction · 0.64