Documentation ¶
Overview ¶
Errors and random helper functions.
Index ¶
- func Abs(a int) int
- func AppendCopy(nxt int, arr []int) []int
- func AppendUvarint(v uint64, byt []byte) (int, []byte)
- func CheckOverflow(items ...uint64) bool
- func CheckUnique(items ...Any) bool
- func CheckUniqueInt(items ...Any) bool
- func CheckUniqueSorted(equalFunc func(a, b Any) bool, items ...Any) bool
- func ContainsInt(l sort.IntSlice, v int) bool
- func ContainsSlice(s1 sort.IntSlice, s2 sort.IntSlice) bool
- func ConvertInt64(n interface{}) int64
- func CopyBuf(buf []byte) []byte
- func CreateIntSlice(n int) (ret []int)
- func DecodeHelper(reader io.Reader) (n int, buff []byte, err error)
- func EncodeHelper(arr []byte, writer io.Writer) (n int, err error)
- func EncodeUint16(v uint16, writer io.Writer) (int, error)
- func EncodeUint32(v uint32, writer io.Writer) (int, error)
- func EncodeUint64(v uint64, writer io.Writer) (int, error)
- func EncodeUvarint(v uint64, writer io.Writer) (int, error)
- func Exp(x, y int) (ret int)
- func GenList(count int) []int
- func GenListUint64(start, end int) []uint64
- func GenRandPerm(count int, max int, rnd *rand.Rand) []int
- func GetBitAt(idx uint, v uint64) types.BinVal
- func GetDuplicates(items sort.IntSlice) (nonDuplicates sort.IntSlice, duplicates sort.IntSlice)
- func GetNonDuplicateCount(s1 sort.IntSlice, s2 sort.IntSlice) int
- func GetOneThirdBottom(n int) int
- func GetUniqueCount(s1 sort.IntSlice) int
- func IncreaseCap(arr []byte, newCap int) []byte
- func InsertIfNotFound(arr sort.IntSlice, toInsert int, startIndex int) (sort.IntSlice, int, bool)
- func InsertInSortedSlice(arr sort.IntSlice, toInsert int, startIndex int) (sort.IntSlice, int)
- func JoinBytes(items ...[]byte) []byte
- func Max(a, b int) int
- func Max64(a, b int64) int64
- func MaxConsensusIndex(l ...types.ConsensusInt) types.ConsensusInt
- func MaxConsensusRound(l ...types.ConsensusRound) types.ConsensusRound
- func MaxDuration(l ...time.Duration) time.Duration
- func MaxInt(l1 int, l ...int) int
- func MaxIntSlice(l ...int) int
- func MaxU64(a, b uint64) uint64
- func MaxU64Slice(l ...uint64) (ret uint64)
- func MaxUint32(l []uint32) uint32
- func Min(a, b int) int
- func MinConsensusIndex(l ...types.ConsensusInt) types.ConsensusInt
- func MinConsensusRound(l ...types.ConsensusRound) types.ConsensusRound
- func MinDuration(l ...time.Duration) time.Duration
- func MinIntSlice(l ...int) (ret int)
- func MinU64Slice(l ...uint64) (ret uint64)
- func MinUint32(l ...uint32) uint32
- func NonZeroCount(v [][][]byte) (count int)
- func PanicNonNil(err error)
- func ReadBytes(n int, reader io.Reader) (read int, buff []byte, err error)
- func ReadTCPIPFile(filePath string, includePort bool) ([]string, error)
- func ReadUint16(reader io.Reader) (v uint16, n int, err error)
- func ReadUint32(reader io.Reader) (v uint32, n int, err error)
- func ReadUint64(reader io.Reader) (v uint64, n int, err error)
- func ReadUvarint(r io.Reader) (uint64, int, error)
- func ReadUvarintByteReader(r io.ByteReader) (uint64, int, error)
- func RemoveDuplicatesSortCountString(input []string) (ret []string)
- func RemoveFromSlice(n int, sli []int) (bool, []int)
- func RemoveFromSliceString(n string, sli []string) (bool, []string)
- func SortSorted(s1 sort.IntSlice, s2 sort.IntSlice) sort.IntSlice
- func SortSortedList(items ...sort.IntSlice) sort.IntSlice
- func SortSortedNoDuplicates(s1 sort.IntSlice, s2 sort.IntSlice) sort.IntSlice
- func SplitBytes(buff []byte, maxPieces int) (ret [][]byte)
- func SubOrOne(a, b uint64) uint64
- func SubOrZero(a, b uint64) uint64
- func SubSortedSlice(s1 sort.IntSlice, s2 sort.IntSlice) sort.IntSlice
- func SumConsensusRound(l []types.ConsensusRound) types.ConsensusRound
- func SumDuration(l []time.Duration) time.Duration
- func SumUint32(l []uint32) uint32
- func SumUint64(l ...uint64) uint64
- func TrimZeros(buff []byte, minLen int) []byte
- func TrueCount(arr []bool) (ret int)
- func Uint64ToBytes(v uint64) []byte
- func XORbytes(a, b []byte) ([]byte, error)
- type Any
- type MovingAvg
- type SeededCTRSource
- type SortedChildren
- type StringNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendCopy ¶
func CheckOverflow ¶
CheckOverflow returns true if the sum of items would overflow.
func CheckUnique ¶
CheckUnique returns true if all items input are unique. Compares items using == (so won't follow pointers, etc)
func CheckUniqueInt ¶
func CheckUniqueSorted ¶
//////////////////////////////////////////////////// Check unique items /////////////////////////////////////////////////// CheckUniqueSorted takes as input a sorted list of items, and a function that returns true if 2 items are equal. It returns true if all items are unique.
func ContainsSlice ¶
ContainsSlice returns true if s2 is contained in s1
func ConvertInt64 ¶
func ConvertInt64(n interface{}) int64
func CreateIntSlice ¶
CreateIntSlice returns a slice of length n, where ret[i] == i.
func EncodeHelper ¶
EncodeHelper writes the size of the bytes followed by the bytes to the writer.
func GenList ¶
GenList creates a list of integers upto count, i.e. if count = 3 it returns []int{0,1,2}.
func GenListUint64 ¶
GenListUint64 is the same as GenList, except creates a list of uint64s.
func GetDuplicates ¶
GetDuplicates takes as input a sorted slice of integers, then returns a sorted slice containing all the values, and a sorted slice containing any remaining duplicates. More specifically: "sort(nonDuplicates + duplicates) == items".
func GetNonDuplicateCount ¶
GetNonDuplicateCount returns "| set(s1 + s2) |".
func GetUniqueCount ¶
GetUnique count returns the number of unique items in s1
func IncreaseCap ¶
IncreaseCap increases the capacitiy of the array if needed
func InsertIfNotFound ¶
InsertIfNotFound inserts toInsert into arr, only if it does not already exist in arr after startIndex. arr must be sorted.
func InsertInSortedSlice ¶
InsertInSortedSlice inserts toInsert into arr returning the sorted arr and the index where toInsert was inserted, startIndex is where to start searching for the insert location, (i.e arr[startIndex] must be less than toInsert). It allows duplcates.
func MaxConsensusIndex ¶
func MaxConsensusIndex(l ...types.ConsensusInt) types.ConsensusInt
MinConsensusIndex returns the minimum input types.ConsensusInt.
func MaxConsensusRound ¶
func MaxConsensusRound(l ...types.ConsensusRound) types.ConsensusRound
MaxConsensusRound returns the maximum types.ConsensusRound in l.
func MaxDuration ¶
MaxDuration returns the maximum duration in l.
func MaxIntSlice ¶
func MaxU64Slice ¶
MaxU64Slice returns the max value in the slice.
func MinConsensusIndex ¶
func MinConsensusIndex(l ...types.ConsensusInt) types.ConsensusInt
MinConsensusIndex returns the minimum input types.ConsensusInt.
func MinConsensusRound ¶
func MinConsensusRound(l ...types.ConsensusRound) types.ConsensusRound
MinConsensusRound returns the minimum input types.ConsensusRound .
func MinDuration ¶
MinDuration returns the minimum duration in l.
func MinIntSlice ¶
MinIntSlice returns the max value in the slice.
func MinU64Slice ¶
MinU64Slice returns the max value in the slice.
func NonZeroCount ¶
func PanicNonNil ¶
func PanicNonNil(err error)
func ReadBytes ¶
ReadBytes reads the given number of bytes into a new slice. An error is returned if less than n bytes are read.
func ReadTCPIPFile ¶
ReadTCPIPFile reads a file with one ip address per line, checks if the IPs are valid, and returns them as a slice of strings. If includePort is true, then the port is not removed when the address is read.
func ReadUvarint ¶
ReadUvarint reads an encoded unsigned integer from r and returns it as a uint64. This is modified from the golang library to use io.Reader instead of byte reader
func ReadUvarintByteReader ¶
func ReadUvarintByteReader(r io.ByteReader) (uint64, int, error)
func RemoveDuplicatesSortCountString ¶
RemoveDuplicatesString returns a new slice of strings with duplicates removed The results is sorted by the ones with the most duplicates.
func RemoveFromSlice ¶
RemoveFromSlice removes n from sli and returns true and the new slice. If n is not in the slice it returns false.
func RemoveFromSliceString ¶
RemoveFromSlice removes n from sli and returns true and the new slice. If n is not in the slice it returns false.
func SortSorted ¶
SortSorted takes two sorted lists as input and outputs the two lists sorted in a single list.
func SortSortedList ¶
SortSorted list takes as input several sorted lists and returns a sorted list containing all items.
func SortSortedNoDuplicates ¶
SortSortedNoDuplicates is the same as SortSorted, but returns a list with no duplicates.
func SplitBytes ¶
func SubSortedSlice ¶
SubSortedSlice subtracts s2 from s1
func SumConsensusRound ¶
func SumConsensusRound(l []types.ConsensusRound) types.ConsensusRound
SumConsensusRound sums l.
func SumDuration ¶
SumDuration sums the durations in l.
func Uint64ToBytes ¶
Uint64ToBytes uses uvarint to encode the uint64 to bytes.
Types ¶
type MovingAvg ¶
type MovingAvg struct {
// contains filtered or unexported fields
}
MovingAvg tracks a cumlitive moving average.
func NewMovingAvg ¶
NewMovingAvg creates a object for tracking the cumlitive moving average with the given window size, initVal means the previous windowSize inputs had that initVal TODO this should keep the number of messages over a certain time, not a fixed number
func (*MovingAvg) AddElement ¶
AddElement adds a new element to the moving average, and returns the new moving average
type SeededCTRSource ¶
type SeededCTRSource struct {
// contains filtered or unexported fields
}
SeededCTRSource is intended to be used as a source for the golang math.Rand objects. It uses an key and a nonce as the seed for the randoms using golang's AES CTR stream.
func NewSeededCTRSource ¶
func NewSeededCTRSource(key [32]byte, nonce [16]byte) (*SeededCTRSource, error)
NewSeededCTRSource create a need random source using key and nonce as the seed.
func (*SeededCTRSource) Int63 ¶
func (src *SeededCTRSource) Int63() int64
Int63 returns a non-negative pseudo-random 63-bit integer as an int64.
func (*SeededCTRSource) Seed ¶
func (src *SeededCTRSource) Seed(seed int64)
Seed is not supported, the source instead should be created with NewSeededCTRSource.
func (*SeededCTRSource) Uint64 ¶
func (src *SeededCTRSource) Uint64() uint64
Uint64 returns the next pseudo-random uint64.
type SortedChildren ¶
type SortedChildren []*StringNode
func (SortedChildren) Len ¶
func (sc SortedChildren) Len() int
func (SortedChildren) Less ¶
func (sc SortedChildren) Less(i, j int) bool
func (SortedChildren) Swap ¶
func (sc SortedChildren) Swap(i, j int)
type StringNode ¶
type StringNode struct { Value string Children SortedChildren Other interface{} }