assemble

package
v0.0.67 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0, NCSA Imports: 22 Imported by: 0

Documentation

Overview

Package assemble provides functions to build the various components (nodes, edges, and decorations) of an xrefs serving table.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendEntry added in v0.0.21

func AppendEntry(src *ipb.Source, e *spb.Entry)

AppendEntry adds the given Entry to the Source's facts or edges. It is assumed that src.Ticket == kytheuri.ToString(e.Source).

func CrossReference added in v0.0.17

func CrossReference(file *srvpb.File, norm *span.Normalizer, d *srvpb.FileDecorations_Decoration, tgt *srvpb.Node) (*ipb.CrossReference, error)

CrossReference returns a (Referent, TargetAnchor) *ipb.CrossReference equivalent to the given decoration. The decoration's anchor is expanded given its parent file and associated Normalizer.

func ExpandAnchor added in v0.0.18

func ExpandAnchor(anchor *srvpb.RawAnchor, file *srvpb.File, norm *span.Normalizer, kind string) (*srvpb.ExpandedAnchor, error)

ExpandAnchor returns the ExpandedAnchor equivalent of the given RawAnchor where file (and its associated Normalizer) must be the anchor's parent file.

func FactsToMap added in v0.0.16

func FactsToMap(facts []*cpb.Fact) map[string][]byte

FactsToMap returns a map from fact name to value.

func FilterTextFacts added in v0.0.16

func FilterTextFacts(n *srvpb.Node) *srvpb.Node

FilterTextFacts returns a new Node without any text facts.

func GetFact added in v0.0.16

func GetFact(facts []*cpb.Fact, name string) []byte

GetFact returns the value of the first fact in facts with the given name; otherwise returns nil.

func Node added in v0.0.21

func Node(s *ipb.Source) *srvpb.Node

Node returns the Source as a srvpb.Node.

func PartialReverseEdges added in v0.0.16

func PartialReverseEdges(src *ipb.Source) []*srvpb.Edge

PartialReverseEdges returns the set of partial reverse edges from the given source. Each reversed Edge has its Target fully populated and its Source will have no facts. To ensure every node has at least 1 Edge, the first Edge will be a self-edge without a Kind or Target. To reduce the size of edge sets, each Target will have any text facts filtered (see FilterTextFacts).

func SourceFromEntries

func SourceFromEntries(entries []*spb.Entry) *ipb.Source

SourceFromEntries returns a new Source from the given a set of entries with the same source VName.

func Sources

func Sources(rd stream.EntryReader, f func(*ipb.Source) error) error

Sources constructs a new Source for every contiguous set of entries sharing the same Source, calling f for each.

Types

type ByAnchorTicket added in v0.0.22

type ByAnchorTicket []*srvpb.ExpandedAnchor

ByAnchorTicket sorts anchors by their ticket.

func (ByAnchorTicket) Len added in v0.0.22

func (s ByAnchorTicket) Len() int

func (ByAnchorTicket) Less added in v0.0.22

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

func (ByAnchorTicket) Swap added in v0.0.22

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

type ByOffset

ByOffset sorts file decorations by their byte offsets.

func (ByOffset) Len

func (s ByOffset) Len() int

func (ByOffset) Less

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

func (ByOffset) Swap

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

type ByTicket added in v0.0.22

type ByTicket []*srvpb.Node

ByTicket sorts nodes by their ticket.

func (ByTicket) Len added in v0.0.22

func (s ByTicket) Len() int

func (ByTicket) Less added in v0.0.22

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

func (ByTicket) Swap added in v0.0.22

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

type CrossReferencesBuilder added in v0.0.17

type CrossReferencesBuilder struct {
	MaxPageSize int

	Output     func(context.Context, *srvpb.PagedCrossReferences) error
	OutputPage func(context.Context, *srvpb.PagedCrossReferences_Page) error
	// contains filtered or unexported fields
}

CrossReferencesBuilder is a type wrapper around a pager.SetPager that emits *srvpb.PagedCrossReferences and *srvpb.PagedCrossReferences_Pages. Each PagedCrossReferences_Group added the builder should be in sorted order so that groups of the same kind are added sequentially. Before each set of like-kinded groups, StartSet should be called with the source ticket of the proceeding groups. See also EdgeSetBuilder.

func (*CrossReferencesBuilder) AddGroup added in v0.0.17

AddGroup add the given group of cross-references to the currently being built *srvpb.PagedCrossReferences. The group should share the same source ticket as given to the mostly recent invocation to StartSet.

func (*CrossReferencesBuilder) Flush added in v0.0.17

Flush emits any *srvpb.PagedCrossReferences and *srvpb.PagedCrossReferences_Page currently being built.

func (*CrossReferencesBuilder) StartSet added in v0.0.17

func (b *CrossReferencesBuilder) StartSet(ctx context.Context, src *srvpb.Node) error

StartSet begins a new *srvpb.PagedCrossReferences. As a side-effect, a previously-built srvpb.PagedCrossReferences may be emitted.

type DecorationFragmentBuilder added in v0.0.16

type DecorationFragmentBuilder struct {
	Output func(ctx context.Context, file string, fragment *srvpb.FileDecorations) error
	// contains filtered or unexported fields
}

DecorationFragmentBuilder builds pieces of FileDecorations given an ordered (see AddEdge) stream of completed Edges. Each fragment constructed (either by AddEdge or Flush) will be emitted using the Output function in the builder. There are two types of fragments: file fragments (which have their SourceText, FileTicket, and Encoding set) and decoration fragments (which have only Decoration set).

func (*DecorationFragmentBuilder) AddEdge added in v0.0.16

AddEdge adds the given edge to the current fragment (or emits some fragments and starts a new fragment with e). AddEdge must be called in GraphStore sorted order of the Edges with the beginning to every set of edges with the same Source having a signaling Edge with only its Source set (no Kind or Target). Otherwise, every Edge must have a completed Source, Kind, and Target. Flush must be called after every call to AddEdge in order to output any remaining fragments.

func (*DecorationFragmentBuilder) Flush added in v0.0.16

Flush outputs any remaining fragments that are being built. It is safe, but usually unnecessary, to call Flush in between sets of Edges with the same Source. This also means that DecorationFragmentBuilder can be used to construct decoration fragments in parallel by partitioning edges along the same boundaries.

type EdgeSetBuilder

type EdgeSetBuilder struct {
	// MaxEdgePageSize is maximum number of edges that are allowed in the
	// PagedEdgeSet and any EdgePage.  If MaxEdgePageSize <= 0, no paging is
	// attempted.
	MaxEdgePageSize int

	// Output is used to emit each PagedEdgeSet constructed.
	Output func(context.Context, *srvpb.PagedEdgeSet) error
	// OutputPage is used to emit each EdgePage constructed.
	OutputPage func(context.Context, *srvpb.EdgePage) error
	// contains filtered or unexported fields
}

EdgeSetBuilder constructs a set of PagedEdgeSets and EdgePages from a sequence of Nodes and EdgeSet_Groups. For each set of groups with the same source, a call to StartEdgeSet must precede. All EdgeSet_Groups for the same source are then assumed to be given sequentially to AddGroup, secondarily ordered by the group's edge kind. If given in this order, Output will be given exactly 1 PagedEdgeSet per source with as few EdgeSet_Group per edge kind as to satisfy MaxEdgePageSize (MaxEdgePageSize == 0 indicates that there will be exactly 1 edge group per edge kind). If not given in this order, no guarantees can be made. Flush must be called after the final call to AddGroup.

func (*EdgeSetBuilder) AddGroup

func (b *EdgeSetBuilder) AddGroup(ctx context.Context, eg *srvpb.EdgeGroup) error

AddGroup adds a EdgeSet_Group to current EdgeSet being built, possibly emitting a new PagedEdgeSet and/or EdgePage. StartEdgeSet must be called before any calls to this method. See EdgeSetBuilder's documentation for the assumed order of the groups and this method's relation to StartEdgeSet.

func (*EdgeSetBuilder) Flush

func (b *EdgeSetBuilder) Flush(ctx context.Context) error

Flush signals the end of the current PagedEdgeSet being built, flushing it, and its EdgeSet_Groups to the output function. This should be called after the final call to AddGroup. Manually calling Flush at any other time is unnecessary.

func (*EdgeSetBuilder) StartEdgeSet added in v0.0.16

func (b *EdgeSetBuilder) StartEdgeSet(ctx context.Context, src *srvpb.Node) error

StartEdgeSet begins a new EdgeSet for the given source node, possibly emitting a PagedEdgeSet for the previous EdgeSet. Each following call to AddGroup adds the group to this new EdgeSet until another call to StartEdgeSet is made.

Jump to

Keyboard shortcuts

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