cockroach: github.com/cockroachdb/cockroach/pkg/util Index | Files | Directories

package util

import "github.com/cockroachdb/cockroach/pkg/util"

Index

Package Files

every_n.go fast_int_map.go fast_int_set.go hash.go nocopy.go pluralize.go race_off.go reflect.go smalltrace.go strings.go testaddr_random.go topk.go union_find.go unresolved_addr.go unresolved_addr.pb.go

Constants

const RaceEnabled = false

RaceEnabled is true if CockroachDB was built with the race build tag.

Variables

var (
    ErrInvalidLengthUnresolvedAddr = fmt.Errorf("proto: negative length found during unmarshaling")
    ErrIntOverflowUnresolvedAddr   = fmt.Errorf("proto: integer overflow")
)
var TestAddr = NewUnresolvedAddr("tcp", "127.0.0.1:0")

TestAddr is an address to use for test servers. Listening on port 0 causes the kernel to allocate an unused port.

func CRC32 Uses

func CRC32(data []byte) uint32

CRC32 computes the Castagnoli CRC32 of the given data.

func EnableRacePreemptionPoints Uses

func EnableRacePreemptionPoints() func()

EnableRacePreemptionPoints enables goroutine preemption points declared with RacePreempt for builds using the race build tag.

func EqualPtrFields Uses

func EqualPtrFields(src, dst reflect.Value, prefix string) []string

EqualPtrFields uses reflection to check two "mirror" structures for matching pointer fields that point to the same object. Used to verify cloning/deep copy functions.

Returns the names of equal pointer fields.

func GetSingleRune Uses

func GetSingleRune(s string) (rune, error)

GetSingleRune decodes the string s as a single rune if possible.

func GetSmallTrace Uses

func GetSmallTrace(skip int) string

GetSmallTrace returns a comma-separated string containing the top 5 callers from a given skip level.

func MoveTopKToFront Uses

func MoveTopKToFront(data sort.Interface, k int)

MoveTopKToFront moves the top K elements to the front. It makes O(n) calls to data.Less and data.Swap (with very high probability). It uses Hoare's selection algorithm (aka quickselect).

func Pluralize Uses

func Pluralize(n int64) string

Pluralize returns a single character 's' unless n == 1.

func RacePreempt Uses

func RacePreempt()

RacePreempt adds a goroutine preemption point if CockroachDB was built with the race build tag and preemption points have been enabled. The function is a no-op (and should be optimized out through dead code elimination) if the race build tag was not used.

type EveryN Uses

type EveryN struct {
    // N is the minimum duration of time between log messages.
    N   time.Duration

    syncutil.Mutex
    // contains filtered or unexported fields
}

EveryN provides a way to rate limit spammy events. It tracks how recently a given event has occurred so that it can determine whether it's worth handling again.

The zero value for EveryN is usable and is equivalent to Every(0), meaning that all calls to ShouldProcess will return true.

NOTE: If you specifically care about log messages, you should use the version of this in the log package, as it integrates with the verbosity flags.

func Every Uses

func Every(n time.Duration) EveryN

Every is a convenience constructor for an EveryN object that allows a log message every n duration.

func (*EveryN) ShouldProcess Uses

func (e *EveryN) ShouldProcess(now time.Time) bool

ShouldProcess returns whether it's been more than N time since the last event.

type FastIntMap Uses

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

FastIntMap is a replacement for map[int]int which is more efficient when both keys and values are small. It can be passed by value (but Copy must be used for independent modification of copies).

func (FastIntMap) Copy Uses

func (m FastIntMap) Copy() FastIntMap

Copy returns a FastIntMap that can be independently modified.

func (FastIntMap) Empty Uses

func (m FastIntMap) Empty() bool

Empty returns true if the map is empty.

func (FastIntMap) ForEach Uses

func (m FastIntMap) ForEach(fn func(key, val int))

ForEach calls the given function for each key/value pair in the map (in arbitrary order).

func (FastIntMap) Get Uses

func (m FastIntMap) Get(key int) (value int, ok bool)

Get returns the current value mapped to key, or ok=false if the key is unmapped.

func (FastIntMap) Len Uses

func (m FastIntMap) Len() int

Len returns the number of keys in the map.

func (FastIntMap) MaxKey Uses

func (m FastIntMap) MaxKey() (_ int, ok bool)

MaxKey returns the maximum key that is in the map. If the map is empty, returns ok=false.

func (FastIntMap) MaxValue Uses

func (m FastIntMap) MaxValue() (_ int, ok bool)

MaxValue returns the maximum value that is in the map. If the map is empty, returns ok=false.

func (*FastIntMap) Set Uses

func (m *FastIntMap) Set(key, val int)

Set maps a key to the given value.

func (FastIntMap) String Uses

func (m FastIntMap) String() string

String prints out the contents of the map in the following format:

map[key1:val1 key2:val2 ...]

The keys are in ascending order.

func (*FastIntMap) Unset Uses

func (m *FastIntMap) Unset(key int)

Unset unmaps the given key.

type FastIntSet Uses

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

FastIntSet keeps track of a set of integers. It does not perform any allocations when the values are small. It is not thread-safe.

func MakeFastIntSet Uses

func MakeFastIntSet(vals ...int) FastIntSet

MakeFastIntSet returns a set initialized with the given values.

func (*FastIntSet) Add Uses

func (s *FastIntSet) Add(i int)

Add adds a value to the set. No-op if the value is already in the set.

func (*FastIntSet) AddRange Uses

func (s *FastIntSet) AddRange(from, to int)

AddRange adds values 'from' up to 'to' (inclusively) to the set. E.g. AddRange(1,5) adds the values 1, 2, 3, 4, 5 to the set. 'to' must be >= 'from'. AddRange is always more efficient than individual Adds.

func (FastIntSet) Contains Uses

func (s FastIntSet) Contains(i int) bool

Contains returns true if the set contains the value.

func (FastIntSet) Copy Uses

func (s FastIntSet) Copy() FastIntSet

Copy returns a copy of s which can be modified independently.

func (*FastIntSet) CopyFrom Uses

func (s *FastIntSet) CopyFrom(c FastIntSet)

CopyFrom sets the receiver to a copy of c, which can then be modified independently.

func (FastIntSet) Difference Uses

func (s FastIntSet) Difference(rhs FastIntSet) FastIntSet

Difference returns the elements of s that are not in rhs as a new set.

func (*FastIntSet) DifferenceWith Uses

func (s *FastIntSet) DifferenceWith(rhs FastIntSet)

DifferenceWith removes any elements in rhs from this set.

func (FastIntSet) Empty Uses

func (s FastIntSet) Empty() bool

Empty returns true if the set is empty.

func (FastIntSet) Equals Uses

func (s FastIntSet) Equals(rhs FastIntSet) bool

Equals returns true if the two sets are identical.

func (FastIntSet) ForEach Uses

func (s FastIntSet) ForEach(f func(i int))

ForEach calls a function for each value in the set (in increasing order).

func (FastIntSet) Intersection Uses

func (s FastIntSet) Intersection(rhs FastIntSet) FastIntSet

Intersection returns the intersection of s and rhs as a new set.

func (*FastIntSet) IntersectionWith Uses

func (s *FastIntSet) IntersectionWith(rhs FastIntSet)

IntersectionWith removes any elements not in rhs from this set.

func (FastIntSet) Intersects Uses

func (s FastIntSet) Intersects(rhs FastIntSet) bool

Intersects returns true if s has any elements in common with rhs.

func (FastIntSet) Len Uses

func (s FastIntSet) Len() int

Len returns the number of the elements in the set.

func (FastIntSet) Next Uses

func (s FastIntSet) Next(startVal int) (int, bool)

Next returns the first value in the set which is >= startVal. If there is no value, the second return value is false.

func (FastIntSet) Ordered Uses

func (s FastIntSet) Ordered() []int

Ordered returns a slice with all the integers in the set, in increasing order.

func (*FastIntSet) Remove Uses

func (s *FastIntSet) Remove(i int)

