types

package
v0.0.0-...-3afbc18 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2016 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

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

Index

Examples

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 BlobType = makePrimitiveType(BlobKind)
View Source
var BoolType = makePrimitiveType(BoolKind)
View Source
var EmptyStructType = MakeStructType("", []string{}, []*Type{})
View Source
var KindToString = map[NomsKind]string{
	BlobKind:   "Blob",
	BoolKind:   "Bool",
	CycleKind:  "Cycle",
	ListKind:   "List",
	MapKind:    "Map",
	NumberKind: "Number",
	RefKind:    "Ref",
	SetKind:    "Set",
	StructKind: "Struct",
	StringKind: "String",
	TypeKind:   "Type",
	UnionKind:  "Union",
	ValueKind:  "Value",
}
View Source
var NumberType = makePrimitiveType(NumberKind)
View Source
var StringType = makePrimitiveType(StringKind)
View Source
var TypeType = makePrimitiveType(TypeKind)
View Source
var ValueType = makePrimitiveType(ValueKind)

Functions

func CamelCaseFieldName

func CamelCaseFieldName(input string) string

func EncodeValue

func EncodeValue(v Value, vw ValueWriter) chunks.Chunk

func EncodedIndexValue

func EncodedIndexValue(v Value) string

func EncodedValue

func EncodedValue(v Value) string

EncodedValue returns a string containing the serialization of a value.

func EncodedValueMaxLines

func EncodedValueMaxLines(v Value, maxLines uint32) string

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

func EncodedValueWithTags

func EncodedValueWithTags(v Value) string

func EnsureHash

func EnsureHash(h *hash.Hash, v Value) hash.Hash

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 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 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(requiredType, concreteType *Type) bool

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

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 NewStreamingList

func NewStreamingList(vrw ValueReadWriter, 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(vrw ValueReadWriter, kvs <-chan Value) <-chan Map

func NewStreamingSet

func NewStreamingSet(vrw ValueReadWriter, vals <-chan Value) <-chan Set

func ValueCanBePathIndex

func ValueCanBePathIndex(v Value) bool

func WriteEncodedValue

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

WriteEncodedValue writes the serialization of a value

func WriteEncodedValueMaxLines

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

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

func WriteEncodedValueWithTags

func WriteEncodedValueWithTags(w io.Writer, v Value) error

WriteEncodedValueWithTags writes the serialization of a value prefixed by its type.

Types

type BatchStore

type BatchStore interface {
	// Get returns from the store the Value Chunk by h. If h is absent from the store, chunks.EmptyChunk is returned.
	Get(h hash.Hash) chunks.Chunk

	// SchedulePut enqueues a write for the Chunk c with the given refHeight. Typically, the Value which was encoded to provide c can also be queried for its refHeight. The call may or may not block until c is persisted. The provided hints are used to assist in validation. Validation requires checking that all refs embedded in c are themselves valid, which could naively be done by resolving each one. Instead, hints provides a (smaller) set of refs that point to Chunks that themselves contain many of c's refs. Thus, by checking only the hinted Chunks, c can be validated with fewer read operations.
	// c may or may not be persisted when Put() returns, but is guaranteed to be persistent after a call to Flush() or Close().
	SchedulePut(c chunks.Chunk, refHeight uint64, hints Hints)

	// AddHints allows additional hints, as used by SchedulePut, to be added for use in the current batch.
	AddHints(hints Hints)

	// Flush causes enqueued Puts to be persisted.
	Flush()
	chunks.RootTracker
	io.Closer
}

BatchStore provides an interface similar to chunks.ChunkStore, but batch-oriented. Instead of Put(), it provides SchedulePut(), which enqueues a Chunk to be sent at a possibly later time.

func NewBatchStoreAdaptor

func NewBatchStoreAdaptor(cs chunks.ChunkStore) BatchStore

NewBatchStoreAdaptor returns a BatchStore instance backed by a ChunkStore. Takes ownership of cs and manages its lifetime; calling Close on the returned BatchStore will Close cs.

type BatchStoreAdaptor

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

BatchStoreAdaptor provides a naive implementation of BatchStore should only be used with ChunkStores that can Put relatively quickly. It provides no actual batching or validation. Its intended use is for adapting a ChunkStore for use in something that requires a BatchStore.

func (*BatchStoreAdaptor) AddHints

func (bsa *BatchStoreAdaptor) AddHints(hints Hints)

AddHints is a noop.

func (*BatchStoreAdaptor) Close

func (bsa *BatchStoreAdaptor) Close() error

Close closes the underlying ChunkStore

func (*BatchStoreAdaptor) Flush

func (bsa *BatchStoreAdaptor) Flush()

Flush is a noop.

func (*BatchStoreAdaptor) Get

func (bsa *BatchStoreAdaptor) Get(h hash.Hash) chunks.Chunk

Get simply proxies to the backing ChunkStore

func (*BatchStoreAdaptor) Root

func (bsa *BatchStoreAdaptor) Root() hash.Hash

func (*BatchStoreAdaptor) SchedulePut

func (bsa *BatchStoreAdaptor) SchedulePut(c chunks.Chunk, refHeight uint64, hints Hints)

SchedulePut simply calls Put on the underlying ChunkStore, and ignores hints.

func (*BatchStoreAdaptor) UpdateRoot

func (bsa *BatchStoreAdaptor) UpdateRoot(current, last hash.Hash) bool

type Blob

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

Blob represents a list of Blobs.

func NewBlob

func NewBlob(rs ...io.Reader) Blob

NewBlob creates a Blob by reading from every Reader in rs and concatenating the result. NewBlob uses one goroutine per Reader. Chunks are kept in memory as they're created - to reduce memory pressure and write to disk instead, use NewStreamingBlob with a non-nil reader.

func NewEmptyBlob

func NewEmptyBlob() Blob

func NewStreamingBlob

func NewStreamingBlob(vrw ValueReadWriter, rs ...io.Reader) Blob

NewStreamingBlob creates a Blob by reading from every Reader in rs and concatenating the result. NewStreamingBlob uses one goroutine per Reader. If vrw is not nil, chunks are written to vrw instead of kept in memory.

func (Blob) Concat

func (b Blob) Concat(other Blob) Blob

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) Empty

func (b Blob) Empty() bool

func (Blob) Equals

func (b Blob) Equals(other Value) bool

Value interface

func (Blob) Hash

func (b Blob) Hash() hash.Hash

func (Blob) Len

func (b Blob) Len() uint64

Collection interface

func (Blob) Less

func (b Blob) Less(other Value) bool

func (Blob) Reader

func (b Blob) Reader() io.ReadSeeker

BUG 155 - Should provide Write... Maybe even have Blob implement ReadWriteSeeker

func (Blob) Splice

func (b Blob) Splice(idx uint64, deleteCount uint64, data []byte) Blob

func (Blob) Type

func (b Blob) Type() *Type

func (Blob) WalkRefs

func (b Blob) WalkRefs(cb RefCallback)

func (Blob) WalkValues

func (b Blob) WalkValues(cb ValueCallback)

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 (v Bool) Equals(other Value) bool

Value interface

func (Bool) Hash

func (v Bool) Hash() hash.Hash

func (Bool) Less

func (v Bool) Less(other Value) bool

func (Bool) Type

func (v Bool) Type() *Type

func (Bool) WalkRefs

func (v Bool) WalkRefs(cb RefCallback)

func (Bool) WalkValues

func (v Bool) WalkValues(cb ValueCallback)

type Collection

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

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) HasUnresolvedCycle

func (c CompoundDesc) HasUnresolvedCycle(visited []*Type) bool

func (CompoundDesc) Kind

func (c CompoundDesc) Kind() NomsKind

type CycleDesc

type CycleDesc uint32

func (CycleDesc) HasUnresolvedCycle

func (c CycleDesc) HasUnresolvedCycle(visited []*Type) bool

func (CycleDesc) Kind

func (c CycleDesc) Kind() NomsKind

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 EditDistanceEqualsFn

type EditDistanceEqualsFn func(prevIndex uint64, currentIndex uint64) bool

