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 ¶
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 (*Set) Add ¶
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 ¶
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 ¶
Encode constructs a canonical version of s and renders it into a kythe.storage.EntrySet protobuf message.
func (*Set) Sources ¶
Sources groups the entries of the set into Source messages and invokes f for each one. If f returns false the visit is aborted.
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.