entryset

package
v0.0.50 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2021 License: Apache-2.0, NCSA Imports: 10 Imported by: 2

Documentation

Overview

Package entryset implements a compact representation for sets of Kythe entry messages in the format emitted by indexers.

Call New to construct an empty set, and use the Add method to add entries:

set := entryset.New(nil)
for entry := range readEntries() {
   if err := set.Add(entry); err != nil {
      log.Exitf("Invalid entry: %v", err)
   }
}

Entries are automatically deduplicated. You can traverse the contents of an entry set with the Visit method, which takes a callback:

set.Visit(func(e *storagepb.Entry) bool {
   process(e)
   return wantMore
})

An entry set may or may not be "canonical": A canonical entry set has the property that calling its Visit method will deliver all the entries in the canonical entry order (http://www.kythe.io/docs/kythe-storage.html). A newly-created entry set is canonical; a call to Add may invalidate this status. Call the Canonicalize method to canonicalize an entryset.

set := entryset.New(nil) // set is canonical
set.Add(e)               // set is no longer canonical
set.Canonicalize()       // set is (once again) canonical

An entryset can be converted into a kythe.storage.EntrySet protobuf message using the Encode method. This message is defined in entryset.proto. You can construct a Set from an EntrySet message using Decode:

pb := old.Encode()
new, err := entryset.Decode(pb)
if err != nil {
  log.Exitf("Invalid entryset message: %v", err)
}

When rendered in wire format, the protobuf encoding is considerably more compact than a naive entry stream.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// When encoding a set to wire format, any symbol longer than this number
	// of bytes will be split into chunks of at most this length.
	// If ≤ 0, no splitting is performed.
	MaxSymbolBytes int
}

Options provide configuration settings for a Set. A nil *Options provides sensible default values.

type Set

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

A Set represents a set of unique entries.

func Decode

func Decode(es *espb.EntrySet) (*Set, error)

Decode constructs a set from a protobuf representation. The resulting set will be canonical if the encoding was; if the message was encoded by the Encode method of a *Set it will be so.

func New

func New(opts *Options) *Set

New constructs a new Set containing no entries.

func Unmarshal

func Unmarshal(data []byte) (*Set, error)

Unmarshal unmarshals a wire-format EntrySet message into a *Set.

func (*Set) Add

func (s *Set) Add(e *spb.Entry) error

Add adds the specified entry to the set, returning an error if the entry is structurally invalid. An invalid entry does not corrupt the state of the set, such entries are simply discarded. It is therefore safe to ignore an error from this method if you want to drop invalid data.

func (*Set) Canonicalize

func (s *Set) Canonicalize() *Set

Canonicalize modifies s in-place to be in canonical form, and returns s to permit chaining. If s is already in canonical form, it is returned unmodified.

func (*Set) Encode

func (s *Set) Encode() *espb.EntrySet

Encode constructs a canonical version of s and renders it into a kythe.storage.EntrySet protobuf message.

func (*Set) Sources

func (s *Set) Sources(f func(*intpb.Source) bool)

Sources groups the entries of the set into Source messages and invokes f for each one. If f returns false the visit is aborted.

func (*Set) Stats

func (s *Set) Stats() *Stats

Stats returns current statistics for s.

func (*Set) Visit

func (s *Set) Visit(f func(*spb.Entry) bool)

Visit calls f with each entry in the set. If s is canonical, entries are delivered in canonical order; otherwise the order is unspecified. If f returns false the visit is aborted.

func (*Set) WriteTo

func (s *Set) WriteTo(w io.Writer) (int64, error)

WriteTo writes s to w as a wire-format EntrySet message.

type Stats

type Stats struct {
	Adds    int // number of times Add was successfully invoked
	Errors  int // number of times Add reported an error
	Nodes   int // count of unique nodes stored
	Facts   int // total number of facts stored
	Edges   int // total number of edges stored
	Symbols int // total count of unique symbols stored
}

Stats carry statistics about the contents of a Set.

Jump to

Keyboard shortcuts

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