type FieldMap

type FieldMap map[string]*Type

type FieldPath

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

Gets Struct field values by name.

func NewFieldPath

func NewFieldPath(name string) FieldPath

func (FieldPath) Resolve

func (fp FieldPath) Resolve(v Value) Value

func (FieldPath) String

func (fp FieldPath) String() string

type GraphBuilder

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

func NewGraphBuilder

func NewGraphBuilder(vrw ValueReadWriter, rootKind NomsKind, verbose bool) *GraphBuilder

NewGraphBuilder() returns an new GraphBuilder object.

func (*GraphBuilder) Build

func (b *GraphBuilder) Build() Value

Builds and returns the graph. This method should only be called after all calls to the mutation operations (i.e. MapSet, SetInsert, and ListAppend) have completed. It is the caller's responsibility to ensure that this is the case. Build() will panic if called more than once on any GraphBuilder object.

Example
vs := NewTestValueStore()
defer vs.Close()

gb := NewGraphBuilder(vs, MapKind, false)
gb.SetInsert([]Value{String("parent"), String("children")}, String("John"))
gb.SetInsert([]Value{String("parent"), String("children")}, String("Mary"))
gb.SetInsert([]Value{String("parent"), String("children")}, String("Frieda"))
gb.MapSet([]Value{String("parent"), String("ages")}, String("Father"), Number(42))
gb.MapSet([]Value{String("parent"), String("ages")}, String("Mother"), Number(44))
gb.ListAppend([]Value{String("parent"), String("chores")}, String("Make dinner"))
gb.ListAppend([]Value{String("parent"), String("chores")}, String("Wash dishes"))
gb.ListAppend([]Value{String("parent"), String("chores")}, String("Make breakfast"))
gb.ListAppend([]Value{String("parent"), String("chores")}, String("Wash dishes"))
gb.MapSet([]Value{String("parent")}, String("combinedAge"), Number(86))
m := gb.Build()
fmt.Println("map:", EncodedValue(m))
Output:

func (*GraphBuilder) ListAppend

func (b *GraphBuilder) ListAppend(keys []Value, v Value)

ListAppends() will append |v| to the list at path |p|. Intermediate maps referenced by |keys| are created as necessary. This is threadsafe, may call from multiple go routines, however append semantics are such that the elements will be appended in order that functions are called, so order has to be managed by caller.

func (*GraphBuilder) MapSet

func (b *GraphBuilder) MapSet(keys []Value, k Value, v Value)

MapSet() will add the key/value pair |k, v| to the map found by traversing the graph using the |keys| slice. Intermediate maps referenced by |keys| are created as necessary. This is threadsafe, may call from multiple go routines.

func (*GraphBuilder) SetInsert

func (b *GraphBuilder) SetInsert(keys []Value, v Value)

SetInsert() will insert the value |v| into the set at path |keys|. Intermediate maps referenced by |keys| are created as necessary. This is threadsafe, may call from multiple go routines.

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 NewHashIndexIntoKeyPath

func NewHashIndexIntoKeyPath(h hash.Hash) HashIndexPath

func NewHashIndexPath

func NewHashIndexPath(h hash.Hash) HashIndexPath

func (HashIndexPath) Resolve

func (hip HashIndexPath) Resolve(v Value) (res Value)

func (HashIndexPath) String

func (hip HashIndexPath) String() string

type Hints

type Hints map[hash.Hash]struct{}

Hints are a set of hashes that should be used to speed up the validation of one or more Chunks.

type IndexPath

type IndexPath struct {
	// The value of the index, e.g. `[42]` or `["value"]`.
	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
}

Indexes into Maps and Lists by key or index.

func NewIndexIntoKeyPath

func NewIndexIntoKeyPath(idx Value) IndexPath

func NewIndexPath

func NewIndexPath(idx Value) IndexPath

func (IndexPath) Resolve

func (ip IndexPath) Resolve(v Value) Value

func (IndexPath) String

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

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 (i *IntersectionIterator) Next() Value

func (*IntersectionIterator) SkipTo

func (i *IntersectionIterator) SkipTo(v Value) Value

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(Number(1), Bool(true))
fmt.Println(l.Type().Describe())
// outputs List<Bool | Number>

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

func NewList

func NewList(values ...Value) List

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) Append

func (l List) Append(vs ...Value) List

Append returns a new list where vs have been appended to the resulting list.

func (List) Concat

func (l List) Concat(other List) List

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(last List, changes chan<- Splice, closeChan <-chan struct{})

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(last List, changes chan<- Splice, closeChan <-chan struct{}, maxSpliceMatrixSize uint64)

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) Empty

func (l List) Empty() bool

Empty returns true if the list is empty (length is zero).

func (List) Equals

func (l List) Equals(other Value) bool

func (List) Get

func (l List) Get(idx uint64) Value

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) Hash

func (l List) Hash() hash.Hash

func (List) Insert

func (l List) Insert(idx uint64, vs ...Value) List

Insert returns a new list where vs values have been inserted at idx.

func (List) Iter

func (l List) Iter(f listIterFunc)

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(f listIterAllFunc)

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) Iterator

func (l List) Iterator() ListIterator

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

func (List) IteratorAt

func (l List) IteratorAt(index uint64) ListIterator

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

func (List) Len

func (l List) Len() uint64

Len returns the number of elements in the list.

func (List) Less

func (l List) Less(other Value) bool

func (List) Map deprecated

func (l List) Map(mf MapFunc) []interface{}

Deprecated: This API may change in the future. Use IterAll or Iterator instead.

func (List) Remove

func (l List) Remove(start uint64, end uint64) List

Remove returns a new list where the items at index start (inclusive) through end (exclusive) have been removed. This panics if end is smaller than start.

func (List) RemoveAt

func (l List) RemoveAt(idx uint64) List

RemoveAt returns a new list where a single element at index idx have been removed.

func (List) Set

func (l List) Set(idx uint64, v Value) List

Set returns a new list where the valie at the given index have been replaced with v. If idx is out bounds then this panics.

func (List) Splice

func (l List) Splice(idx uint64, deleteCount uint64, vs ...Value) List

Splice returns a new list where deleteCount values have been removed at idx and vs have been inserted instead. This function panics if idx or deleteCount is out of bounds.

func (List) Type

func (l List) Type() *Type

func (List) WalkRefs

func (l List) WalkRefs(cb RefCallback)

func (List) WalkValues

func (l List) WalkValues(cb ValueCallback)

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() (out Value)

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
}

func NewMap

func NewMap(kv ...Value) Map

func (Map) Diff

func (m Map) Diff(last Map, changes chan<- ValueChanged, closeChan <-chan struct{})

Computes the diff from |last| to |m| using "best" algorithm, which balances returning results early vs completing quickly.

func (Map) DiffLeftRight

func (m Map) DiffLeftRight(last Map, changes chan<- ValueChanged, closeChan <-chan struct{})

Like Diff() but uses a left-to-right streaming approach, optimised for returning results early, but not completing quickly.

func (Map) Empty

func (m Map) Empty() bool

func (Map) Equals

func (m Map) Equals(other Value) bool

Value interface

func (Map) First

func (m Map) First() (Value, Value)

func (Map) Get

func (m Map) Get(key Value) Value

func (Map) Has

func (m Map) Has(key Value) bool

func (Map) Hash

func (m Map) Hash() hash.Hash

func (Map) Iter

func (m Map) Iter(cb mapIterCallback)

func (Map) IterAll

func (m Map) IterAll(cb mapIterAllCallback)

func (Map) IterFrom

func (m Map) IterFrom(start Value, cb mapIterCallback)

func (Map) Last

func (m Map) Last() (Value, Value)

func (Map) Len

func (m Map) Len() uint64

Collection interface

func (Map) Less

func (m Map) Less(other Value) bool

func (Map) MaybeGet

func (m Map) MaybeGet(key Value) (v Value, ok bool)

func (Map) Remove

func (m Map) Remove(k Value) Map

func (Map) Set

func (m Map) Set(key Value, val Value) Map

func (Map) SetM

func (m Map) SetM(kv ...Value) Map

func (Map) Type

func (m Map) Type() *Type

func (Map) WalkRefs

func (m Map) WalkRefs(cb RefCallback)

func (Map) WalkValues

func (m Map) WalkValues(cb ValueCallback)

type MapFunc

type MapFunc func(v Value, index uint64) interface{}

type NomsKind

type NomsKind uint8

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

const (
	BoolKind NomsKind = iota
	NumberKind
	StringKind
	BlobKind
	ValueKind
	ListKind
	MapKind
	RefKind
	SetKind
	StructKind
	TypeKind
	CycleKind // Only used in encoding/decoding.
	UnionKind
)

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

type Number

type Number float64

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

func (Number) Equals

func (v Number) Equals(other Value) bool

Value interface

func (Number) Hash

func (v Number) Hash() hash.Hash

func (Number) Less

func (v Number) Less(other Value) bool

func (Number) Type

func (v Number) Type() *Type

func (Number) WalkRefs

func (v Number) WalkRefs(cb RefCallback)

func (Number) WalkValues

func (v Number) WalkValues(cb ValueCallback)

type Path

type Path []PathPart

A Path is an address to a Noms value - and unlike hashes (i.e. #abcd...) they can address inlined values. See https://github.com/attic-labs/noms/blob/master/doc/spelling.md.

func ParsePath

func ParsePath(str string) (Path, error)

func (Path) Equals

func (p Path) Equals(o Path) bool

func (Path) Resolve

func (p Path) Resolve(v Value) (resolved Value)

func (Path) String

func (p Path) String() string

type PathPart

type PathPart interface {
	Resolve(v Value) Value
	String() string
}

type PrimitiveDesc

type PrimitiveDesc NomsKind

PrimitiveDesc implements TypeDesc for all primitive Noms types: Blob Bool Number Package String Type Value

func (PrimitiveDesc) HasUnresolvedCycle

func (p PrimitiveDesc) HasUnresolvedCycle(visited []*Type) bool

func (PrimitiveDesc) Kind

func (p PrimitiveDesc) Kind() NomsKind

type Ref

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

func NewRef

func NewRef(v Value) Ref

func (Ref) Equals

func (r Ref) Equals(other Value) bool

Value interface

func (Ref) Hash

func (r Ref) Hash() hash.Hash

func (Ref) Height

func (r Ref) Height() uint64

func (Ref) Less

func (r Ref) Less(other Value) bool

func (Ref) TargetHash

func (r Ref) TargetHash() hash.Hash

func (Ref) TargetValue

func (r Ref) TargetValue(vr ValueReader) Value

func (Ref) Type

func (r Ref) Type() *Type

func (Ref) WalkRefs

func (r Ref) WalkRefs(cb RefCallback)

func (Ref) WalkValues

func (r Ref) WalkValues(cb ValueCallback)

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)

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
}

func NewSet

func NewSet(v ...Value) Set

func (Set) Diff

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

Computes the diff from |last| to |s| using "best" algorithm, which balances returning results early vs completing quickly.

func (Set) DiffLeftRight

func (s Set) DiffLeftRight(last Set, changes chan<- ValueChanged, closeChan <-chan struct{})

Like Diff() but uses a left-to-right streaming approach, optimised for returning results early, but not completing quickly.

func (Set) Empty

func (s Set) Empty() bool

func (Set) Equals

func (s Set) Equals(other Value) bool

Value interface

func (Set) First

func (s Set) First() Value

func (Set) Has

func (s Set) Has(v Value) bool

func (Set) Hash

func (s Set) Hash() hash.Hash

func (Set) Insert

func (s Set) Insert(values ...Value) Set

func (Set) Iter

func (s Set) Iter(cb setIterCallback)

func (Set) IterAll

func (s Set) IterAll(cb setIterAllCallback)

func (Set) Iterator

func (s Set) Iterator() SetIterator

func (Set) Len

func (s Set) Len() uint64

Collection interface

func (Set) Less

func (s Set) Less(other Value) bool

func (Set) Remove

func (s Set) Remove(values ...Value) Set

func (Set) Type

