dolt/go/store: types: sequence_chunker: Small *Format cleanup.

This commit is contained in:
Aaron Son
2019-07-03 10:54:37 -07:00
committed by Brian Hendriks
parent 6ac5ab2790
commit 4a996a1e2b
17 changed files with 43 additions and 46 deletions
+1 -1
View File
@@ -141,7 +141,7 @@ func ApplyEdits(ctx context.Context, f *Format, edits EditProvider, m Map) (Map,
}
if ch == nil {
ch = newSequenceChunker(ctx, f, cur, 0, vrw, makeMapLeafChunkFn(f, vrw), newOrderedMetaSequenceChunkFn(MapKind, f, vrw), mapHashValueBytes)
ch = newSequenceChunker(ctx, cur, 0, vrw, makeMapLeafChunkFn(f, vrw), newOrderedMetaSequenceChunkFn(MapKind, f, vrw), mapHashValueBytes)
} else {
ch.advanceTo(ctx, cur)
}
+2 -2
View File
@@ -139,7 +139,7 @@ func (b Blob) Concat(ctx context.Context, other Blob) Blob {
}
func (b Blob) newChunker(ctx context.Context, f *Format, cur *sequenceCursor, vrw ValueReadWriter) *sequenceChunker {
return newSequenceChunker(ctx, f, cur, 0, vrw, makeBlobLeafChunkFn(vrw, f), newIndexedMetaSequenceChunkFn(f, BlobKind, vrw), hashValueByte)
return newSequenceChunker(ctx, cur, 0, vrw, makeBlobLeafChunkFn(vrw, f), newIndexedMetaSequenceChunkFn(f, BlobKind, vrw), hashValueByte)
}
func (b Blob) asSequence() sequence {
@@ -243,7 +243,7 @@ func readBlobsP(ctx context.Context, vrw ValueReadWriter, rs ...io.Reader) Blob
}
func readBlob(ctx context.Context, f *Format, r io.Reader, vrw ValueReadWriter) Blob {
sc := newEmptySequenceChunker(ctx, f, vrw, makeBlobLeafChunkFn(vrw, f), newIndexedMetaSequenceChunkFn(f, BlobKind, vrw), func(item sequenceItem, rv *rollingValueHasher) {
sc := newEmptySequenceChunker(ctx, vrw, makeBlobLeafChunkFn(vrw, f), newIndexedMetaSequenceChunkFn(f, BlobKind, vrw), func(item sequenceItem, rv *rollingValueHasher) {
rv.HashByte(item.(byte))
})
+1 -1
View File
@@ -17,7 +17,7 @@ type leafSequence struct {
}
func newLeafSequence(format *Format, vrw ValueReadWriter, buff []byte, offsets []uint32, len uint64) leafSequence {
return leafSequence{newSequenceImpl(vrw, buff, offsets, len), format}
return leafSequence{newSequenceImpl(vrw, format, buff, offsets, len), format}
}
func newLeafSequenceFromValues(kind NomsKind, vrw ValueReadWriter, f *Format, vs ...Value) leafSequence {
+2 -2
View File
@@ -252,7 +252,7 @@ func (l List) DiffWithLimit(ctx context.Context, last List, changes chan<- Splic
}
func (l List) newChunker(ctx context.Context, cur *sequenceCursor, vrw ValueReadWriter) *sequenceChunker {
return newSequenceChunker(ctx, l.format, cur, 0, vrw, makeListLeafChunkFn(vrw, l.format), newIndexedMetaSequenceChunkFn(l.format, ListKind, vrw), hashValueBytes)
return newSequenceChunker(ctx, cur, 0, vrw, makeListLeafChunkFn(vrw, l.format), newIndexedMetaSequenceChunkFn(l.format, ListKind, vrw), hashValueBytes)
}
func makeListLeafChunkFn(vrw ValueReadWriter, f *Format) makeChunkFn {
@@ -270,5 +270,5 @@ func makeListLeafChunkFn(vrw ValueReadWriter, f *Format) makeChunkFn {
}
func newEmptyListSequenceChunker(ctx context.Context, f *Format, vrw ValueReadWriter) *sequenceChunker {
return newEmptySequenceChunker(ctx, f, vrw, makeListLeafChunkFn(vrw, f), newIndexedMetaSequenceChunkFn(f, ListKind, vrw), hashValueBytes)
return newEmptySequenceChunker(ctx, vrw, makeListLeafChunkFn(vrw, f), newIndexedMetaSequenceChunkFn(f, ListKind, vrw), hashValueBytes)
}
+1 -1
View File
@@ -91,7 +91,7 @@ func (le *ListEditor) List(ctx context.Context) List {
sp := <-<-spliceChan
if ch == nil {
ch = newSequenceChunker(ctx, le.f, cur, 0, vrw, makeListLeafChunkFn(vrw, le.f), newIndexedMetaSequenceChunkFn(le.f, ListKind, vrw), hashValueBytes)
ch = newSequenceChunker(ctx, cur, 0, vrw, makeListLeafChunkFn(vrw, le.f), newIndexedMetaSequenceChunkFn(le.f, ListKind, vrw), hashValueBytes)
} else {
ch.advanceTo(ctx, cur)
}
+1 -1
View File
@@ -312,5 +312,5 @@ func makeMapLeafChunkFn(f *Format, vrw ValueReadWriter) makeChunkFn {
}
func newEmptyMapSequenceChunker(ctx context.Context, f *Format, vrw ValueReadWriter) *sequenceChunker {
return newEmptySequenceChunker(ctx, f, vrw, makeMapLeafChunkFn(f, vrw), newOrderedMetaSequenceChunkFn(MapKind, f, vrw), mapHashValueBytes)
return newEmptySequenceChunker(ctx, vrw, makeMapLeafChunkFn(f, vrw), newOrderedMetaSequenceChunkFn(MapKind, f, vrw), mapHashValueBytes)
}
+4 -5
View File
@@ -47,7 +47,7 @@ func (mt metaTuple) decoderAtPart(part uint32) valueDecoder {
func (mt metaTuple) ref() Ref {
dec := mt.decoderAtPart(metaTuplePartRef)
return dec.readRef()
return dec.readRef(mt.format)
}
func (mt metaTuple) key() orderedKey {
@@ -122,11 +122,10 @@ func (key orderedKey) writeTo(w nomsWriter, f *Format) {
type metaSequence struct {
sequenceImpl
format *Format
}
func newMetaSequence(f *Format, vrw ValueReadWriter, buff []byte, offsets []uint32, len uint64) metaSequence {
return metaSequence{newSequenceImpl(vrw, buff, offsets, len), f}
return metaSequence{newSequenceImpl(vrw, f, buff, offsets, len)}
}
func newMetaSequenceFromTuples(f *Format, kind NomsKind, level uint64, tuples []metaTuple, vrw ValueReadWriter) metaSequence {
@@ -205,7 +204,7 @@ func (ms metaSequence) readTuple(f *Format, dec *valueDecoder) metaTuple {
func (ms metaSequence) getRefAt(dec *valueDecoder, idx int) Ref {
dec.offset = uint32(ms.getItemOffset(idx))
return dec.readRef()
return dec.readRef(ms.format)
}
func (ms metaSequence) getNumLeavesAt(idx int) uint64 {
@@ -230,7 +229,7 @@ func (ms metaSequence) typeOf() *Type {
ts := make(typeSlice, 0, count)
var lastRef Ref
for i := uint64(0); i < count; i++ {
ref := dec.readRef()
ref := dec.readRef(ms.format)
if lastRef.IsZeroValue() || !lastRef.isSameTargetType(ref) {
lastRef = ref
t := ref.TargetType()
+3 -3
View File
@@ -48,15 +48,15 @@ func constructRef(f *Format, targetHash hash.Hash, targetType *Type, height uint
offsets[refPartHeight] = w.offset
w.writeCount(height)
return Ref{valueImpl{nil, w.data(), offsets}}
return Ref{valueImpl{nil, f, w.data(), offsets}}
}
// readRef reads the data provided by a reader and moves the reader forward.
func readRef(dec *typedBinaryNomsReader) Ref {
func readRef(f *Format, dec *typedBinaryNomsReader) Ref {
start := dec.pos()
offsets := skipRef(dec)
end := dec.pos()
return Ref{valueImpl{nil, dec.byteSlice(start, end), offsets}}
return Ref{valueImpl{nil, f, dec.byteSlice(start, end), offsets}}
}
// skipRef moves the reader forward, past the data representing the Ref, and returns the offsets of the component parts.
+2 -2
View File
@@ -52,8 +52,8 @@ type sequenceImpl struct {
len uint64
}
func newSequenceImpl(vrw ValueReadWriter, buff []byte, offsets []uint32, len uint64) sequenceImpl {
return sequenceImpl{valueImpl{vrw, buff, offsets}, len}
func newSequenceImpl(vrw ValueReadWriter, f *Format, buff []byte, offsets []uint32, len uint64) sequenceImpl {
return sequenceImpl{valueImpl{vrw, f, buff, offsets}, len}
}
func (seq sequenceImpl) decoderSkipToValues() (valueDecoder, uint64) {
+8 -10
View File
@@ -24,17 +24,16 @@ type sequenceChunker struct {
rv *rollingValueHasher
done bool
unwrittenCol Collection
format *Format
}
// makeChunkFn takes a sequence of items to chunk, and returns the result of chunking those items, a tuple of a reference to that chunk which can itself be chunked + its underlying value.
type makeChunkFn func(level uint64, values []sequenceItem) (Collection, orderedKey, uint64)
func newEmptySequenceChunker(ctx context.Context, f *Format, vrw ValueReadWriter, makeChunk, parentMakeChunk makeChunkFn, hashValueBytes hashValueBytesFn) *sequenceChunker {
return newSequenceChunker(ctx, f, nil, uint64(0), vrw, makeChunk, parentMakeChunk, hashValueBytes)
func newEmptySequenceChunker(ctx context.Context, vrw ValueReadWriter, makeChunk, parentMakeChunk makeChunkFn, hashValueBytes hashValueBytesFn) *sequenceChunker {
return newSequenceChunker(ctx, nil, uint64(0), vrw, makeChunk, parentMakeChunk, hashValueBytes)
}
func newSequenceChunker(ctx context.Context, format *Format, cur *sequenceCursor, level uint64, vrw ValueReadWriter, makeChunk, parentMakeChunk makeChunkFn, hashValueBytes hashValueBytesFn) *sequenceChunker {
func newSequenceChunker(ctx context.Context, cur *sequenceCursor, level uint64, vrw ValueReadWriter, makeChunk, parentMakeChunk makeChunkFn, hashValueBytes hashValueBytesFn) *sequenceChunker {
d.PanicIfFalse(makeChunk != nil)
d.PanicIfFalse(parentMakeChunk != nil)
d.PanicIfFalse(hashValueBytes != nil)
@@ -51,10 +50,9 @@ func newSequenceChunker(ctx context.Context, format *Format, cur *sequenceCursor
makeChunk, parentMakeChunk,
true,
hashValueBytes,
newRollingValueHasher(format, byte(level%256)),
newRollingValueHasher(vrw.Format(), byte(level%256)),
false,
nil,
format,
}
if cur != nil {
@@ -171,7 +169,7 @@ func (sc *sequenceChunker) createParent(ctx context.Context) {
// Clone the parent cursor because otherwise calling cur.advance() will affect our parent - and vice versa - in surprising ways. Instead, Skip moves forward our parent's cursor if we advance across a boundary.
parent = sc.cur.parent
}
sc.parent = newSequenceChunker(ctx, sc.format, parent, sc.level+1, sc.vrw, sc.parentMakeChunk, sc.parentMakeChunk, metaHashValueBytes)
sc.parent = newSequenceChunker(ctx, parent, sc.level+1, sc.vrw, sc.parentMakeChunk, sc.parentMakeChunk, metaHashValueBytes)
sc.parent.isLeaf = false
if sc.unwrittenCol != nil {
@@ -205,11 +203,11 @@ func (sc *sequenceChunker) createSequence(ctx context.Context, write bool) (sequ
if write {
ref = sc.vrw.WriteValue(ctx, col)
} else {
ref = NewRef(col, sc.format)
ref = NewRef(col, sc.vrw.Format())
sc.unwrittenCol = col
}
mt := newMetaTuple(sc.format, ref, key, numLeaves)
mt := newMetaTuple(sc.vrw.Format(), ref, key, numLeaves)
return col.asSequence(), mt
}
@@ -275,7 +273,7 @@ func (sc *sequenceChunker) Done(ctx context.Context) sequence {
return child
}
mt = child.getItem(0, sc.format).(metaTuple)
mt = child.getItem(0, sc.vrw.Format()).(metaTuple)
}
}
+1 -1
View File
@@ -218,5 +218,5 @@ func makeSetLeafChunkFn(f *Format, vrw ValueReadWriter) makeChunkFn {
}
func newEmptySetSequenceChunker(ctx context.Context, f *Format, vrw ValueReadWriter) *sequenceChunker {
return newEmptySequenceChunker(ctx, f, vrw, makeSetLeafChunkFn(f, vrw), newOrderedMetaSequenceChunkFn(SetKind, f, vrw), hashValueBytes)
return newEmptySequenceChunker(ctx, vrw, makeSetLeafChunkFn(f, vrw), newOrderedMetaSequenceChunkFn(SetKind, f, vrw), hashValueBytes)
}
+1 -1
View File
@@ -92,7 +92,7 @@ func (se *SetEditor) Set(ctx context.Context) Set {
}
if ch == nil {
ch = newSequenceChunker(ctx, se.s.format, cur, 0, vrw, makeSetLeafChunkFn(se.s.format, vrw), newOrderedMetaSequenceChunkFn(SetKind, se.s.format, vrw), hashValueBytes)
ch = newSequenceChunker(ctx, cur, 0, vrw, makeSetLeafChunkFn(se.s.format, vrw), newOrderedMetaSequenceChunkFn(SetKind, se.s.format, vrw), hashValueBytes)
} else {
ch.advanceTo(ctx, cur)
}
+4 -4
View File
@@ -33,7 +33,7 @@ func readStruct(f *Format, dec *valueDecoder) Struct {
start := dec.pos()
skipStruct(f, dec)
end := dec.pos()
return Struct{valueImpl{dec.vrw, dec.byteSlice(start, end), nil}, f}
return Struct{valueImpl{dec.vrw, f, dec.byteSlice(start, end), nil}, f}
}
func skipStruct(f *Format, dec *valueDecoder) {
@@ -94,7 +94,7 @@ func newStruct(f *Format, name string, fieldNames []string, values []Value) Stru
}
values[i].writeTo(&w, f)
}
return Struct{valueImpl{vrw, w.data(), nil}, f}
return Struct{valueImpl{vrw, f, w.data(), nil}, f}
}
func NewStruct(format *Format, name string, data StructData) Struct {
@@ -287,7 +287,7 @@ func (s Struct) Set(n string, v Value) Struct {
v.writeTo(&w, s.format)
w.writeRaw(tail)
return Struct{valueImpl{s.vrw, w.data(), nil}, s.format}
return Struct{valueImpl{s.vrw, s.format, w.data(), nil}, s.format}
}
// splitFieldsAt splits the buffer into two parts. The fields coming before the field we are looking for
@@ -340,7 +340,7 @@ func (s Struct) Delete(n string) Struct {
w.writeRaw(head)
w.writeRaw(tail)
return Struct{valueImpl{s.vrw, w.data(), nil}, s.format}
return Struct{valueImpl{s.vrw, s.format, w.data(), nil}, s.format}
}
func (s Struct) Diff(last Struct, changes chan<- ValueChanged, closeChan <-chan struct{}) {
+4 -5
View File
@@ -48,7 +48,6 @@ func (itr *TupleIterator) Pos() uint64 {
type Tuple struct {
valueImpl
format *Format
}
// readTuple reads the data provided by a decoder and moves the decoder forward.
@@ -56,7 +55,7 @@ func readTuple(f *Format, dec *valueDecoder) Tuple {
start := dec.pos()
skipTuple(f, dec)
end := dec.pos()
return Tuple{valueImpl{dec.vrw, dec.byteSlice(start, end), nil}, f}
return Tuple{valueImpl{dec.vrw, f, dec.byteSlice(start, end), nil}}
}
func skipTuple(f *Format, dec *valueDecoder) {
@@ -87,7 +86,7 @@ func NewTuple(f *Format, values ...Value) Tuple {
}
values[i].writeTo(&w, f)
}
return Tuple{valueImpl{vrw, w.data(), nil}, f}
return Tuple{valueImpl{vrw, f, w.data(), nil}}
}
func (t Tuple) Empty() bool {
@@ -198,7 +197,7 @@ func (t Tuple) Set(n uint64, v Value) Tuple {
v.writeTo(&w, t.format)
w.writeRaw(tail)
return Tuple{valueImpl{t.vrw, w.data(), nil}, t.format}
return Tuple{valueImpl{t.vrw, t.format, w.data(), nil}}
}
func (t Tuple) Append(v Value) Tuple {
@@ -214,7 +213,7 @@ func (t Tuple) Append(v Value) Tuple {
w.writeRaw(dec.buff[fieldsOffset:])
v.writeTo(&w, t.format)
return Tuple{valueImpl{t.vrw, w.data(), nil}, t.format}
return Tuple{valueImpl{t.vrw, t.format, w.data(), nil}}
}
// splitFieldsAt splits the buffer into two parts. The fields coming before the field we are looking for
+1
View File
@@ -114,6 +114,7 @@ type valueReadWriter interface {
type valueImpl struct {
vrw ValueReadWriter
format *Format
buff []byte
offsets []uint32
}
+3 -3
View File
@@ -26,8 +26,8 @@ func newValueDecoderWithValidation(nr binaryNomsReader, vrw ValueReadWriter) val
return valueDecoder{typedBinaryNomsReader{nr, true}, vrw}
}
func (r *valueDecoder) readRef() Ref {
return readRef(&(r.typedBinaryNomsReader))
func (r *valueDecoder) readRef(f *Format) Ref {
return readRef(f, &(r.typedBinaryNomsReader))
}
func (r *valueDecoder) skipRef() {
@@ -203,7 +203,7 @@ func (r *valueDecoder) readValue(f *Format) Value {
case MapKind:
return newMap(r.readMapSequence(f), f)
case RefKind:
return r.readRef()
return r.readRef(f)
case SetKind:
return newSet(f, r.readSetSequence(f))
case StructKind:
+4 -4
View File
@@ -30,8 +30,8 @@ func newRefWalker(buff []byte) refWalker {
return refWalker{typedBinaryNomsReader{nr, false}}
}
func (r *refWalker) walkRef(cb RefCallback) {
cb(readRef(&(r.typedBinaryNomsReader)))
func (r *refWalker) walkRef(f *Format, cb RefCallback) {
cb(readRef(f, &(r.typedBinaryNomsReader)))
}
func (r *refWalker) walkBlobLeafSequence() {
@@ -95,7 +95,7 @@ func (r *refWalker) walkMapLeafSequence(f *Format, cb RefCallback) {
func (r *refWalker) walkMetaSequence(f *Format, k NomsKind, level uint64, cb RefCallback) {
count := r.readCount()
for i := uint64(0); i < count; i++ {
r.walkRef(cb) // ref to child sequence
r.walkRef(f, cb) // ref to child sequence
r.skipOrderedKey(f)
r.skipCount() // numLeaves
}
@@ -141,7 +141,7 @@ func (r *refWalker) walkValue(f *Format, cb RefCallback) {
case MapKind:
r.walkMap(f, cb)
case RefKind:
r.walkRef(cb)
r.walkRef(f, cb)
case SetKind:
r.walkSet(f, cb)
case StructKind: