utils

package
v5.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2022 License: AGPL-3.0, AGPL-3.0-or-later Imports: 9 Imported by: 0

Documentation

Overview

Package utils provides utility functions and types that are needed in elprep.

Index

Constants

View Source
const (
	// ProgramName is "elprep"
	ProgramName = "elprep"

	// ProgramVersion is the version of the elprep binary
	ProgramVersion = "5.1.3"

	// ProgramURL is the repository for the elprep source code
	ProgramURL = "http://github.com/exascience/elprep"
)

Variables

This section is empty.

Functions

func Find

func Find(dict []StringMap, predicate func(record StringMap) bool) int

Find returns the first index in a slice of StringMap where the predicate returns true, or -1 if predicate never returns true.

func HandleBGZF

func HandleBGZF(buf *bufio.Reader) io.Reader

HandleBGZF checks if the given reader produces a gzip file by looking at the initial byte. It then either returns a bgzf.Reader, or returns the given reader unchanged. HandleBGZF uses ReadByte und UnreadByte.

func SymbolHash

func SymbolHash(s Symbol) uint64

SymbolHash computes a hash value for the given Symbol.

Types

type SmallMap

type SmallMap []SmallMapEntry

A SmallMap maps keys to values, similar to Go's built-in maps. A SmallMap can be more efficient in terms of memory and runtime performance than a native map if it has only few entries. SmallMap keys are always symbols.

func (*SmallMap) Delete

func (m *SmallMap) Delete(key Symbol) bool

Delete removes the first entry from a SmallMap that has the same key as the given key.

It also returns true if an entry was removed, and false if no entry was removed because there was no entry for the given key.

func (*SmallMap) DeleteIf

func (m *SmallMap) DeleteIf(test func(key Symbol, val interface{}) bool) bool

DeleteIf removes all entries from a SmallMap that satisfy the given test.

It also returns true if any entry was removed, and false if no entry was removed because no entry matched the given test.

func (SmallMap) Get

func (m SmallMap) Get(key Symbol) (interface{}, bool)

Get returns the first entry in the SmallMap that has the same key as the given key.

It returns the found value and true if the key was found, otherwise nil and false.

func (*SmallMap) Set

func (m *SmallMap) Set(key Symbol, value interface{})

Set associates the given value with the given key.

It does so by either setting the value of the first entry that has the same key as the given key, or else by appending a new key/value pair to the end of the SmallMap if no entry already has that key.

func (SmallMap) String

func (m SmallMap) String() string

type SmallMapEntry

type SmallMapEntry struct {
	Key   Symbol
	Value interface{}
}

SmallMapEntry is an entry in a SmallMap.

type StringMap

type StringMap map[string]string

A StringMap maps strings to strings.

func (StringMap) SetUniqueEntry

func (record StringMap) SetUniqueEntry(key, value string) bool

SetUniqueEntry checks if a mapping for the given key already exists in the StringMap. If this is the case, it returns false and the StringMap is not modified. Otherwise, the given key/value pair is added to the StringMap.

type Symbol

type Symbol *string

A Symbol is a unique pointer to a string.

func Intern

func Intern(s string) Symbol

Intern returns a Symbol for the given string.

It always returns the same pointer for strings that are equal, and different pointers for strings that are not equal. So for two strings s1 and s2, if s1 == s2, then Intern(s1) == Intern(s2), and if s1 != s2, then Intern(s1) != Intern(s2).

Dereferencing the pointer always yields a string that is equal to the original string: *Intern(s) == s always holds.

It is safe for multiple goroutines to call Intern concurrently.

Directories

Path Synopsis
packge bgzf provides readers and writers for BGZF files.
packge bgzf provides readers and writers for BGZF files.
Package nibbles is a library for representing sequences of 4-bit values.
Package nibbles is a library for representing sequences of 4-bit values.

Jump to

Keyboard shortcuts

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