symbol

package
v0.0.0-...-9d3c4bc Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package symbol manages symbols. Symbols are deduped strings represented as small integers.

Index

Constants

View Source
const AnonAccName = "_acc"

AnonAccName and AnonValName are passed to the reduce combiner.

View Source
const AnonRowName = "_"

AnonRowName is a variable used to store a row that's not a struct. For a struct, each field becomes a separate variable.

View Source
const AnonValName = "_val"
View Source
const (
	// Invalid is a sentinel.
	Invalid = ID(0)
)

Variables

View Source
var (
	// List of frequently used symbols.
	Chrom    = Intern("chrom")
	Date     = Intern("date")
	Default  = Intern("default")
	End      = Intern("end")
	Feat     = Intern("feat")
	Filter   = Intern("filter")
	Key      = Intern("key")
	Length   = Intern("length")
	Map      = Intern("map")
	Name     = Intern("name")
	Path     = Intern("path")
	Pos      = Intern("pos")
	Row      = Intern("row")
	Shards   = Intern("shards")
	Start    = Intern("start")
	Type     = Intern("type")
	Value    = Intern("value")
	Subshard = Intern("subshard")
	Depth    = Intern("depth")
	Mode     = Intern("mode")
	GZIP     = Intern("gzip")

	// Fragment table field names.
	Reference = Intern("reference")

	// BAM table field names.
	MapQ  = Intern("mapq")
	Cigar = Intern("cigar")
	Flags = Intern("flags")
	RNext = Intern("rnext")
	PNext = Intern("pnext")
	TLen  = Intern("tlen")
	Seq   = Intern("seq")
	Qual  = Intern("qual")
	// AuxTags contains common aux tags.
	AuxTags      = map[sam.Tag]ID{}
	AuxTagsIndex = map[ID]sam.Tag{}

	AnonRow = Intern(AnonRowName)
	AnonAcc = Intern(AnonAccName)
	AnonVal = Intern(AnonValName)
)

Functions

func MarkPreInternedSymbols

func MarkPreInternedSymbols()

MarkPreInternedSymbols must be called at the end of gql initialization.

Types

type ID

type ID int32

ID represents an interned symbol.

func Intern

func Intern(v string) ID

Intern finds or creates an ID for the given string.

func (ID) Hash

func (id ID) Hash() hash.Hash

Hash hashes a symbol.

func (ID) Marshal

func (id ID) Marshal(enc *marshal.Encoder)

Marshal encodes the ID in binary.

func (ID) MarshalBinary

func (id ID) MarshalBinary() ([]byte, error)

MarshalBinary implements the GOB interface.

func (ID) Str

func (id ID) Str() string

Str returns a human-readable string.

Note: we don't call it String() since it makes the code deadlock prone.

func (*ID) Unmarshal

func (id *ID) Unmarshal(dec *marshal.Decoder)

Unmarshal decodes the data produced by MarshalGOB.

func (*ID) UnmarshalBinary

func (id *ID) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the GOB interface.

type SymbolMap

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

SymbolMap is a concurrent map. A reader can access the map without lock, regardless of background updates. The writer side must coordinate using an external mutex if there are multiple writers. This map is linearizable.

Example:

m := NewSymbolMap(10)
go func() {  // writer
  m.Store("foo", "bar")
}()
go func() {  // reader
  val, ok := m.Load("foo")
}

func NewSymbolMap

func NewSymbolMap(initialLenHint int) *SymbolMap

NewSymbolMap creates a new map. Arg initialLenHint suggests the the initial capacity. If you plan to store 100 keys, then pass 100 as the value. If you don't know the capacity, pass 0 as initialLenHint.

func (*SymbolMap) Load

func (m *SymbolMap) Load(key string) (ID, bool)

Load finds a value with the given key. Returns false if not found.

func (*SymbolMap) Store

func (m *SymbolMap) Store(key string, value ID)

Store stores the value for the given key. If the key is already in the map, it updates the mapping to the given value.

Caution: if Store() is going to be called concurrently, it must be serialized externally.

Jump to

Keyboard shortcuts

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