Files
dolt/types/walk.go
T
Erik Arvidsson d06da3ca0a Chunking: Multi level chunking for blobs
After a compound blob is created we try to chunk it again in a similar
way to how we chunk Lists. We use the refs of the sub blob and compute
a rolling hash over these. If the hash matches a pattern then we split
the existing compound blob into a new compound blob with sub blobs
which are slices of the original compound blob.

Issue #17
2015-09-03 19:47:17 -04:00

60 lines
1.6 KiB
Go

package types
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
)
// SomeCallback takes a Future and returns a bool indicating whether the current walk should skip the tree descending from that Future.
type SomeCallback func(f Future) bool
type AllCallback func(f Future)
// Some recursively walks over all Values reachable from r and calls cb on them.
// If cb ever returns true, the walk will stop recursing that subtree.
func Some(r ref.Ref, cs chunks.ChunkSource, cb SomeCallback) {
doTreeWalk(futureFromRef(r), cs, cb)
}
// All recursively walks over all Values reachable from r and calls cb on them.
func All(r ref.Ref, cs chunks.ChunkSource, cb AllCallback) {
doTreeWalk(futureFromRef(r), cs, func(f Future) (skip bool) {
cb(f)
return
})
}
func doTreeWalk(f Future, cs chunks.ChunkSource, cb SomeCallback) {
doTreeWalk2(f, cs, cb, false)
}
func doTreeWalk2(f Future, cs chunks.ChunkSource, cb SomeCallback, skip bool) {
// skip is set to true when we shoud skip the top level value and this is used
// by compound lists which consists of other lists.
if !skip && cb(f) {
return
}
v := f.Deref(cs)
switch v := v.(type) {
case compoundList:
for _, f := range v.futures {
doTreeWalk2(f, cs, cb, true)
}
case listLeaf:
for _, f := range v.list {
doTreeWalk(f, cs, cb)
}
case Map:
for _, e := range v.m {
doTreeWalk(e.key, cs, cb)
doTreeWalk(e.value, cs, cb)
}
case Set:
for _, f := range v.m {
doTreeWalk(f, cs, cb)
}
// Note: no blob here because we're recursing the value tree, not the chunk tree. We treat each value as one thing, no matter how many chunks it is composed of.
}
}