utils

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2018 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

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 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) (SmallMap, bool)

Delete returns a SmallMap from which the first entry has been removed 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) (SmallMap, bool)

DeleteIf returns a SmallMap from which all entries have been removed 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.

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.

Jump to

Keyboard shortcuts

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