Remove removes a value from the set. No-op if the value is not in the set.

func (*FastIntSet) Shift Uses

func (s *FastIntSet) Shift(delta int) FastIntSet

Shift generates a new set which contains elements i+delta for elements i in the original set.

func (FastIntSet) String Uses

func (s FastIntSet) String() string

String returns a list representation of elements. Sequential runs of positive numbers are shown as ranges. For example, for the set {0, 1, 2, 5, 6, 10}, the output is "(0-2,5,6,10)".

func (FastIntSet) SubsetOf Uses

func (s FastIntSet) SubsetOf(rhs FastIntSet) bool

SubsetOf returns true if rhs contains all the elements in s.

func (FastIntSet) Union Uses

func (s FastIntSet) Union(rhs FastIntSet) FastIntSet

Union returns the union of s and rhs as a new set.

func (*FastIntSet) UnionWith Uses

func (s *FastIntSet) UnionWith(rhs FastIntSet)

UnionWith adds all the elements from rhs to this set.

type NoCopy Uses

type NoCopy struct{}

NoCopy may be embedded into structs which must not be copied after the first use.

See https://github.com/golang/go/issues/8005#issuecomment-190753527 for details.

func (*NoCopy) Lock Uses

func (*NoCopy) Lock()

Lock is a no-op used by -copylocks checker from `go vet`.

func (*NoCopy) Unlock Uses

func (*NoCopy) Unlock()

Unlock is a no-op used by -copylocks checker from `go vet`.

type UnionFind Uses

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

UnionFind implements the union find structure, with union by rank and path compression heuristics. Find and Union operations are effectively constant time. The data structure uses O(N) space where N is the largest element. It sizes itself as necessary; there are no allocations if Union is never called.

func (*UnionFind) Copy Uses

func (f *UnionFind) Copy() UnionFind

Copy returns a copy of the structure which can be modified independently.

func (*UnionFind) Equals Uses

func (f *UnionFind) Equals(rhs UnionFind) bool

Equals returns true if the two structures have the same sets.

func (*UnionFind) Find Uses

func (f *UnionFind) Find(n int) int

Find returns the representative of the group that n is part of; this is the smallest element of that group. Two elements a, b are in the same group iff Find(a) == Find(b).

func (*UnionFind) Len Uses

func (f *UnionFind) Len() int

Len returns the number of elements up to and including the last element that is part of a multi-element group. In other words, if X is the largest value which was passed to a Union operation, the length is X+1.

func (*UnionFind) Union Uses

func (f *UnionFind) Union(a, b int)

Union joins the groups to which a and b belong.

type UnresolvedAddr Uses

type UnresolvedAddr struct {
    NetworkField string `protobuf:"bytes,1,opt,name=network_field,json=networkField" json:"network_field"`
    AddressField string `protobuf:"bytes,2,opt,name=address_field,json=addressField" json:"address_field"`
}

/ UnresolvedAddr is an unresolved version of net.Addr.

var IsolatedTestAddr *UnresolvedAddr

IsolatedTestAddr is an address to use for tests that need extra isolation by using more addresses than 127.0.0.1 (support for this is platform-specific and only enabled on Linux). Both TestAddr and IsolatedTestAddr guarantee that the chosen port is not in use when allocated, but IsolatedTestAddr draws from a larger pool of addresses so that when tests are run in a tight loop the system is less likely to run out of available ports or give a port to one test immediately after it was closed by another.

IsolatedTestAddr should be used for tests that open and close a large number of sockets, or tests which stop a server and rely on seeing a "connection refused" error afterwards. It cannot be used with tests that operate in secure mode since our test certificates are only valid for 127.0.0.1.

func MakeUnresolvedAddr Uses

func MakeUnresolvedAddr(network, addr string) UnresolvedAddr

MakeUnresolvedAddr populates an UnresolvedAddr from a network and raw address string.

func NewUnresolvedAddr Uses

func NewUnresolvedAddr(network, addr string) *UnresolvedAddr

NewUnresolvedAddr creates a new UnresolvedAddr from a network and raw address string.