func (s Set) Type() *Type

func (Set) WalkRefs

func (s Set) WalkRefs(cb RefCallback)

func (Set) WalkValues

func (s Set) WalkValues(cb ValueCallback)

type SetIterator

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

	// 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(v Value) Value
}

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

func NewIntersectionIterator

func NewIntersectionIterator(iterA, iterB SetIterator) SetIterator

NewIntersectionIterator creates a intersect iterator from two other SetIterators.

func NewUnionIterator

func NewUnionIterator(iterA, iterB SetIterator) SetIterator

NewUnionIterator creates a union iterator from two other SetIterators.

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

Value interface

func (String) Hash

func (s String) Hash() hash.Hash

func (String) Less

func (s String) Less(other Value) bool

func (String) Type

func (s String) Type() *Type

func (String) WalkRefs

func (s String) WalkRefs(cb RefCallback)

func (String) WalkValues

func (s String) WalkValues(cb ValueCallback)

type Struct

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

func NewStruct

func NewStruct(name string, data StructData) Struct

func NewStructWithType

func NewStructWithType(t *Type, data ValueSlice) Struct

func (Struct) Diff

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

func (Struct) Equals

func (s Struct) Equals(other Value) bool

Value interface

func (Struct) Get

func (s Struct) Get(n string) Value

Get returns the value of a field in the struct. If the struct does not a have a field with the name name then this panics.

func (Struct) Hash

func (s Struct) Hash() hash.Hash

func (Struct) Less

func (s Struct) Less(other Value) bool

func (Struct) MaybeGet

func (s Struct) MaybeGet(n string) (Value, bool)

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) Set

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

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) Type

func (s Struct) Type() *Type

func (Struct) WalkRefs

func (s Struct) WalkRefs(cb RefCallback)

func (Struct) WalkValues

func (s Struct) WalkValues(cb ValueCallback)

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) *Type

func (StructDesc) HasUnresolvedCycle

func (s StructDesc) HasUnresolvedCycle(visited []*Type) bool

func (StructDesc) IterFields

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

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 Type

type Type struct {
	Desc TypeDesc
	// contains filtered or unexported fields
}

func MakeCycleType

func MakeCycleType(level uint32) *Type

func MakeListType

func MakeListType(elemType *Type) *Type

func MakeMapType

func MakeMapType(keyType, valType *Type) *Type

func MakePrimitiveType

func MakePrimitiveType(k NomsKind) *Type

func MakePrimitiveTypeByString

func MakePrimitiveTypeByString(p string) *Type

func MakeRefType

func MakeRefType(elemType *Type) *Type

func MakeSetType

func MakeSetType(elemType *Type) *Type

func MakeStructType

func MakeStructType(name string, fieldNames []string, fieldTypes []*Type) *Type

func MakeStructTypeFromFields

func MakeStructTypeFromFields(name string, fields FieldMap) *Type

func MakeUnionType

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

func (*Type) Describe

func (t *Type) Describe() (out string)

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

func (*Type) Equals

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

Value interface

func (*Type) HasUnresolvedCycle

func (t *Type) HasUnresolvedCycle() bool

func (*Type) Hash

func (t *Type) Hash() hash.Hash

func (*Type) Kind

func (t *Type) Kind() NomsKind

func (*Type) Less

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

func (*Type) Type

func (t *Type) Type() *Type

func (*Type) WalkRefs

func (t *Type) WalkRefs(cb RefCallback)

func (*Type) WalkValues

func (t *Type) WalkValues(cb ValueCallback)

type TypeCache

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

func NewTypeCache

func NewTypeCache() *TypeCache

func (*TypeCache) Lock

func (tc *TypeCache) Lock()

func (*TypeCache) Unlock

func (tc *TypeCache) Unlock()

type TypeDesc

type TypeDesc interface {
	Kind() NomsKind
	HasUnresolvedCycle(visited []*Type) bool
}

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

type TypeMap

type TypeMap map[string]*Type

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() Value

func (*UnionIterator) SkipTo

func (u *UnionIterator) SkipTo(v Value) Value

type ValidatingBatchingSink

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

