Documentation ¶
Overview ¶
Package note provides types and functions for interacting with a note maps data storage system.
Package note provides types and functions for interacting with a note maps data storage system.
Index ¶
- Constants
- Variables
- func Patch(a *TruncatedNote, ops []Operation) error
- type Database
- type DatabaseReader
- type DatabaseWriter
- type EmptyNote
- type FindLoadPatcher
- type FindLoader
- type Finder
- type GraphNote
- type ID
- type IDSlice
- func (xs IDSlice) Append(add ...ID) IDSliceDelta
- func (xs IDSlice) Apply(ops []IDSliceOp) IDSlice
- func (xs IDSlice) CanApply(ops []IDSliceOp) bool
- func (xs IDSlice) Delete(i, num int) IDSliceDelta
- func (xs IDSlice) DeleteElements(del ...ID) IDSliceDelta
- func (xs IDSlice) Insert(i int, add ...ID) IDSliceDelta
- func (xs IDSlice) PrefixMatch(ys []ID) int
- func (xs IDSlice) Retain(r int) IDSliceDelta
- func (ids IDSlice) String() string
- type IDSliceDelta
- type IDSliceOp
- type IDSliceOpDelete
- func (x IDSliceOpDelete) Apply(xs IDSlice) (IDSlice, IDSlice)
- func (x IDSliceOpDelete) Compact(op IDSliceOp) (IDSliceOp, bool)
- func (x IDSliceOpDelete) Leaves(in int) int
- func (x IDSliceOpDelete) Len() int
- func (x IDSliceOpDelete) Rebase(base IDSliceOp) (IDSliceOp, IDSliceOp, IDSliceOp)
- func (x IDSliceOpDelete) Skip(n int) IDSliceOp
- func (x IDSliceOpDelete) String() string
- type IDSliceOpInsert
- func (x IDSliceOpInsert) Apply(xs IDSlice) (IDSlice, IDSlice)
- func (x IDSliceOpInsert) Compact(op IDSliceOp) (IDSliceOp, bool)
- func (x IDSliceOpInsert) Leaves(in int) int
- func (x IDSliceOpInsert) Len() int
- func (x IDSliceOpInsert) Rebase(base IDSliceOp) (IDSliceOp, IDSliceOp, IDSliceOp)
- func (x IDSliceOpInsert) Skip(n int) IDSliceOp
- func (x IDSliceOpInsert) String() string
- type IDSliceOpRetain
- func (x IDSliceOpRetain) Apply(xs IDSlice) (IDSlice, IDSlice)
- func (x IDSliceOpRetain) Compact(op IDSliceOp) (IDSliceOp, bool)
- func (x IDSliceOpRetain) Leaves(in int) int
- func (x IDSliceOpRetain) Len() int
- func (x IDSliceOpRetain) Rebase(base IDSliceOp) (IDSliceOp, IDSliceOp, IDSliceOp)
- func (x IDSliceOpRetain) Skip(n int) IDSliceOp
- func (x IDSliceOpRetain) String() string
- type Loader
- type NoteDelta
- func (xs NoteDelta) ChangeContents(d IDSliceDelta) NoteDelta
- func (xs NoteDelta) ChangeTypes(d IDSliceDelta) NoteDelta
- func (xs NoteDelta) ChangeValueString(d runes.StringDelta) NoteDelta
- func (xs NoteDelta) ChangeValueType(vt ID) NoteDelta
- func (xs NoteDelta) GetContentIDs() IDSlice
- func (xs NoteDelta) GetID() ID
- func (xs NoteDelta) GetTypeIDs() IDSlice
- func (xs NoteDelta) GetValueString() runes.String
- func (xs NoteDelta) GetValueTypeID() ID
- func (xs NoteDelta) SetID(id ID) NoteDelta
- func (xs NoteDelta) Truncate() TruncatedNote
- type NoteMapDelta
- type NoteMapOp
- type NoteMapOpNoteDelta
- type NoteOp
- type NoteOpContentsDelta
- type NoteOpID
- type NoteOpTypesDelta
- type NoteOpValueDelta
- type NoteOpValueTypeDelta
- type Op
- type OpContentDelta
- type OpIDSliceDelta
- type OpSetValue
- type OpSetValueString
- type OpTypesDelta
- type Operation
- type OperationSlice
- func (os OperationSlice) InsertContent(id ID, index int, cs ...ID) OperationSlice
- func (os OperationSlice) PatchContent(id ID, ops []IDSliceOp) OperationSlice
- func (os OperationSlice) PatchTypes(id ID, ops []IDSliceOp) OperationSlice
- func (os OperationSlice) SetValue(id ID, vs string, vt ID) OperationSlice
- func (os OperationSlice) SetValueString(id ID, vs string) OperationSlice
- type Patcher
- type Plain
- type Query
- type Stage
- type StageNote
- func (x *StageNote) AddContent(id ID) (*StageNote, error)
- func (x *StageNote) GetContentIDs() ([]ID, error)
- func (x *StageNote) GetContents() ([]GraphNote, error)
- func (x *StageNote) GetID() ID
- func (x *StageNote) GetTypeIDs() ([]ID, error)
- func (x *StageNote) GetTypes() ([]GraphNote, error)
- func (x *StageNote) GetValue() (string, GraphNote, error)
- func (x *StageNote) InsertTypes(i int, add ...ID) error
- func (x *StageNote) Note(id ID) *StageNote
- func (x *StageNote) SetValue(lexical string, datatype ID) error
- type TruncatedNote
Constants ¶
const ( // EmptyLoader implements the Loader interface for a note map that is // always empty. EmptyLoader emptyLoader = 0 )
Variables ¶
var (
InvalidID = errors.New("invalid note id")
)
Functions ¶
func Patch ¶
func Patch(a *TruncatedNote, ops []Operation) error
Patch applies a set of operations to a.
Types ¶
type Database ¶
type Database interface { DatabaseReader DatabaseWriter io.Closer }
Database provides atomic isolated read and write operations over a note map.
An instance of Database should be closed when it is no longer needed.
type DatabaseReader ¶
type DatabaseReader interface { // IsolatedRead invokes f with a FindLoader that will read from an // unchanging version of the note map. IsolatedRead(f func(r FindLoader) error) error }
DatabaseReader provides isolated read operations over a note map.
type DatabaseWriter ¶
type DatabaseWriter interface { // IsolatedWrite invokes f with an isolated FindLoadPatcher that can read and // change a note map. // // If f returns an error, none of the changes will be saved. Implementations // should return an error in any case when changes are not saved. IsolatedWrite(f func(rw FindLoadPatcher) error) error }
DatabaseWriter provides atomic isolated write operations over a note map.
type EmptyNote ¶
type EmptyNote ID
EmptyNote is simply an empty GraphNote with nothing more than an ID.
func (EmptyNote) GetContents ¶
type FindLoadPatcher ¶
FindLoadPatcher combines the Finder, Loader, and Patcher interfaces.
type FindLoader ¶
FindLoader combines the Finder and Loader interfaces.
type Finder ¶
Finder can be implemented to support finding notes in a note map according to a query.
type GraphNote ¶
type GraphNote interface { GetID() ID GetValue() (string, GraphNote, error) GetContents() ([]GraphNote, error) GetTypes() ([]GraphNote, error) }
GraphNote is a graph-like interface to a note in a note map.
Since traversing from note to note in a note map may require fragile operations like loading query results from a storage backend, most methods can return an error instead of the requested data.
func ExpandNote ¶
func ExpandNote(tn TruncatedNote, l Loader) GraphNote
ExpandNote uses tn and l to provide a full GraphNote implementation.
type ID ¶
type ID string
ID is the type of values that identify note.
const EmptyID ID = ""
EmptyID is the zero or nil value for note identifiers, and never identifies a valid note.
EmptyID exists only to make code that specifies the zero value for note identifiers a bit more readable.
type IDSlice ¶
type IDSlice []ID
func (IDSlice) Append ¶
func (xs IDSlice) Append(add ...ID) IDSliceDelta
func (IDSlice) Delete ¶
func (xs IDSlice) Delete(i, num int) IDSliceDelta
func (IDSlice) DeleteElements ¶
func (xs IDSlice) DeleteElements(del ...ID) IDSliceDelta
func (IDSlice) PrefixMatch ¶
PrefixMatch returns the number of elements at the beginning of xs that match the elements at the beginning of ys.
func (IDSlice) Retain ¶
func (xs IDSlice) Retain(r int) IDSliceDelta
type IDSliceDelta ¶
type IDSliceDelta []IDSliceOp
func IDSliceDiff ¶
func IDSliceDiff(a, b []ID) IDSliceDelta
IDSliceDiff produces a set of operations that can be applied to xs to produce a slice that would match slice b.
func (IDSliceDelta) Delete ¶
func (x IDSliceDelta) Delete(d int) IDSliceDelta
func (IDSliceDelta) Insert ¶
func (x IDSliceDelta) Insert(add ...ID) IDSliceDelta
func (IDSliceDelta) Rebase ¶
func (x IDSliceDelta) Rebase(base IDSliceDelta) (IDSliceDelta, error)
func (IDSliceDelta) Retain ¶
func (x IDSliceDelta) Retain(r int) IDSliceDelta
type IDSliceOp ¶
type IDSliceOp interface { // Leaves returns how many elements of a slice of length n would remain // to be transformed by additional ops after applying this op. Returns // a negative number if and only if this op cannot be coherently // applied to a slice of length n. Leaves(n int) int // Len returns the number of elements inserted, retained, or deleted by // this op. Len() int // Skip returns an equivalent op that assumes its intent is already carried // out for the first n elements. May panic if n > Len(). Skip(n int) IDSliceOp // Rebase transforms op into a rebased op r (or nil), a subsequent op for // rebasing xn (or nil), and a subsequent base bn (or nil). Rebase(base IDSliceOp) (r IDSliceOp, xn IDSliceOp, bn IDSliceOp) // Compact expands this op to include o if possible, returning true if // successful. Compact(o IDSliceOp) (IDSliceOp, bool) Apply(IDSlice) (include IDSlice, remainder IDSlice) String() string }
type IDSliceOpDelete ¶
type IDSliceOpDelete int
func (IDSliceOpDelete) Leaves ¶
func (x IDSliceOpDelete) Leaves(in int) int
func (IDSliceOpDelete) Len ¶
func (x IDSliceOpDelete) Len() int
func (IDSliceOpDelete) Rebase ¶
func (x IDSliceOpDelete) Rebase(base IDSliceOp) (IDSliceOp, IDSliceOp, IDSliceOp)
func (IDSliceOpDelete) Skip ¶
func (x IDSliceOpDelete) Skip(n int) IDSliceOp
func (IDSliceOpDelete) String ¶
func (x IDSliceOpDelete) String() string
type IDSliceOpInsert ¶
type IDSliceOpInsert []ID
func (IDSliceOpInsert) Leaves ¶
func (x IDSliceOpInsert) Leaves(in int) int
func (IDSliceOpInsert) Len ¶
func (x IDSliceOpInsert) Len() int
func (IDSliceOpInsert) Rebase ¶
func (x IDSliceOpInsert) Rebase(base IDSliceOp) (IDSliceOp, IDSliceOp, IDSliceOp)
func (IDSliceOpInsert) Skip ¶
func (x IDSliceOpInsert) Skip(n int) IDSliceOp
func (IDSliceOpInsert) String ¶
func (x IDSliceOpInsert) String() string
type IDSliceOpRetain ¶
type IDSliceOpRetain int
func (IDSliceOpRetain) Leaves ¶
func (x IDSliceOpRetain) Leaves(in int) int
func (IDSliceOpRetain) Len ¶
func (x IDSliceOpRetain) Len() int
func (IDSliceOpRetain) Rebase ¶
func (x IDSliceOpRetain) Rebase(base IDSliceOp) (IDSliceOp, IDSliceOp, IDSliceOp)
func (IDSliceOpRetain) Skip ¶
func (x IDSliceOpRetain) Skip(n int) IDSliceOp
func (IDSliceOpRetain) String ¶
func (x IDSliceOpRetain) String() string
type Loader ¶
type Loader interface { // Load returns a slice of all found notes. // // All notes exist implicitly, even if they are empty. An error indicates // something actually went wrong. Load(ids []ID) ([]GraphNote, error) }
Loader can be implemented to support loading notes by id.
type NoteDelta ¶
type NoteDelta []NoteOp
func NoteDeltaFromTruncatedNote ¶
func NoteDeltaFromTruncatedNote(n TruncatedNote) NoteDelta
func (NoteDelta) ChangeContents ¶
func (xs NoteDelta) ChangeContents(d IDSliceDelta) NoteDelta
func (NoteDelta) ChangeTypes ¶
func (xs NoteDelta) ChangeTypes(d IDSliceDelta) NoteDelta
func (NoteDelta) ChangeValueString ¶
func (xs NoteDelta) ChangeValueString(d runes.StringDelta) NoteDelta
func (NoteDelta) ChangeValueType ¶
func (NoteDelta) GetContentIDs ¶
func (NoteDelta) GetTypeIDs ¶
func (NoteDelta) GetValueString ¶
func (NoteDelta) GetValueTypeID ¶
func (NoteDelta) Truncate ¶
func (xs NoteDelta) Truncate() TruncatedNote
type NoteMapDelta ¶
type NoteMapDelta []NoteMapOp
func (NoteMapDelta) ChangeNote ¶
func (xs NoteMapDelta) ChangeNote(n NoteDelta) NoteMapDelta
type NoteMapOpNoteDelta ¶
type NoteMapOpNoteDelta NoteDelta
type NoteOpContentsDelta ¶
type NoteOpContentsDelta IDSliceDelta
type NoteOpTypesDelta ¶
type NoteOpTypesDelta IDSliceDelta
type NoteOpValueDelta ¶
type NoteOpValueDelta runes.StringDelta
type NoteOpValueTypeDelta ¶
type NoteOpValueTypeDelta ID
type Op ¶
type Op ID
Op is a minimal implementation of Operation meant to be used as a mixin for operations that affect only one note.
type OpContentDelta ¶
type OpContentDelta OpIDSliceDelta
func (OpContentDelta) String ¶
func (o OpContentDelta) String() string
type OpIDSliceDelta ¶
func (OpIDSliceDelta) String ¶
func (o OpIDSliceDelta) String() string
type OpSetValue ¶
OpSetValue sets the value and data type of a note to Lexical and Datatype.
func (OpSetValue) String ¶
func (os OpSetValue) String() string
type OpSetValueString ¶
OpSetValueString sets the value of a note to Lexical.
func (OpSetValueString) String ¶
func (os OpSetValueString) String() string
type OpTypesDelta ¶
type OpTypesDelta OpIDSliceDelta
func (OpTypesDelta) String ¶
func (o OpTypesDelta) String() string
type Operation ¶
Operation is implemented by types that can describe changes that might be made to a note map.
func Diff ¶
func Diff(a, b TruncatedNote) []Operation
Diff produces a set of operations that if applied to a would make it match b.
Differences in ID are not considered: a and b are not required to have the same ID, and applying the operations to a will not cause it to have the same ID as b.
type OperationSlice ¶
type OperationSlice []Operation
func (OperationSlice) InsertContent ¶
func (os OperationSlice) InsertContent(id ID, index int, cs ...ID) OperationSlice
InsertContent returns a new OperationSlice that also inserts cs to the contents of note id at index.
func (OperationSlice) PatchContent ¶
func (os OperationSlice) PatchContent(id ID, ops []IDSliceOp) OperationSlice
PatchContent returns a new OperationSlice that also applies ops to the contents of note id.
func (OperationSlice) PatchTypes ¶
func (os OperationSlice) PatchTypes(id ID, ops []IDSliceOp) OperationSlice
PatchTypes returns a new OperationSlice that also applies ops to the types of note id.
func (OperationSlice) SetValue ¶
func (os OperationSlice) SetValue(id ID, vs string, vt ID) OperationSlice
SetValue returns a new OperationSlice that also sets the value and type of note id to vs and vt.
func (OperationSlice) SetValueString ¶
func (os OperationSlice) SetValueString(id ID, vs string) OperationSlice
SetValue returns a new OperationSlice that also sets the value of note id to vs.
type Patcher ¶
Patcher can be implemented to support making changes to notes in a note map by applying a set of differences to them.
type Plain ¶
Plain is a "plain old Go object" representation of a note that uses pointers to refer directly to related notes in memory.
Most of package notes is designed for working with entire note maps which may not fit in memory. Plain is better suited for working with limited subgraphs, for example when decoding subgraphs that are to be merged into a note map.
type Query ¶
type Query struct { }
Query limits the notes that will be found when loading information from a graph.
The default query matches all notes.
type Stage ¶
type Stage struct { Ops OperationSlice Base Loader }
Stage describes a set of changes that might be made to a note map.
The default stage describes an empty set of changes to be made to an empty note map.
A default Stage{} is an empty set of changes made to an empty note map.
type StageNote ¶
StageNote supports updating the content of a note within a batch, and also implements the GraphNote interface to read the hypothetical state of a note with the batch applied.
func MustStageNote ¶
func (*StageNote) AddContent ¶
AddContent expands the staged operations to add content to this note.
func (*StageNote) GetContentIDs ¶
func (*StageNote) GetContents ¶
func (*StageNote) GetTypeIDs ¶
func (*StageNote) InsertTypes ¶
AddContent expands the staged operations to add content to this note.
type TruncatedNote ¶
TruncatedNote is a minimal representation of a note intended for storage integrations and for algorithms that don't need to traverse a graph of note.
func TruncateNote ¶
func TruncateNote(n GraphNote) (TruncatedNote, error)
TruncateNote returns a TruncatedNote representation of n.
func (TruncatedNote) Equals ¶
func (x TruncatedNote) Equals(y TruncatedNote) bool
Equals return true if and only if x is deeply equal to y.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package textile uses Textileio ThreadsDB to implement the github.com/google/note-maps/note interfaces.
|
Package textile uses Textileio ThreadsDB to implement the github.com/google/note-maps/note interfaces. |
Package yaml marshals notes to and from YAML format.
|
Package yaml marshals notes to and from YAML format. |