func (*UnresolvedAddr) Descriptor Uses

func (*UnresolvedAddr) Descriptor() ([]byte, []int)

func (UnresolvedAddr) IsEmpty Uses

func (a UnresolvedAddr) IsEmpty() bool

IsEmpty returns true if the address has no network or address specified.

func (*UnresolvedAddr) Marshal Uses

func (m *UnresolvedAddr) Marshal() (dAtA []byte, err error)

func (*UnresolvedAddr) MarshalTo Uses

func (m *UnresolvedAddr) MarshalTo(dAtA []byte) (int, error)

func (*UnresolvedAddr) Network Uses

func (a *UnresolvedAddr) Network() string

Network returns the address's network name.

func (*UnresolvedAddr) ProtoMessage Uses

func (*UnresolvedAddr) ProtoMessage()

func (*UnresolvedAddr) Reset Uses

func (m *UnresolvedAddr) Reset()

func (UnresolvedAddr) Resolve Uses

func (a UnresolvedAddr) Resolve() (net.Addr, error)

Resolve attempts to resolve a into a net.Addr.

func (*UnresolvedAddr) Size Uses

func (m *UnresolvedAddr) Size() (n int)

func (UnresolvedAddr) String Uses

func (a UnresolvedAddr) String() string

String returns the address's string form.

func (*UnresolvedAddr) Unmarshal Uses

func (m *UnresolvedAddr) Unmarshal(dAtA []byte) error

func (*UnresolvedAddr) XXX_DiscardUnknown Uses

func (m *UnresolvedAddr) XXX_DiscardUnknown()

func (*UnresolvedAddr) XXX_Marshal Uses

func (m *UnresolvedAddr) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*UnresolvedAddr) XXX_Merge Uses

func (dst *UnresolvedAddr) XXX_Merge(src proto.Message)

func (*UnresolvedAddr) XXX_Size Uses

func (m *UnresolvedAddr) XXX_Size() int

func (*UnresolvedAddr) XXX_Unmarshal Uses

func (m *UnresolvedAddr) XXX_Unmarshal(b []byte) error

Directories

PathSynopsis
arith
binfetcher
bitarray
bufalloc
cache
caller
causer
cloudinfo
contextutil
ctxgroupPackage ctxgroup wraps golang.org/x/sync/errgroup with a context func.
duration
encoding
encoding/csvPackage csv reads and writes comma-separated values (CSV) files.
envutil
errorutil
errorutil/unimplemented
fileutil
flagutilPackage flagutil facilitates creation of rich flag types.
fsmPackage fsm provides an interface for defining and working with finite-state machines.
growstack
grpcutil
hlcPackage hlc implements the Hybrid Logical Clock outlined in "Logical Physical Clocks and Consistent Snapshots in Globally Distributed Databases", available online at http://www.cse.buffalo.edu/tech-reports/2014-04.pdf.
httputil
humanizeutil
intervalPackage interval provides two implementations for an interval tree.
ipaddr
json
keysutil
leaktestPackage leaktest provides tools to detect leaked goroutines in tests.
limit
logPackage log implements logging.
log/logflags
metricPackage metric provides server metrics (a.k.a.
mon
netutil
prettyPackage pretty prints documents based on a target line width.
protoutil
quotapoolPackage quotapool provides an abstract implementation of a pool of resources to be distributed among concurrent clients.
randutil
retry
ring
sdnotifyPackage sdnotify implements both sides of the systemd readiness protocol.
search
shuffle
stop
stringarena
stringencoding
syncutil
syncutil/singleflightPackage singleflight provides a duplicate function call suppression mechanism.
sysutilPackage sysutil is a cross-platform compatibility layer on top of package syscall.
timeofday
timeutil
timeutil/pgdatePackage pgdate contains parsing functions and types for dates and times in a manner that is compatible with PostgreSQL.
tracing
treeprinter
uint128
uuid
version

Package util imports 20 packages (graph) and is imported by 124 packages. Updated 2019-09-20. Refresh now. Tools for package owners.