types

package
v0.0.0-...-892de5e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2020 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Package types contains most of the data structures available to/from Noms.

Index

Constants

View Source
const (
	DEFAULT_MAX_SPLICE_MATRIX_SIZE = 2e7
	SPLICE_UNASSIGNED              = math.MaxUint64

	UNCHANGED = 0
	UPDATED   = 1
	INSERTED  = 2
	REMOVED   = 3
)

Variables

View Source
var EmptyStructType, _ = MakeStructType("")
View Source
var ErrKeysNotOrdered = errors.New("streaming map keys not ordered")
View Source
var ErrUnknownType = errors.New("unknown type")
View Source
var Format_7_18 = &NomsBinFormat{}
View Source
var Format_LD_1 = &NomsBinFormat{formatTag_LD_1}
View Source
var KindToString = map[NomsKind]string{
	UnknownKind:    "unknown",
	BlobKind:       "Blob",
	BoolKind:       "Bool",
	CycleKind:      "Cycle",
	ListKind:       "List",
	MapKind:        "Map",
	FloatKind:      "Float",
	RefKind:        "Ref",
	SetKind:        "Set",
	StructKind:     "Struct",
	StringKind:     "String",
	TypeKind:       "Type",
	UnionKind:      "Union",
	ValueKind:      "Value",
	UUIDKind:       "UUID",
	IntKind:        "Int",
	UintKind:       "Uint",
	NullKind:       "Null",
	TupleKind:      "Tuple",
	InlineBlobKind: "InlineBlob",
	TimestampKind:  "Timestamp",
	DecimalKind:    "Decimal",
}
View Source
var KindToTypeSlice []Value
View Source
var MaxPrimitiveKind int
View Source
var PrimitiveKindMask []bool
View Source
var PrimitiveTypeMap = map[NomsKind]*Type{
	ValueKind: makePrimitiveType(ValueKind),
}

PrimitiveTypeMap auto populates with Value types that return true from isPrimitive(). Only include a type here manually if it has no associated Value type.

Functions

func ApplyEdits

func ApplyEdits(ctx context.Context, edits EditProvider, m Map) (Map, AppliedEditStats, error)

ApplyEdits applies all the edits to a given Map and returns the resulting map, and some statistics about the edits that were applied.

func ContainCommonSupertype

func ContainCommonSupertype(nbf *NomsBinFormat, a, b *Type) bool

ContainCommonSupertype returns true if it's possible to synthesize a non-trivial (i.e. not empty) supertype from types |a| and |b|.

It is useful for determining whether a subset of values can be extracted from one object to produce another object.

The rules for determining whether |a| and |b| intersect are:

  • if either type is Value, return true
  • if either type is Union, return true iff at least one variant of |a| intersects with one variant of |b|
  • if |a| & |b| are not the same kind, return false
  • else
  • if both are structs, return true iff their names are equal or one name is "", they share a field name and the type of that field intersects
  • if both are refs, sets or lists, return true iff the element type intersects
  • if both are maps, return true iff they have a key with the same type and value types that intersect
  • else return true

func EncodeValue

func EncodeValue(v Value, nbf *NomsBinFormat) (chunks.Chunk, error)

func EncodedIndexValue

func EncodedIndexValue(ctx context.Context, v Value) (string, error)

func EncodedValue

func EncodedValue(ctx context.Context, v Value) (string, error)

EncodedValue returns a string containing the serialization of a value.

func EncodedValueMaxLines

func EncodedValueMaxLines(ctx context.Context, v Value, maxLines uint32) (string, error)

EncodedValueMaxLines returns a string containing the serialization of a value. The string is truncated at |maxLines|.

func EscapeStructField

func EscapeStructField(input string) string

EscapeStructField escapes names for use as noms structs with regards to non CSV imported data. Disallowed characters are encoded as 'Q<hex-encoded-utf8-bytes>'. Note that Q itself is also escaped since it is the escape character.

func HasStructCycles

func HasStructCycles(t *Type) bool

HasStructCycles determines if the type contains any struct cycles.

func HeightOrder

func HeightOrder(a, b Ref) bool

HeightOrder returns true if a is 'higher than' b, generally if its ref-height is greater. If the two are of the same height, fall back to sorting by TargetHash.

func IsNull

func IsNull(val Value) bool

IsNull returns true if the value is nil, or if the value is of kind NULLKind

func IsPrimitiveKind

func IsPrimitiveKind(k NomsKind) bool

IsPrimitiveKind returns true if k represents a Noms primitive type, which excludes collections (List, Map, Set), Refs, Structs, Symbolic and Unresolved types.

func IsSubtype

func IsSubtype(nbf *NomsBinFormat, requiredType, concreteType *Type) bool

IsSubtype determines whether concreteType is a subtype of requiredType. For example, `Float` is a subtype of `Float | String`.

func IsSubtypeDisallowExtraStructFields

func IsSubtypeDisallowExtraStructFields(nbf *NomsBinFormat, requiredType, concreteType *Type) bool

IsSubtypeDisallowExtraFields is a slightly weird variant of IsSubtype. It returns true IFF IsSubtype(requiredType, concreteType) AND Structs in concreteType CANNOT have field names absent in requiredType ISSUE: https://github.com/attic-labs/noms/issues/3446

func IsValidStructFieldName

func IsValidStructFieldName(name string) bool

IsValidStructFieldName returns whether the name is valid as a field name in a struct. Valid names must start with `a-zA-Z` and after that `a-zA-Z0-9_`.

func IsValueSubtypeOf

func IsValueSubtypeOf(nbf *NomsBinFormat, v Value, t *Type) (bool, error)

func IsValueSubtypeOfDetails

func IsValueSubtypeOfDetails(nbf *NomsBinFormat, v Value, t *Type) (bool, bool, error)

IsValueSubtypeOfDetails returns two values:

isSub - which indicates whether v is a subtype of t.
hasExtra - which indicates whether v has additional fields. This field has
           no meaning if IsSub is false.

For example, given the following data:

type1 := struct S {               v := Struct S1 {
    a Float | string                 a: "hello"
    b ?int                            b: 2
}                                 }

IsValueSubtypeOfDetails(v, type1) would return isSub == true, and hasExtra == false

And given these types:

type2 := struct S {               v := Struct S1 {
    a Float | string                 a: "hello"
    b ?int                            b: 2
}                                     c: "hello again"
                                  }

IsValueSubtypeOfDetails(v, type1) would return isSub == true, and hasExtra == true

func NewStreamingList

func NewStreamingList(ctx context.Context, vrw ValueReadWriter, ae *atomicerr.AtomicError, values <-chan Value) <-chan List

NewStreamingList creates a new List, populated with values, chunking if and when needed. As chunks are created, they're written to vrw -- including the root chunk of the list. Once the caller has closed values, the caller can read the completed List from the returned channel.

func NewStreamingMap

func NewStreamingMap(ctx context.Context, vrw ValueReadWriter, ae *atomicerr.AtomicError, kvs <-chan Value) <-chan Map

NewStreamingMap takes an input channel of values and returns a output channel that will produce a finished Map. Values sent to the input channel must be alternating keys and values. (e.g. k1, v1, k2, v2...). Moreover keys need to be added to the channel in Noms sortorder, adding key values to the input channel out of order will result in a panic. Once the input channel is closed by the caller, a finished Map will be sent to the output channel. See graph_builder.go for building collections with values that are not in order.

func NewStreamingSet

func NewStreamingSet(ctx context.Context, vrw ValueReadWriter, ae *atomicerr.AtomicError, vChan <-chan Value) <-chan Set

NewStreamingSet takes an input channel of values and returns a output channel that will produce a finished Set. Values that are sent to the input channel must be in Noms sortorder, adding values to the input channel out of order will result in a panic. Once the input channel is closed by the caller, a finished Set will be sent to the output channel. See graph_builder.go for building collections with values that are not in order.

func PanicIfDangling

func PanicIfDangling(ctx context.Context, unresolved hash.HashSet, cs chunks.ChunkStore)

func RegisterHRSCommenter

func RegisterHRSCommenter(typename, unique string, commenter HRSCommenter)

RegisterHRSCommenter is called to with three arguments:

typename: the name of the struct this function will be applied to
unique: an arbitrary string to differentiate functions that should be applied
  to different structs that have the same name (e.g. two implementations of
  the "Employee" type.
commenter: an interface with a 'Comment()' function that gets called for all
  Values with this name. The function should verify the type of the Value
  and, if appropriate, return a non-empty string to be appended as the comment

func SearchWithErroringLess

func SearchWithErroringLess(n int, f func(i int) (bool, error)) (int, error)

func SortWithErroringLess

func SortWithErroringLess(data SortData) error

func UnregisterHRSCommenter

func UnregisterHRSCommenter(typename, unique string)

UnregisterHRSCommenter will remove a commenter function for a specified typename/unique string combination.

func ValueCanBePathIndex

func ValueCanBePathIndex(v Value) bool

func WalkRefs

func WalkRefs(c chunks.Chunk, nbf *NomsBinFormat, cb RefCallback) error

WalkRefs calls cb() on each Ref that can be decoded from |c|. The results are precisely equal to DecodeValue(c).WalkRefs(cb), but this should be much faster.

func WalkValues

func WalkValues(ctx context.Context, nbf *NomsBinFormat, target Value, vr ValueReader, cb SkipValueCallback) error

WalkValues recursively walks over all types.Values reachable from r and calls cb on them.

func WriteEncodedValue

func WriteEncodedValue(ctx context.Context, w io.Writer, v Value) error

WriteEncodedValue writes the serialization of a value

func WriteEncodedValueMaxLines

func WriteEncodedValueMaxLines(ctx context.Context, w io.Writer, v Value, maxLines uint32) error

WriteEncodedValueMaxLines writes the serialization of a value. Writing will be stopped and an error returned after |maxLines|.

func WriteValueStats

func WriteValueStats(ctx context.Context, w io.Writer, v Value, vr ValueReader) error

Types

type AppliedEditStats

type AppliedEditStats struct {
	// Additions counts the number of elements added to the map
	Additions int64

	// Modifications counts the number of map entries that were modified
	Modifications int64

	// SamVal counts the number of edits that had no impact because a value was set to the same value that is already
	// stored in the map
	SameVal int64

	// Deletions counts the number of items deleted from the map
	Deletions int64

	// NonexistantDeletes counts the number of items where a deletion was attempted, but the key didn't exist in the map
	// so there was no impact
	NonExistentDeletes int64
}

AppliedEditStats contains statistics on what edits were applied in types.ApplyEdits

func (AppliedEditStats) Add

Add adds two AppliedEditStats structures member by member.

type AtAnnotation

type AtAnnotation struct {
	// Index is the position to resolve at. If negative, it means an index
	// relative to the end of the collection.
	Index int64
	// IntoKey see IndexPath.IntoKey.
	IntoKey bool
}

AtAnnotation is a PathPart annotation that gets the value of a collection at a position, rather than a key. This is equivalent to IndexPath for lists, but different for sets and maps.

func NewAtAnnotation

func NewAtAnnotation(idx int64) AtAnnotation

func (AtAnnotation) Resolve

func (ann AtAnnotation) Resolve(ctx context.Context, v Value, vr ValueReader) (Value, error)

func (AtAnnotation) String

func (ann AtAnnotation) String() (str string)

type Blob

type Blob struct {
	// contains filtered or unexported fields
}

Blob represents a list of Blobs.

func NewBlob

func NewBlob(ctx context.Context, vrw ValueReadWriter, rs ...io.Reader) (Blob, error)

NewBlob creates a Blob by reading from every Reader in rs and concatenating the result. NewBlob uses one goroutine per Reader.

func NewEmptyBlob

func NewEmptyBlob(vrw ValueReadWriter) (Blob, error)

func (Blob) Concat

func (b Blob) Concat(ctx context.Context, other Blob) (Blob, error)

Concat returns a new Blob comprised of this joined with other. It only needs to visit the rightmost prolly tree chunks of this Blob, and the leftmost prolly tree chunks of other, so it's efficient.

func (Blob) Copy

func (b Blob) Copy(ctx context.Context, w io.Writer) (int64, error)

func (Blob) CopyReadAhead

func (b Blob) CopyReadAhead(ctx context.Context, w io.Writer, chunkSize uint64, concurrency int) (int64, error)

CopyReadAhead copies the entire contents of |b| to |w|, and attempts to stay |concurrency| |chunkSize| blocks of bytes ahead of the last byte written to |w|.

func (Blob) HumanReadableString

func (b Blob) HumanReadableString() string

func (Blob) Kind

func (b Blob) Kind() NomsKind

func (Blob) ReadAt

func (b Blob) ReadAt(ctx context.Context, p []byte, off int64) (n int, err error)

ReadAt implements the ReaderAt interface. Eagerly loads requested byte-range from the blob p-tree.

func (Blob) Reader

func (b Blob) Reader(ctx context.Context) *BlobReader

func (Blob) String

func (b Blob) String() string

func (Blob) Value

func (b Blob) Value(ctx context.Context) (Value, error)

Value interface

func (Blob) WalkValues

func (b Blob) WalkValues(ctx context.Context, cb ValueCallback) error

type BlobReader

type BlobReader struct {
	// contains filtered or unexported fields
}

func (*BlobReader) Read

func (cbr *BlobReader) Read(p []byte) (n int, err error)

func (*BlobReader) Seek

func (cbr *BlobReader) Seek(offset int64, whence int) (int64, error)

type Bool

type Bool bool

Bool is a Noms Value wrapper around the primitive bool type.

func (Bool) Equals

func (b Bool) Equals(other Value) bool

func (Bool) Hash

func (b Bool) Hash(nbf *NomsBinFormat) (hash.Hash, error)

func (Bool) HumanReadableString

func (b Bool) HumanReadableString() string

func (Bool) Kind

func (b Bool) Kind() NomsKind

func (Bool) Less

func (b Bool) Less(nbf *NomsBinFormat, other LesserValuable) (bool, error)

func (Bool) Value

func (b Bool) Value(ctx context.Context) (Value, error)

Value interface

func (Bool) WalkRefs

func (b Bool) WalkRefs(nbf *NomsBinFormat, cb RefCallback) error

func (Bool) WalkValues

func (b Bool) WalkValues(ctx context.Context, cb ValueCallback) error

type Collection

type Collection interface {
	Value
	Emptyable
	Len() uint64
	// contains filtered or unexported methods
}

func LoadLeafNodes

func LoadLeafNodes(ctx context.Context, cols []Collection, startIdx, endIdx uint64) ([]Collection, uint64, error)

LoadLeafNodes loads the set of leaf nodes which contain the items [startIdx -> endIdx). Returns the set of nodes and the offset within the first sequence which corresponds to |startIdx|.

type CompoundDesc

type CompoundDesc struct {
	ElemTypes typeSlice
	// contains filtered or unexported fields
}

CompoundDesc describes a List, Map, Set, Ref, or Union type. ElemTypes indicates what type or types are in the container indicated by kind, e.g. Map key and value or Set element.

func (CompoundDesc) Kind

func (c CompoundDesc) Kind() NomsKind

type CreateEditAcc

type CreateEditAcc func(nbf *NomsBinFormat) EditAccumulator

CreateEditAcc defines a factory method for EditAccumulator creation

var CreateEditAccForMapEdits CreateEditAcc = NewDumbEditAccumulator

CreateEditAccForMapEdits allows users to define the EditAccumulator that should be used when creating a MapEditor via the Map.Edit method. In most cases you should call:

func init() {
		types.CreateEditAccForMapEdits = func() EditAccumulator {
			return edits.NewAsyncSortedEdits(10000, 4, 2) // configure your own constants
		}
}

type CycleDesc

type CycleDesc string

func (CycleDesc) Kind

func (c CycleDesc) Kind() NomsKind

type Decimal

type Decimal decimal.Decimal

func (Decimal) Equals

func (v Decimal) Equals(other Value) bool

func (Decimal) Hash

func (v Decimal) Hash(nbf *NomsBinFormat) (hash.Hash, error)

func (Decimal) HumanReadableString

func (v Decimal) HumanReadableString() string

func (Decimal) Kind

func (v Decimal) Kind() NomsKind

func (Decimal) Less

func (v Decimal) Less(nbf *NomsBinFormat, other LesserValuable) (bool, error)

func (Decimal) Value

func (v Decimal) Value(ctx context.Context) (Value, error)

func (Decimal) WalkRefs

func (v Decimal) WalkRefs(nbf *NomsBinFormat, cb RefCallback) error

func (Decimal) WalkValues

func (v Decimal) WalkValues(ctx context.Context, cb ValueCallback) error

type DecodedChunk

type DecodedChunk struct {
	Chunk *chunks.Chunk
	Value *Value
}

DecodedChunk holds a pointer to a Chunk and the Value that results from calling DecodeFromBytes(c.Data()).

type DiffChangeType

type DiffChangeType uint8
const (
	DiffChangeAdded DiffChangeType = iota
	DiffChangeRemoved
	DiffChangeModified
)

type DumbEditAccumulator

type DumbEditAccumulator struct {
	// contains filtered or unexported fields
}

DumbEditAccumulator is a simple EditAccumulator and EditProvider implementation that allows for more complex implementations to be put into other packages. It is fine for small edits, and tests, but edits.AsyncSortedEdits performs much better for large amounts of data

func (*DumbEditAccumulator) AddEdit

func (dumb *DumbEditAccumulator) AddEdit(k LesserValuable, v Valuable)

AddEdit adds an edit to the list of edits

func (*DumbEditAccumulator) Close

func (dumb *DumbEditAccumulator) Close()

Close satisfies the EditAccumulator interface

func (*DumbEditAccumulator) FinishedEditing

func (dumb *DumbEditAccumulator) FinishedEditing() (EditProvider, error)

FinishEditing should be called when all edits have been added to get an EditProvider which provides the edits in sorted order. Adding more edits after calling FinishedEditing is an error

func (*DumbEditAccumulator) Next

func (dumb *DumbEditAccumulator) Next() (*KVP, error)

Next returns the next KVP representing the next edit to be applied. Next will always return KVPs in key sorted order

func (*DumbEditAccumulator) NumEdits

func (dumb *DumbEditAccumulator) NumEdits() int64

NumEdits returns the number of KVPs representing the edits that will be provided when calling next

type EditAccumulator

type EditAccumulator interface {
	// AddEdit adds an edit to the list of edits
	AddEdit(k LesserValuable, v Valuable)

	// FinishEditing should be called when all edits have been added to get an EditProvider which provides the
	// edits in sorted order. Adding more edits after calling FinishedEditing is an error.
	FinishedEditing() (EditProvider, error)

	// Close ensures that the accumulator is closed. Repeat calls are allowed. Not guaranteed to be thread-safe, thus
	// requires external synchronization.
	Close()
}

EditAccumulator is an interface for a datastructure that can have edits added to it. Once all edits are added FinishedEditing can be called to get an EditProvider which provides the edits in sorted order

func NewDumbEditAccumulator

func NewDumbEditAccumulator(nbf *NomsBinFormat) EditAccumulator

NewDumbEditAccumulator is a factory method for creation of DumbEditAccumulators

type EditDistanceEqualsFn

type EditDistanceEqualsFn func(prevIndex uint64, currentIndex uint64) (bool, error)

type EditProvider

type EditProvider interface {
	// Next returns the next KVP representing the next edit to be applied.  Next will always return KVPs
	// in key sorted order
	Next() (*KVP, error)

	// NumEdits returns the number of KVPs representing the edits that will be provided when calling next
	NumEdits() int64
}

EditProvider is an interface which provides map edits as KVPs where each edit is a key and the new value associated with the key for inserts and updates. deletes are modeled as a key with no value

type EmptyEditProvider

type EmptyEditProvider struct{}

EmptyEditProvider is an EditProvider implementation that has no edits

func (EmptyEditProvider) Next

func (eep EmptyEditProvider) Next() (*KVP, error)

Next will always return nil

func (EmptyEditProvider) NumEdits

func (eep EmptyEditProvider) NumEdits() int64

NumEdits will always return 0

type Emptyable

type Emptyable interface {
	Empty() bool
}

Emptyable is an interface for Values which may or may not be empty

type FieldMap

type FieldMap map[string]*Type

type FieldPath

type FieldPath struct {
	// The name of the field, e.g. `.Name`.
	Name string
}

FieldPath references Struct field values by name.

func NewFieldPath

func NewFieldPath(name string) FieldPath

func (FieldPath) Resolve

func (fp FieldPath) Resolve(ctx context.Context, v Value, vr ValueReader) (Value, error)

func (FieldPath) String

func (fp FieldPath) String() string

type Float

type Float float64

Float is a Noms Value wrapper around the primitive float64 type.

func (Float) Equals

func (v Float) Equals(other Value) bool

func (Float) Hash

func (v Float) Hash(nbf *NomsBinFormat) (hash.Hash, error)

func (Float) HumanReadableString

func (v Float) HumanReadableString() string

func (Float) Kind

func (v Float) Kind() NomsKind

func (Float) Less

func (v Float) Less(nbf *NomsBinFormat, other LesserValuable) (bool, error)

func (Float) Value

func (v Float) Value(ctx context.Context) (Value, error)

Value interface

func (Float) WalkRefs

func (v Float) WalkRefs(nbf *NomsBinFormat, cb RefCallback) error

func (Float) WalkValues

func (v Float) WalkValues(ctx context.Context, cb ValueCallback) error

type HRSCommenter

type HRSCommenter interface {
	Comment(context.Context, Value) string
}

Function type for commenter functions

func GetHRSCommenters

func GetHRSCommenters(typename string) []HRSCommenter

GetHRSCommenters the map of 'unique' strings to HRSCommentFunc for a specified typename.

type HashIndexPath

type HashIndexPath struct {
	// The hash of the key or value to search for. Maps and Set are ordered, so
	// this in O(log(size)).
	Hash hash.Hash
	// Whether this index should resolve to the key of a map, given by a `@key`
	// annotation. Typically IntoKey is false, and indices would resolve to the
	// values. E.g. given `{a: 42}` and if the hash of `"a"` is `#abcd`, then
	// `[#abcd]` resolves to `42`. If IntoKey is true, then it resolves to `"a"`.
	// This is useful for when Map keys aren't primitive values, e.g. a struct,
	// since struct literals can't be spelled using a Path.
	IntoKey bool
}

Indexes into Maps by the hash of a key, or a Set by the hash of a value.

func NewHashIndexPath

func NewHashIndexPath(h hash.Hash) HashIndexPath

func (HashIndexPath) Resolve

func (hip HashIndexPath) Resolve(ctx context.Context, v Value, vr ValueReader) (Value, error)

func (HashIndexPath) String

func (hip HashIndexPath) String() (str string)

type IndexPath

type IndexPath struct {
	// The value of the index, e.g. `[42]` or `["value"]`. If Index is a negative
	// number and the path is resolved in a List, it means index from the back.
	Index Value
	// Whether this index should resolve to the key of a map, given by a `@key`
	// annotation. Typically IntoKey is false, and indices would resolve to the
	// values. E.g. given `{a: 42}` then `["a"]` resolves to `42`. If IntoKey is
	// true, then it resolves to `"a"`. For IndexPath this isn't particularly
	// useful - it's mostly provided for consistency with HashIndexPath - but
	// note that given `{a: 42}` then `["b"]` resolves to nil, not `"b"`.
	IntoKey bool
}

IndexPath ndexes into Maps and Lists by key or index.

func NewIndexPath

func NewIndexPath(idx Value) IndexPath

func (IndexPath) Resolve

func (ip IndexPath) Resolve(ctx context.Context, v Value, vr ValueReader) (Value, error)

func (IndexPath) String

func (ip IndexPath) String() (str string)

type InlineBlob

type InlineBlob []byte

func (InlineBlob) Equals

func (v InlineBlob) Equals(other Value) bool

func (InlineBlob) Hash

func (v InlineBlob) Hash(nbf *NomsBinFormat) (hash.Hash, error)

func (InlineBlob) HumanReadableString

func (v InlineBlob) HumanReadableString() string

func (InlineBlob) Kind

func (v InlineBlob) Kind() NomsKind

func (InlineBlob) Less

func (v InlineBlob) Less(nbf *NomsBinFormat, other LesserValuable) (bool, error)

func (InlineBlob) Value

func (v InlineBlob) Value(ctx context.Context) (Value, error)

func (InlineBlob) WalkRefs

func (v InlineBlob) WalkRefs(nbf *NomsBinFormat, cb RefCallback) error

func (InlineBlob) WalkValues

func (v InlineBlob) WalkValues(ctx context.Context, cb ValueCallback) error

type Int

type Int int64

Int is a Noms Value wrapper around the primitive int32 type.

func (Int) Equals

func (v Int) Equals(other Value) bool

func (Int) Hash

func (v Int) Hash(nbf *NomsBinFormat) (hash.Hash, error)

func (Int) HumanReadableString

func (v Int) HumanReadableString() string

func (Int) Kind

func (v Int) Kind() NomsKind

func (Int) Less

func (v Int) Less(nbf *NomsBinFormat, other LesserValuable) (bool, error)

func (Int) Value

func (v Int) Value(ctx context.Context) (Value, error)

Value interface

func (Int) WalkRefs

func (v Int) WalkRefs(nbf *NomsBinFormat, cb RefCallback) error

func (Int) WalkValues

func (v Int) WalkValues(ctx context.Context, cb ValueCallback) error

type IntersectionIterator

type IntersectionIterator struct {
	// contains filtered or unexported fields
}

IntersectionIterator only returns values that are returned in both of its child iterators. The values from Next() are returned in noms-defined order with all duplicates removed.

func (*IntersectionIterator) Next

func (*IntersectionIterator) SkipTo

func (i *IntersectionIterator) SkipTo(ctx context.Context, v Value) (Value, error)

type KVP

type KVP struct {
	// Key is the key
	Key LesserValuable

	// Val is the value
	Val Valuable
}

KVP is a simple key value pair

type KVPSlice

type KVPSlice []KVP

KVPSlice is a slice of KVPs that implements sort.Interface

type KVPSort

type KVPSort struct {
	Values []KVP
	NBF    *NomsBinFormat
}

func (KVPSort) Len

func (kvps KVPSort) Len() int

Len returns the size of the slice

func (KVPSort) Less

func (kvps KVPSort) Less(i, j int) (bool, error)

Less returns a bool representing whether the key at index i is less than the key at index j

func (KVPSort) Swap

func (kvps KVPSort) Swap(i, j int)

Swap swaps the KVP at index i with the KVP at index j

type LesserValuable

type LesserValuable interface {
	Valuable
	// Less determines if this Noms value is less than another Noms value.
	// When comparing two Noms values and both are comparable and the same type (Bool, Float or
	// String) then the natural ordering is used. For other Noms values the Hash of the value is
	// used. When comparing Noms values of different type the following ordering is used:
	// Bool < Float < String < everything else.
	Less(nbf *NomsBinFormat, other LesserValuable) (bool, error)
}

type List

type List struct {
	// contains filtered or unexported fields
}

List represents a list or an array of Noms values. A list can contain zero or more values of zero or more types. The type of the list will reflect the type of the elements in the list. For example:

l := NewList(Float(1), Bool(true))
fmt.Println(l.Type().Describe())
// outputs List<Bool | Float>

Lists, like all Noms values are immutable so the "mutation" methods return a new list.

var EmptyList List

func NewList

func NewList(ctx context.Context, vrw ValueReadWriter, values ...Value) (List, error)

NewList creates a new List where the type is computed from the elements in the list, populated with values, chunking if and when needed.

func (List) Concat

func (l List) Concat(ctx context.Context, other List) (List, error)

Concat returns a new List comprised of this joined with other. It only needs to visit the rightmost prolly tree chunks of this List, and the leftmost prolly tree chunks of other, so it's efficient.

func (List) Diff

func (l List) Diff(ctx context.Context, last List, changes chan<- Splice, closeChan <-chan struct{}) error

Diff streams the diff from last to the current list to the changes channel. Caller can close closeChan to cancel the diff operation.

func (List) DiffWithLimit

func (l List) DiffWithLimit(ctx context.Context, last List, changes chan<- Splice, closeChan <-chan struct{}, maxSpliceMatrixSize uint64) error

DiffWithLimit streams the diff from last to the current list to the changes channel. Caller can close closeChan to cancel the diff operation. The maxSpliceMatrixSize determines the how big of an edit distance matrix we are willing to compute versus just saying the thing changed.

func (List) Edit

func (l List) Edit() *ListEditor

func (List) Format

func (l List) Format() *NomsBinFormat

func (List) Get

func (l List) Get(ctx context.Context, idx uint64) (Value, error)

Get returns the value at the given index. If this list has been chunked then this will have to descend into the prolly-tree which leads to Get being O(depth).

func (List) HumanReadableString

func (l List) HumanReadableString() string

func (List) Iter

func (l List) Iter(ctx context.Context, f func(v Value, index uint64) (stop bool)) error

Iter iterates over the list and calls f for every element in the list. If f returns true then the iteration stops.

func (List) IterAll

func (l List) IterAll(ctx context.Context, f func(v Value, index uint64) error) error

IterAll iterates over the list and calls f for every element in the list. Unlike Iter there is no way to stop the iteration and all elements are visited.

func (List) IterRange

func (l List) IterRange(ctx context.Context, startIdx, endIdx uint64, f func(v Value, idx uint64) error) error

func (List) Iterator

func (l List) Iterator(ctx context.Context) (ListIterator, error)

Iterator returns a ListIterator which can be used to iterate efficiently over a list.

func (List) IteratorAt

func (l List) IteratorAt(ctx context.Context, index uint64) (ListIterator, error)

IteratorAt returns a ListIterator starting at index. If index is out of bound the iterator will have reached its end on creation.

func (List) String

func (l List) String() string

func (List) ToSet

func (l List) ToSet(ctx context.Context) (Set, error)

func (List) Value

func (l List) Value(ctx context.Context) (Value, error)

Value interface

func (List) WalkValues

func (l List) WalkValues(ctx context.Context, cb ValueCallback) error

type ListEditor

type ListEditor struct {
	// contains filtered or unexported fields
}

func NewListEditor

func NewListEditor(l List) *ListEditor

func (*ListEditor) Append

func (le *ListEditor) Append(vs ...Valuable) *ListEditor

func (*ListEditor) Get

func (le *ListEditor) Get(ctx context.Context, idx uint64) (Valuable, error)

func (*ListEditor) Insert

func (le *ListEditor) Insert(idx uint64, vs ...Valuable) *ListEditor

func (*ListEditor) Kind

func (le *ListEditor) Kind() NomsKind

func (*ListEditor) Len

func (le *ListEditor) Len() uint64

func (*ListEditor) List

func (le *ListEditor) List(ctx context.Context) (List, error)

func (*ListEditor) Remove

func (le *ListEditor) Remove(start uint64, end uint64) *ListEditor

func (*ListEditor) RemoveAt

func (le *ListEditor) RemoveAt(idx uint64) *ListEditor

func (*ListEditor) Set

func (le *ListEditor) Set(idx uint64, v Valuable) *ListEditor

func (*ListEditor) Splice

func (le *ListEditor) Splice(idx uint64, deleteCount uint64, vs ...Valuable) *ListEditor

func (*ListEditor) Value

func (le *ListEditor) Value(ctx context.Context) (Value, error)

type ListIterator

type ListIterator struct {
	// contains filtered or unexported fields
}

ListIterator can be used to efficiently iterate through a Noms List.

func (ListIterator) Next

func (li ListIterator) Next(ctx context.Context) (Value, error)

Next returns subsequent Values from a List, starting with the index at which the iterator was created. If there are no more Values, Next() returns nil.

type Map

type Map struct {
	// contains filtered or unexported fields
}
var EmptyMap Map

func NewMap

func NewMap(ctx context.Context, vrw ValueReadWriter, kv ...Value) (Map, error)

func (Map) Any

func (m Map) Any(ctx context.Context, cb func(k, v Value) bool) (yep bool, err error)

Any returns true if cb() return true for any of the items in the map.

func (Map) At

func (m Map) At(ctx context.Context, idx uint64) (key, value Value, err error)

func (Map) BufferedIterator

func (m Map) BufferedIterator(ctx context.Context) (MapIterator, error)

func (Map) BufferedIteratorAt

func (m Map) BufferedIteratorAt(ctx context.Context, pos uint64) (MapIterator, error)

func (Map) Diff

func (m Map) Diff(ctx context.Context, last Map, ae *atomicerr.AtomicError, changes chan<- ValueChanged, closeChan <-chan struct{})

Diff computes the diff from |last| to |m| using the top-down algorithm, which completes as fast as possible while taking longer to return early results than left-to-right.

func (Map) DiffHybrid

func (m Map) DiffHybrid(ctx context.Context, last Map, ae *atomicerr.AtomicError, changes chan<- ValueChanged, closeChan <-chan struct{})

DiffHybrid computes the diff from |last| to |m| using a hybrid algorithm which balances returning results early vs completing quickly, if possible.

func (Map) DiffLeftRight

func (m Map) DiffLeftRight(ctx context.Context, last Map, ae *atomicerr.AtomicError, changes chan<- ValueChanged, closeChan <-chan struct{})

DiffLeftRight computes the diff from |last| to |m| using a left-to-right streaming approach, optimised for returning results early, but not completing quickly.

func (Map) Edit

func (m Map) Edit() *MapEditor

func (Map) First

func (m Map) First(ctx context.Context) (Value, Value, error)

func (Map) Format

func (m Map) Format() *NomsBinFormat

func (Map) Has

func (m Map) Has(ctx context.Context, key Value) (bool, error)

func (Map) HumanReadableString

func (m Map) HumanReadableString() string

func (Map) Iter

func (m Map) Iter(ctx context.Context, cb mapIterCallback) error

func (Map) IterAll

func (m Map) IterAll(ctx context.Context, cb mapIterAllCallback) error

func (Map) IterFrom

func (m Map) IterFrom(ctx context.Context, start Value, cb mapIterCallback) error

func (Map) Iterator

func (m Map) Iterator(ctx context.Context) (MapIterator, error)

func (Map) IteratorAt

func (m Map) IteratorAt(ctx context.Context, pos uint64) (MapIterator, error)

func (Map) IteratorBackFrom

func (m Map) IteratorBackFrom(ctx context.Context, key Value) (MapIterator, error)

func (Map) IteratorFrom

func (m Map) IteratorFrom(ctx context.Context, key Value) (MapIterator, error)

func (Map) Last

func (m Map) Last(ctx context.Context) (Value, Value, error)

func (Map) MaybeGet

func (m Map) MaybeGet(ctx context.Context, key Value) (v Value, ok bool, err error)

func (Map) String

func (m Map) String() string

func (Map) Value

func (m Map) Value(ctx context.Context) (Value, error)

Value interface

func (Map) WalkValues

func (m Map) WalkValues(ctx context.Context, cb ValueCallback) error

type MapEditor

type MapEditor struct {
	// contains filtered or unexported fields
}

MapEditor allows for efficient editing of Map-typed prolly trees.

func NewMapEditor

func NewMapEditor(m Map) *MapEditor

func (*MapEditor) Format

func (med *MapEditor) Format() *NomsBinFormat

func (*MapEditor) Map

func (med *MapEditor) Map(ctx context.Context) (Map, error)

Map applies all edits and returns a newly updated Map

func (*MapEditor) NumEdits

func (med *MapEditor) NumEdits() int64

NumEdits returns the number of edits that have been added.

func (*MapEditor) Remove

func (med *MapEditor) Remove(k LesserValuable) *MapEditor

Remove adds an edit that will remove a value by key

func (*MapEditor) Set

func (med *MapEditor) Set(k LesserValuable, v Valuable) *MapEditor

Set adds an edit

func (*MapEditor) SetM

func (med *MapEditor) SetM(kv ...Valuable) *MapEditor

SetM adds M edits where even values are keys followed by their respective value

type MapIterator

type MapIterator interface {
	Next(ctx context.Context) (k, v Value, err error)
}

MapIterator is the interface used by iterators over Noms Maps.

type MarshalCallback

type MarshalCallback func(val Value) (Value, error)

type NomsBinFormat

type NomsBinFormat struct {
	// contains filtered or unexported fields
}
var Format_Default *NomsBinFormat

func GetFormatForVersionString

func GetFormatForVersionString(s string) (*NomsBinFormat, error)

func (*NomsBinFormat) VersionString

func (nbf *NomsBinFormat) VersionString() string

type NomsKind

type NomsKind uint8

NomsKind allows a TypeDesc to indicate what kind of type is described.

const (
	BoolKind NomsKind = iota
	FloatKind
	StringKind
	BlobKind
	ValueKind
	ListKind
	MapKind
	RefKind
	SetKind

	// Keep StructKind and CycleKind together.
	StructKind
	CycleKind

	TypeKind
	UnionKind

	UUIDKind
	IntKind
	UintKind
	NullKind
	TupleKind
	InlineBlobKind
	TimestampKind
	DecimalKind

	UnknownKind NomsKind = 255
)

All supported kinds of Noms types are enumerated here. The ordering of these (especially Bool, Float and String) is important for ordering of values.

func (NomsKind) String

func (k NomsKind) String() string

String returns the name of the kind.

type Null

type Null byte

Int is a Noms Value wrapper around the primitive int32 type.

var NullValue Null

func (Null) Equals

func (v Null) Equals(other Value) bool

func (Null) Hash

func (v Null) Hash(nbf *NomsBinFormat) (hash.Hash, error)

func (Null) HumanReadableString

func (v Null) HumanReadableString() string

func (Null) Kind

func (v Null) Kind() NomsKind

func (Null) Less

func (v Null) Less(nbf *NomsBinFormat, other LesserValuable) (bool, error)

func (Null) Value

func (v Null) Value(ctx context.Context) (Value, error)

Value interface

func (Null) WalkRefs

func (v Null) WalkRefs(nbf *NomsBinFormat, cb RefCallback) error

func (Null) WalkValues

func (v Null) WalkValues(ctx context.Context, cb ValueCallback) error

type Path

type Path []PathPart

A Path locates a value in Noms relative to some other value. For locating values absolutely within a database, see AbsolutePath. To locate values globally, see Spec.

For more details, see: https://github.com/attic-labs/noms/blob/master/doc/spelling.md.

func MustParsePath

func MustParsePath(str string) Path

MustParsePath parses str into a Path, or panics if parsing failed.

func ParsePath

func ParsePath(str string) (Path, error)

ParsePath parses str into a Path, or returns an error if parsing failed.

func (Path) Append

func (p Path) Append(pp PathPart) Path

Append makes a copy of a p and appends the PathPart 'pp' to it.

func (Path) Equals

func (p Path) Equals(o Path) bool

func (Path) IsEmpty

func (p Path) IsEmpty() bool

func (Path) Resolve

func (p Path) Resolve(ctx context.Context, v Value, vr ValueReader) (Value, error)

Resolve resolves a path relative to some value. A ValueReader is required to resolve paths that contain the @target annotation.

func (Path) String

func (p Path) String() string

type PathPart

type PathPart interface {
	Resolve(ctx context.Context, v Value, vr ValueReader) (Value, error)
	String() string
}

type PrimitiveDesc

type PrimitiveDesc NomsKind

PrimitiveDesc implements TypeDesc for all primitive Noms types: Blob Bool Float String Type Value UUID Int Uint

func (PrimitiveDesc) Kind

func (p PrimitiveDesc) Kind() NomsKind

type Ref

type Ref struct {
	// contains filtered or unexported fields
}

func NewRef

func NewRef(v Value, nbf *NomsBinFormat) (Ref, error)

func ToRefOfValue

func ToRefOfValue(r Ref, nbf *NomsBinFormat) (Ref, error)

ToRefOfValue returns a new Ref that points to the same target as |r|, but with the type 'Ref<Value>'.

func (Ref) Equals

func (v Ref) Equals(other Value) bool

func (Ref) Format

func (r Ref) Format() *NomsBinFormat

func (Ref) Hash

func (v Ref) Hash(*NomsBinFormat) (hash.Hash, error)

func (Ref) Height

func (r Ref) Height() uint64

func (Ref) HumanReadableString

func (r Ref) HumanReadableString() string

func (Ref) IsZeroValue

func (v Ref) IsZeroValue() bool

IsZeroValue can be used to test if a Value is the same as T{}.

func (Ref) Kind

func (v Ref) Kind() NomsKind

func (Ref) Less

func (v Ref) Less(nbf *NomsBinFormat, other LesserValuable) (bool, error)

func (Ref) String

func (r Ref) String() string

func (Ref) TargetHash

func (r Ref) TargetHash() hash.Hash

func (Ref) TargetType

func (r Ref) TargetType() (*Type, error)

func (Ref) TargetValue

func (r Ref) TargetValue(ctx context.Context, vr ValueReader) (Value, error)

func (Ref) Value

func (r Ref) Value(ctx context.Context) (Value, error)

func (Ref) WalkRefs

func (v Ref) WalkRefs(nbf *NomsBinFormat, cb RefCallback) error

func (Ref) WalkValues

func (r Ref) WalkValues(ctx context.Context, cb ValueCallback) error

type RefByHeight

type RefByHeight []Ref

RefByHeight implements sort.Interface to order by increasing HeightOrder(). It uses increasing order because this causes repeated pushes and pops of the 'tallest' Refs to re-use memory, avoiding reallocations. We might consider making this a firmer abstraction boundary as a part of BUG 2182

func (*RefByHeight) DropIndices

func (h *RefByHeight) DropIndices(indices []int)

DropIndices takes a slice of integer indices into h and splices out the Refs at those indices.

func (RefByHeight) Empty

func (h RefByHeight) Empty() bool

func (RefByHeight) Len

func (h RefByHeight) Len() int

func (RefByHeight) Less

func (h RefByHeight) Less(i, j int) bool

func (RefByHeight) MaxHeight

func (h RefByHeight) MaxHeight() uint64

MaxHeight returns the height of the 'tallest' Ref in h.

func (RefByHeight) PeekAt

func (h RefByHeight) PeekAt(idx int) (peek Ref)

PeekAt returns, but does not remove, the Ref at h[idx]. If the index is out of range, returns the empty Ref.

func (RefByHeight) PeekEnd

func (h RefByHeight) PeekEnd() (head Ref)

PeekEnd returns, but does not Pop the tallest Ref in h.

func (*RefByHeight) PopBack

func (h *RefByHeight) PopBack() Ref

func (*RefByHeight) PopRefsOfHeight

func (h *RefByHeight) PopRefsOfHeight(height uint64) (refs RefSlice)

PopRefsOfHeight pops off and returns all refs r in h for which r.Height() == height.

func (*RefByHeight) PushBack

func (h *RefByHeight) PushBack(r Ref)

func (RefByHeight) Swap

func (h RefByHeight) Swap(i, j int)

func (*RefByHeight) Unique

func (h *RefByHeight) Unique()

type RefCallback

type RefCallback func(ref Ref) error

type RefSlice

type RefSlice []Ref

RefSlice implements sort.Interface to order by target ref.

func (RefSlice) Len

func (s RefSlice) Len() int

func (RefSlice) Less

func (s RefSlice) Less(i, j int) bool

func (RefSlice) Swap

func (s RefSlice) Swap(i, j int)

type Set

type Set struct {
	// contains filtered or unexported fields
}
var EmptySet Set

func NewSet

func NewSet(ctx context.Context, vrw ValueReadWriter, v ...Value) (Set, error)

func (Set) At

func (s Set) At(ctx context.Context, idx uint64) (Value, error)

func (Set) Diff

func (s Set) Diff(ctx context.Context, last Set, ae *atomicerr.AtomicError, changes chan<- ValueChanged, closeChan <-chan struct{})

Diff computes the diff from |last| to |m| using the top-down algorithm, which completes as fast as possible while taking longer to return early results than left-to-right.

func (Set) DiffHybrid

func (s Set) DiffHybrid(ctx context.Context, last Set, ae *atomicerr.AtomicError, changes chan<- ValueChanged, closeChan <-chan struct{})

DiffHybrid computes the diff from |last| to |s| using a hybrid algorithm which balances returning results early vs completing quickly, if possible.

func (Set) DiffLeftRight

func (s Set) DiffLeftRight(ctx context.Context, last Set, ae *atomicerr.AtomicError, changes chan<- ValueChanged, closeChan <-chan struct{})

DiffLeftRight computes the diff from |last| to |s| using a left-to-right streaming approach, optimised for returning results early, but not completing quickly.

func (Set) Edit

func (s Set) Edit() *SetEditor

func (Set) First

func (s Set) First(ctx context.Context) (Value, error)

func (Set) Format

func (s Set) Format() *NomsBinFormat

func (Set) Has

func (s Set) Has(ctx context.Context, v Value) (bool, error)

func (Set) HumanReadableString

func (s Set) HumanReadableString() string

func (Set) Iter

func (s Set) Iter(ctx context.Context, cb setIterCallback) error

func (Set) IterAll

func (s Set) IterAll(ctx context.Context, cb setIterAllCallback) error

func (Set) Iterator

func (s Set) Iterator(ctx context.Context) (SetIterator, error)

func (Set) IteratorAt

func (s Set) IteratorAt(ctx context.Context, idx uint64) (SetIterator, error)

func (Set) IteratorFrom

func (s Set) IteratorFrom(ctx context.Context, val Value) (SetIterator, error)

func (Set) String

func (s Set) String() string

func (Set) Value

func (s Set) Value(ctx context.Context) (Value, error)

Value interface

func (Set) WalkValues

func (s Set) WalkValues(ctx context.Context, cb ValueCallback) error

type SetEditor

type SetEditor struct {
	// contains filtered or unexported fields
}

SetEditor allows for efficient editing of Set-typed prolly trees. Edits are buffered to memory and can be applied via Build(), which returns a new Set. Prior to Build(), Get() & Has() will return the value that the resulting Set would return if it were built immediately prior to the respective call. Note: The implementation biases performance towards a usage which applies edits in key-order.

func NewSetEditor

func NewSetEditor(s Set) *SetEditor

func (*SetEditor) Has

func (se *SetEditor) Has(ctx context.Context, v Value) (bool, error)

func (*SetEditor) Insert

func (se *SetEditor) Insert(vs ...Value) (*SetEditor, error)

func (*SetEditor) Kind

func (se *SetEditor) Kind() NomsKind

func (*SetEditor) Remove

func (se *SetEditor) Remove(vs ...Value) (*SetEditor, error)

func (*SetEditor) Set

func (se *SetEditor) Set(ctx context.Context) (Set, error)

func (*SetEditor) Value

func (se *SetEditor) Value(ctx context.Context) (Value, error)

type SetIterator

type SetIterator interface {
	// Next returns subsequent values from a set. It returns nil, when no objects remain.
	Next(ctx context.Context) (Value, error)

	// SkipTo(v) advances to and returns the next value in the iterator >= v.
	// Note: if the iterator has already returned the value being skipped to, it will return the next
	// value (just as if Next() was called). For example, given the following set:
	//   s = Set{ 0, 3, 6, 9, 12, 15, 18 }
	// An iterator on the set would return:
	//   i := s.Iterator()
	//   i.Next()  return 0
	//   i.SkipTo(4) -- returns 6
	//   i.skipTo(3) -- returns 9 (this is the next value in the iterator >= 3)
	//   i.skipTo(12) -- returns 12
	//   i.skipTo(12) -- return 15 (this is the next value in the iterator >= 12)
	//   i.skipTo(20) -- returns nil
	// If there are no values left in the iterator that are >= v,
	// the iterator will skip to the end of the sequence and return nil.
	SkipTo(ctx context.Context, v Value) (Value, error)
}

SetIterator defines methods that can be used to efficiently iterate through a set in 'Noms-defined' sorted order.

func NewIntersectionIterator

func NewIntersectionIterator(ctx context.Context, nbf *NomsBinFormat, iterA, iterB SetIterator) (SetIterator, error)

NewIntersectionIterator creates a intersect iterator from two other SetIterators.

func NewUnionIterator

func NewUnionIterator(ctx context.Context, nbf *NomsBinFormat, iterA, iterB SetIterator) (SetIterator, error)

NewUnionIterator creates a union iterator from two other SetIterators.

type SkipValueCallback

type SkipValueCallback func(v Value) bool

type SortData

type SortData interface {
	Len() int
	Less(i, j int) (bool, error)
	Swap(i, j int)
}

type Splice

type Splice struct {
	SpAt      uint64
	SpRemoved uint64
	SpAdded   uint64
	SpFrom    uint64
}

Read a Splice as "at SpAt (in the previous state), SpRemoved elements were removed and SpAdded elements were inserted, which can be found starting at SpFrom in the current state"

func (Splice) String

func (s Splice) String() string

type String

type String string

String is a Noms Value wrapper around the primitive string type.

func (String) Equals

func (s String) Equals(other Value) bool

func (String) Hash

func (s String) Hash(nbf *NomsBinFormat) (hash.Hash, error)

func (String) HumanReadableString

func (s String) HumanReadableString() string

func (String) Kind

func (s String) Kind() NomsKind

func (String) Less

func (s String) Less(nbf *NomsBinFormat, other LesserValuable) (bool, error)

func (String) Value

func (s String) Value(ctx context.Context) (Value, error)

Value interface

func (String) WalkRefs

func (s String) WalkRefs(nbf *NomsBinFormat, cb RefCallback) error

func (String) WalkValues

func (s String) WalkValues(ctx context.Context, cb ValueCallback) error

type Struct

type Struct struct {
	// contains filtered or unexported fields
}

func EmptyStruct

func EmptyStruct(nbf *NomsBinFormat) Struct

func NewStruct

func NewStruct(nbf *NomsBinFormat, name string, data StructData) (Struct, error)

func (Struct) Delete

func (s Struct) Delete(n string) (Struct, error)

Delete returns a new struct where the field name has been removed. If name is not an existing field in the struct then the current struct is returned.

func (Struct) Diff

func (s Struct) Diff(last Struct, changes chan<- ValueChanged, closeChan <-chan struct{}) error

func (Struct) Empty

func (s Struct) Empty() bool

func (Struct) Equals

func (v Struct) Equals(other Value) bool

func (Struct) Format

func (s Struct) Format() *NomsBinFormat

func (Struct) Hash

func (v Struct) Hash(*NomsBinFormat) (hash.Hash, error)

func (Struct) HumanReadableString

func (s Struct) HumanReadableString() string

func (Struct) IsZeroValue

func (v Struct) IsZeroValue() bool

IsZeroValue can be used to test if a Value is the same as T{}.

func (Struct) IterFields

func (s Struct) IterFields(cb func(name string, value Value) error) error

IterFields iterates over the fields, calling cb for every field in the struct.

func (Struct) Kind

func (v Struct) Kind() NomsKind

func (Struct) Len

func (s Struct) Len() int

Len is the number of fields in the struct.

func (Struct) Less

func (v Struct) Less(nbf *NomsBinFormat, other LesserValuable) (bool, error)

func (Struct) MaybeGet

func (s Struct) MaybeGet(n string) (v Value, found bool, err error)

MaybeGet returns the value of a field in the struct. If the struct does not a have a field with the name name then this returns (nil, false).

func (Struct) Name

func (s Struct) Name() string

Name is the name of the struct.

func (Struct) Set

func (s Struct) Set(n string, v Value) (Struct, error)

Set returns a new struct where the field name has been set to value. If name is not an existing field in the struct or the type of value is different from the old value of the struct field a new struct type is created.

func (Struct) String

func (s Struct) String() string

func (Struct) Value

func (s Struct) Value(ctx context.Context) (Value, error)

func (Struct) WalkRefs

func (v Struct) WalkRefs(nbf *NomsBinFormat, cb RefCallback) error

func (Struct) WalkValues

func (s Struct) WalkValues(ctx context.Context, cb ValueCallback) error

type StructData

type StructData map[string]Value

type StructDesc

type StructDesc struct {
	Name string
	// contains filtered or unexported fields
}

StructDesc describes a custom Noms Struct.

func (StructDesc) Field

func (s StructDesc) Field(name string) (typ *Type, optional bool)

func (StructDesc) IterFields

func (s StructDesc) IterFields(cb func(name string, t *Type, optional bool))

func (StructDesc) Kind

func (s StructDesc) Kind() NomsKind

func (StructDesc) Len

func (s StructDesc) Len() int

Len returns the number of fields in the struct

type StructField

type StructField struct {
	Name     string
	Type     *Type
	Optional bool
}

StructField describes a field in a struct type.

type StructTemplate

type StructTemplate struct {
	// contains filtered or unexported fields
}

StructTemplate allows creating a template for structs with a known shape (name and fields). If a lot of structs of the same shape are being created then using a StructTemplate makes that slightly more efficient.

func MakeStructTemplate

func MakeStructTemplate(name string, fieldNames []string) (t StructTemplate)

MakeStructTemplate creates a new StructTemplate or panics if the name and fields are not valid.

func (StructTemplate) NewStruct

func (st StructTemplate) NewStruct(nbf *NomsBinFormat, values []Value) (Struct, error)

NewStruct creates a new Struct from the StructTemplate. The order of the values must match the order of the field names of the StructTemplate.

type TargetAnnotation

type TargetAnnotation struct {
}

TargetAnnotation is a PathPart annotation to resolve to the targetValue of the Ref it is resolved on.

func (TargetAnnotation) Resolve

func (ann TargetAnnotation) Resolve(ctx context.Context, v Value, vr ValueReader) (Value, error)

func (TargetAnnotation) String

func (ann TargetAnnotation) String() string

type Timestamp

type Timestamp time.Time

func (Timestamp) Equals

func (v Timestamp) Equals(other Value) bool

func (Timestamp) Hash

func (v Timestamp) Hash(nbf *NomsBinFormat) (hash.Hash, error)

func (Timestamp) HumanReadableString

func (v Timestamp) HumanReadableString() string

func (Timestamp) Kind

func (v Timestamp) Kind() NomsKind

func (Timestamp) Less

func (v Timestamp) Less(nbf *NomsBinFormat, other LesserValuable) (bool, error)

func (Timestamp) String

func (v Timestamp) String() string

func (Timestamp) Value

func (v Timestamp) Value(ctx context.Context) (Value, error)

func (Timestamp) WalkRefs

func (v Timestamp) WalkRefs(nbf *NomsBinFormat, cb RefCallback) error

func (Timestamp) WalkValues

func (v Timestamp) WalkValues(ctx context.Context, cb ValueCallback) error

type Tuple

type Tuple struct {
	// contains filtered or unexported fields
}

func EmptyTuple

func EmptyTuple(nbf *NomsBinFormat) Tuple

func NewTuple

func NewTuple(nbf *NomsBinFormat, values ...Value) (Tuple, error)

func (Tuple) Append

func (t Tuple) Append(v Value) (Tuple, error)

func (Tuple) Contains

func (t Tuple) Contains(v Value) (bool, error)

func (Tuple) CountDifferencesBetweenTupleFields

func (t Tuple) CountDifferencesBetweenTupleFields(other Tuple) (uint64, error)

CountDifferencesBetweenTupleFields returns the number of fields that are different between two tuples and does not panic if tuples are different lengths.

func (Tuple) Empty

func (t Tuple) Empty() bool

func (Tuple) Equals

func (v Tuple) Equals(other Value) bool

func (Tuple) Format

func (t Tuple) Format() *NomsBinFormat

func (Tuple) Get

func (t Tuple) Get(n uint64) (Value, error)

Get returns the value of a field in the tuple. If the tuple does not a have a field at the index then this panics

func (Tuple) Hash

func (v Tuple) Hash(*NomsBinFormat) (hash.Hash, error)

func (Tuple) HumanReadableString

func (t Tuple) HumanReadableString() string

func (Tuple) IsZeroValue

func (v Tuple) IsZeroValue() bool

IsZeroValue can be used to test if a Value is the same as T{}.

func (Tuple) IterFields

func (t Tuple) IterFields(cb func(index uint64, value Value) (stop bool, err error)) error

IterFields iterates over the fields, calling cb for every field in the tuple until cb returns false

func (Tuple) Iterator

func (t Tuple) Iterator() (*TupleIterator, error)

func (Tuple) IteratorAt

func (t Tuple) IteratorAt(pos uint64) (*TupleIterator, error)

func (Tuple) Kind

func (v Tuple) Kind() NomsKind

func (Tuple) Len

func (t Tuple) Len() uint64

Len is the number of fields in the struct.

func (Tuple) Less

func (t Tuple) Less(nbf *NomsBinFormat, other LesserValuable) (bool, error)

func (Tuple) Set

func (t Tuple) Set(n uint64, v Value) (Tuple, error)

Set returns a new tuple where the field at index n is set to value. Attempting to use Set on an index that is outside of the bounds will cause a panic. Use Append to add additional values, not Set.

func (Tuple) StartsWith

func (t Tuple) StartsWith(otherTuple Tuple) bool

func (Tuple) String

func (t Tuple) String() string

func (Tuple) Value

func (t Tuple) Value(ctx context.Context) (Value, error)

Value interface

func (Tuple) WalkRefs

func (v Tuple) WalkRefs(nbf *NomsBinFormat, cb RefCallback) error

func (Tuple) WalkValues

func (t Tuple) WalkValues(ctx context.Context, cb ValueCallback) error

type TupleIterator

type TupleIterator struct {
	// contains filtered or unexported fields
}

func (*TupleIterator) HasMore

func (itr *TupleIterator) HasMore() bool

func (*TupleIterator) Len

func (itr *TupleIterator) Len() uint64

func (*TupleIterator) Next

func (itr *TupleIterator) Next() (uint64, Value, error)

func (*TupleIterator) Pos

func (itr *TupleIterator) Pos() uint64

type Type

type Type struct {
	Desc TypeDesc
}

func MakeCycleType

func MakeCycleType(name string) *Type

func MakeListType

func MakeListType(elemType *Type) (*Type, error)

func MakeMapType

func MakeMapType(keyType, valType *Type) (*Type, error)

func MakePrimitiveType

func MakePrimitiveType(k NomsKind) (*Type, error)

func MakeRefType

func MakeRefType(elemType *Type) (*Type, error)

func MakeSetType

func MakeSetType(elemType *Type) (*Type, error)

func MakeStructType

func MakeStructType(name string, fields ...StructField) (*Type, error)

func MakeStructTypeFromFields

func MakeStructTypeFromFields(name string, fields FieldMap) (*Type, error)

func MakeUnionType

func MakeUnionType(elemTypes ...*Type) (*Type, error)

MakeUnionType creates a new union type unless the elemTypes can be folded into a single non union type.

func TypeOf

func TypeOf(v Value) (*Type, error)

TypeOf returns the type describing the value. This is not an exact type but often a simplification of the concrete type.

func (*Type) Describe

func (t *Type) Describe(ctx context.Context) (string, error)

Describe generate text that should parse into the struct being described.

func (*Type) Equals

func (t *Type) Equals(other Value) (res bool)

func (*Type) Hash

func (t *Type) Hash(nbf *NomsBinFormat) (hash.Hash, error)

func (*Type) HumanReadableString

func (t *Type) HumanReadableString() string

func (*Type) Kind

func (t *Type) Kind() NomsKind

func (*Type) Less

func (t *Type) Less(nbf *NomsBinFormat, other LesserValuable) (bool, error)

func (*Type) String

func (t *Type) String() string

func (*Type) TargetKind

func (t *Type) TargetKind() NomsKind

func (*Type) Value

func (t *Type) Value(ctx context.Context) (Value, error)

Value interface

func (*Type) WalkRefs

func (t *Type) WalkRefs(nbf *NomsBinFormat, cb RefCallback) error

func (*Type) WalkValues

func (t *Type) WalkValues(ctx context.Context, cb ValueCallback) error

type TypeAnnotation

type TypeAnnotation struct {
}

TypeAnnotation is a PathPart annotation to resolve to the type of the value it's resolved in.

func (TypeAnnotation) Resolve

func (ann TypeAnnotation) Resolve(ctx context.Context, v Value, vr ValueReader) (Value, error)

func (TypeAnnotation) String

func (ann TypeAnnotation) String() string

type TypeDesc

type TypeDesc interface {
	Kind() NomsKind
	// contains filtered or unexported methods
}

TypeDesc describes a type of the kind returned by Kind(), e.g. Map, Float, or a custom type.

type UUID

type UUID uuid.UUID

func (UUID) Equals

func (v UUID) Equals(other Value) bool

func (UUID) Hash

func (v UUID) Hash(nbf *NomsBinFormat) (hash.Hash, error)

func (UUID) HumanReadableString

func (v UUID) HumanReadableString() string

func (UUID) Kind

func (v UUID) Kind() NomsKind

func (UUID) Less

func (v UUID) Less(nbf *NomsBinFormat, other LesserValuable) (bool, error)

func (UUID) String

func (v UUID) String() string

func (UUID) Value

func (v UUID) Value(ctx context.Context) (Value, error)

func (UUID) WalkRefs

func (v UUID) WalkRefs(nbf *NomsBinFormat, cb RefCallback) error

func (UUID) WalkValues

func (v UUID) WalkValues(ctx context.Context, cb ValueCallback) error

type Uint

type Uint uint64

Int is a Noms Value wrapper around the primitive int32 type.

func (Uint) Equals

func (v Uint) Equals(other Value) bool

func (Uint) Hash

func (v Uint) Hash(nbf *NomsBinFormat) (hash.Hash, error)

func (Uint) HumanReadableString

func (v Uint) HumanReadableString() string

func (Uint) Kind

func (v Uint) Kind() NomsKind

func (Uint) Less

func (v Uint) Less(nbf *NomsBinFormat, other LesserValuable) (bool, error)

func (Uint) Value

func (v Uint) Value(ctx context.Context) (Value, error)

Value interface

func (Uint) WalkRefs

func (v Uint) WalkRefs(nbf *NomsBinFormat, cb RefCallback) error

func (Uint) WalkValues

func (v Uint) WalkValues(ctx context.Context, cb ValueCallback) error

type UnionIterator

type UnionIterator struct {
	// contains filtered or unexported fields
}

UnionIterator combines the results from two other iterators. The values from Next() are returned in noms-defined order with all duplicates removed.

func (*UnionIterator) Next

func (u *UnionIterator) Next(ctx context.Context) (Value, error)

func (*UnionIterator) SkipTo

func (u *UnionIterator) SkipTo(ctx context.Context, v Value) (Value, error)

type ValidatingDecoder

type ValidatingDecoder struct {
	// contains filtered or unexported fields
}

func NewValidatingDecoder

func NewValidatingDecoder(cs chunks.ChunkStore) *ValidatingDecoder

func (*ValidatingDecoder) Decode

func (vbs *ValidatingDecoder) Decode(c *chunks.Chunk) (DecodedChunk, error)

Decode decodes c and checks that the hash of the resulting value matches c.Hash(). It returns a DecodedChunk holding both c and a pointer to the decoded Value.

type Valuable

type Valuable interface {
	// Kind is the NomsKind describing the kind of value this is.
	Kind() NomsKind

	Value(ctx context.Context) (Value, error)
}

Valuable is an interface from which a Value can be retrieved.

type Value

type Value interface {
	LesserValuable

	// Equals determines if two different Noms values represents the same underlying value.
	Equals(other Value) bool

	// Hash is the hash of the value. All Noms values have a unique hash and if two values have the
	// same hash they must be equal.
	Hash(*NomsBinFormat) (hash.Hash, error)

	// WalkValues iterates over the immediate children of this value in the DAG, if any, not including
	// Type()
	WalkValues(context.Context, ValueCallback) error

	// WalkRefs iterates over the refs to the underlying chunks. If this value is a collection that has been
	// chunked then this will return the refs of th sub trees of the prolly-tree.
	WalkRefs(*NomsBinFormat, RefCallback) error

	// HumanReadableString returns a human-readable string version of this Value (not meant for re-parsing)
	HumanReadableString() string
	// contains filtered or unexported methods
}

Value is the interface all Noms values implement.

func DecodeValue

func DecodeValue(c chunks.Chunk, vrw ValueReadWriter) (Value, error)

DecodeValue decodes a value from a chunk source. It is an error to provide an empty chunk.

func ParsePathIndex

func ParsePathIndex(str string) (idx Value, h hash.Hash, rem string, err error)

Parse a Noms value from the path index syntax. 4 -> types.Float "4" -> types.String true|false -> types.Boolean #<chars> -> hash.Hash

type ValueCallback

type ValueCallback func(v Value) error

type ValueChanged

type ValueChanged struct {
	ChangeType              DiffChangeType
	Key, OldValue, NewValue Value
}

type ValueReadWriter

type ValueReadWriter interface {
	ValueReader
	ValueWriter
}

ValueReadWriter is an interface that knows how to read and write Noms Values, e.g. datas/Database. Required to avoid import cycle between this package and the package that implements Value read/writing.

type ValueReader

type ValueReader interface {
	Format() *NomsBinFormat
	ReadValue(ctx context.Context, h hash.Hash) (Value, error)
	ReadManyValues(ctx context.Context, hashes hash.HashSlice) (ValueSlice, error)
}

ValueReader is an interface that knows how to read Noms Values, e.g. datas/Database. Required to avoid import cycle between this package and the package that implements Value reading.

type ValueSlice

type ValueSlice []Value

func (ValueSlice) Contains

func (vs ValueSlice) Contains(nbf *NomsBinFormat, v Value) bool

func (ValueSlice) Equals

func (vs ValueSlice) Equals(other ValueSlice) bool

type ValueSort

type ValueSort struct {
	// contains filtered or unexported fields
}

func (ValueSort) Contains

func (vs ValueSort) Contains(v Value) bool

func (ValueSort) Equals

func (vs ValueSort) Equals(other ValueSort) bool

func (ValueSort) Len

func (vs ValueSort) Len() int

func (ValueSort) Less

func (vs ValueSort) Less(i, j int) (bool, error)

func (ValueSort) Swap

func (vs ValueSort) Swap(i, j int)

type ValueStats

type ValueStats interface {
	String() string
}

type ValueStore

type ValueStore struct {
	// contains filtered or unexported fields
}

ValueStore provides methods to read and write Noms Values to a ChunkStore. It minimally validates Values as they're written, but does not guarantee that these Values are persisted through the ChunkStore until a subsequent Flush. Currently, WriteValue validates the following properties of a Value v: - v can be correctly serialized and its Ref taken

func NewValueStore

func NewValueStore(cs chunks.ChunkStore) *ValueStore

NewValueStore returns a ValueStore instance that owns the provided ChunkStore and manages its lifetime. Calling Close on the returned ValueStore will Close() cs.

func (*ValueStore) ChunkStore

func (lvs *ValueStore) ChunkStore() chunks.ChunkStore

func (*ValueStore) Close

func (lvs *ValueStore) Close() error

Close closes the underlying ChunkStore

func (*ValueStore) Commit

func (lvs *ValueStore) Commit(ctx context.Context, current, last hash.Hash) (bool, error)

Commit() flushes all bufferedChunks into the ChunkStore, with best-effort locality, and attempts to Commit, updating the root to |current| (or keeping it the same as Root()). If the root has moved since this ValueStore was opened, or last Rebased(), it will return false and will have internally rebased. Until Commit() succeeds, no work of the ValueStore will be visible to other readers of the underlying ChunkStore.

func (*ValueStore) Format

func (lvs *ValueStore) Format() *NomsBinFormat

func (*ValueStore) ReadManyValues

func (lvs *ValueStore) ReadManyValues(ctx context.Context, hashes hash.HashSlice) (ValueSlice, error)

ReadManyValues reads and decodes Values indicated by |hashes| from lvs and returns the found Values in the same order. Any non-present Values will be represented by nil.

func (*ValueStore) ReadValue

func (lvs *ValueStore) ReadValue(ctx context.Context, h hash.Hash) (Value, error)

ReadValue reads and decodes a value from lvs. It is not considered an error for the requested chunk to be empty; in this case, the function simply returns nil.

func (*ValueStore) Rebase

func (lvs *ValueStore) Rebase(ctx context.Context) error

func (*ValueStore) Root

func (lvs *ValueStore) Root(ctx context.Context) (hash.Hash, error)

func (*ValueStore) SetEnforceCompleteness

func (lvs *ValueStore) SetEnforceCompleteness(enforce bool)

func (*ValueStore) WriteValue

func (lvs *ValueStore) WriteValue(ctx context.Context, v Value) (Ref, error)

WriteValue takes a Value, schedules it to be written it to lvs, and returns an appropriately-typed types.Ref. v is not guaranteed to be actually written until after Flush().

type ValueWriter

type ValueWriter interface {
	WriteValue(ctx context.Context, v Value) (Ref, error)
}

ValueWriter is an interface that knows how to write Noms Values, e.g. datas/Database. Required to avoid import cycle between this package and the package that implements Value writing.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL