-
Notifications
You must be signed in to change notification settings - Fork 567
/
util.go
67 lines (60 loc) · 1.35 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package index
import (
"sort"
"github.com/pachyderm/pachyderm/v2/src/internal/storage/chunk"
)
// Perm calls f with each permutation of a.
func Perm(a []rune, f func([]rune)) {
perm(a, f, 0)
}
// Permute the values at index i to len(a)-1.
func perm(a []rune, f func([]rune), i int) {
if i > len(a) {
f(a)
return
}
perm(a, f, i+1)
for j := i + 1; j < len(a); j++ {
a[i], a[j] = a[j], a[i]
perm(a, f, i+1)
a[i], a[j] = a[j], a[i]
}
}
// Generate generates the permutations of the passed in string and returns them sorted.
func Generate(s string) []string {
fileNames := []string{}
Perm([]rune(s), func(fileName []rune) {
fileNames = append(fileNames, string(fileName))
})
sort.Strings(fileNames)
return fileNames
}
// PointsTo returns a list of all the chunks this index references
func PointsTo(idx *Index) []chunk.ID {
if idx == nil {
return nil
}
if idx.Range != nil {
return []chunk.ID{chunk.ID(idx.Range.ChunkRef.Ref.Id)}
}
var ids []chunk.ID
if idx.File != nil {
for _, dr := range idx.File.DataRefs {
ids = append(ids, chunk.ID(dr.Ref.Id))
}
}
return ids
}
// SizeBytes computes the size of the indexed data in bytes.
func SizeBytes(idx *Index) int64 {
var size int64
if idx == nil {
return size
}
if idx.File != nil {
for _, dataRef := range idx.File.DataRefs {
size += dataRef.SizeBytes
}
}
return size
}