func NewValidatingBatchingSink

func NewValidatingBatchingSink(cs chunks.ChunkStore) *ValidatingBatchingSink

func (*ValidatingBatchingSink) DecodeUnqueued

func (vbs *ValidatingBatchingSink) DecodeUnqueued(c *chunks.Chunk) DecodedChunk

DecodeUnqueued 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. However, if c has already been Enqueued, DecodeUnqueued returns an empty DecodedChunk.

func (*ValidatingBatchingSink) Enqueue

Enequeue adds c to the queue of Chunks waiting to be Put into vbs' backing ChunkStore. It is assumed that v is the Value decoded from c, and so v can be used to validate the ref-completeness of c. The instance keeps an internal buffer of Chunks, spilling to the ChunkStore when the buffer is full. If an attempt to Put Chunks fails, this method returns the BackpressureError from the underlying ChunkStore.

func (*ValidatingBatchingSink) Flush

func (vbs *ValidatingBatchingSink) Flush() (err chunks.BackpressureError)

Flush Puts any Chunks buffered by Enqueue calls into the backing ChunkStore. If the attempt to Put fails, this method returns the BackpressureError returned by the underlying ChunkStore.

func (*ValidatingBatchingSink) Prepare

func (vbs *ValidatingBatchingSink) Prepare(hints Hints)

Prepare primes the type info cache used to validate Enqueued Chunks by reading the Chunks referenced by the provided hints.

type Value

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

	// 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, Number 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 < Number < String < everything else.
	Less(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() hash.Hash

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

	// 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(RefCallback)

	// Type returns the type of the Noms value. All Noms values carry their runtime Noms type.
	Type() *Type
}

Value is the interface all Noms values implement.

func DecodeFromBytes

func DecodeFromBytes(data []byte, vr ValueReader, tc *TypeCache) Value

func DecodeValue

func DecodeValue(c chunks.Chunk, vr ValueReader) Value

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.Number "4" -> types.String true|false -> types.Boolean #<chars> -> hash.Hash

type ValueCallback

type ValueCallback func(v Value)

type ValueChanged

type ValueChanged struct {
	ChangeType DiffChangeType
	V          Value
}

type ValueReadWriter

type ValueReadWriter interface {
	ValueReader
	ValueWriter
	// contains filtered or unexported methods
}

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 {
	ReadValue(h hash.Hash) Value
}

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) Equals

func (vs ValueSlice) Equals(other ValueSlice) bool

func (ValueSlice) Len

func (vs ValueSlice) Len() int

func (ValueSlice) Less

func (vs ValueSlice) Less(i, j int) bool

func (ValueSlice) Swap

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

type ValueStore

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

ValueStore provides methods to read and write Noms Values to a BatchStore. It validates Values as they are written, but does not guarantee that these Values are persisted to the BatchStore until a subsequent Flush. or Close. Currently, WriteValue validates the following properties of a Value v: - v can be correctly serialized and its Ref taken - all Refs in v point to a Value that can be read from this ValueStore - all Refs in v point to a Value of the correct Type

func NewTestValueStore

func NewTestValueStore() *ValueStore

NewTestValueStore creates a simple struct that satisfies ValueReadWriter and is backed by a chunks.TestStore.

func NewValueStore

func NewValueStore(bs BatchStore) *ValueStore

NewValueStore returns a ValueStore instance that owns the provided BatchStore and manages its lifetime. Calling Close on the returned ValueStore will Close bs.

func NewValueStoreWithCache

func NewValueStoreWithCache(bs BatchStore, cacheSize uint64) *ValueStore

func (*ValueStore) BatchStore

func (lvs *ValueStore) BatchStore() BatchStore

func (*ValueStore) Close

func (lvs *ValueStore) Close() error

Close closes the underlying BatchStore

func (*ValueStore) Flush

func (lvs *ValueStore) Flush()

func (*ValueStore) ReadValue

func (lvs *ValueStore) ReadValue(r hash.Hash) Value

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) WriteValue

func (lvs *ValueStore) WriteValue(v Value) Ref

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(v Value) Ref
}

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