util

package
v1.0.0-preview Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2017 License: Apache-2.0 Imports: 11 Imported by: 4,465

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDirIfMissing

func CreateDirIfMissing(dirPath string) (bool, error)

CreateDirIfMissing creates a dir for dirPath if not already exists. If the dir is empty it returns true

func DecodeOrderPreservingVarUint64

func DecodeOrderPreservingVarUint64(bytes []byte) (uint64, int)

DecodeOrderPreservingVarUint64 decodes the number from the bytes obtained from method 'EncodeOrderPreservingVarUint64'. Also, returns the number of bytes that are consumed in the process

func DirEmpty

func DirEmpty(dirPath string) (bool, error)

DirEmpty returns true if the dir at dirPath is empty

func EncodeOrderPreservingVarUint64

func EncodeOrderPreservingVarUint64(number uint64) []byte

EncodeOrderPreservingVarUint64 returns a byte-representation for a uint64 number such that all zero-bits starting bytes are trimmed in order to reduce the length of the array For preserving the order in a default bytes-comparison, first byte contains the number of remaining bytes. The presence of first byte also allows to use the returned bytes as part of other larger byte array such as a composite-key representation in db

func FileExists

func FileExists(filePath string) (bool, int64, error)

FileExists checks whether the given file exists. If the file exists, this method also returns the size of the file.

func GetSortedKeys

func GetSortedKeys(m interface{}) []string

GetSortedKeys returns the keys of the map in a sorted order. This function assumes that the keys are string

func ListSubdirs

func ListSubdirs(dirPath string) ([]string, error)

ListSubdirs returns the subdirectories

Types

type Buffer

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

Buffer provides a wrapper on top of proto.Buffer. The purpose of this wrapper is to get to know the current position in the []byte

func NewBuffer

func NewBuffer(b []byte) *Buffer

NewBuffer constructs a new instance of Buffer

func (*Buffer) DecodeRawBytes

func (b *Buffer) DecodeRawBytes(alloc bool) ([]byte, error)

DecodeRawBytes wraps the actual method and updates the position

func (*Buffer) DecodeVarint

func (b *Buffer) DecodeVarint() (uint64, error)

DecodeVarint wraps the actual method and updates the position

func (*Buffer) GetBytesConsumed

func (b *Buffer) GetBytesConsumed() int

GetBytesConsumed returns the offset of the current position in the underlying []byte

type FilterBitArray

type FilterBitArray []byte

FilterBitArray is an array of bits based on byte unit, so 8 bits at each index. The array automatically increases if the set index is larger than the current capacity. The bit index starts at 0.

func NewFilterBitArray

func NewFilterBitArray(size uint) FilterBitArray

NewFilterBitArray creates an array with the specified bit-size. This is an optimization to make array once for the expected capacity rather than using Set function to auto-increase the array.

func NewFilterBitArrayFromBytes

func NewFilterBitArrayFromBytes(bytes []byte) FilterBitArray

NewFilterBitArrayFromBytes reconstructs an array from given byte array.

func (*FilterBitArray) Capacity

func (ba *FilterBitArray) Capacity() uint

Capacity returns the number of bits in the FilterBitArray.

func (*FilterBitArray) FromBytes

func (ba *FilterBitArray) FromBytes(bytes []byte)

FromBytes accepts a byte array.

func (*FilterBitArray) IsSet

func (ba *FilterBitArray) IsSet(i uint) bool

IsSet returns true if the specified bit-index is 1; false otherwise.

func (*FilterBitArray) Set

func (ba *FilterBitArray) Set(i uint)

Set assigns 1 to the specified bit-index, which is starting from 0. Set automatically increases the array to accommodate the bit-index.

func (*FilterBitArray) SetRange

func (ba *FilterBitArray) SetRange(begin uint, end uint)

SetRange assigns 1 to the bit-indexes specified by range [begin, end] Set automatically increases the array to accommodate the bit-index.

func (*FilterBitArray) ToBytes

func (ba *FilterBitArray) ToBytes() []byte

ToBytes returns the byte array for storage.

func (*FilterBitArray) Unset

func (ba *FilterBitArray) Unset(i uint)

Unset assigns 0 the specified bit-index. If bit-index is larger than capacity, do nothing.

func (*FilterBitArray) UnsetRange

func (ba *FilterBitArray) UnsetRange(begin uint, end uint)

UnsetRange assigns 0 to all bits in range [begin, end]. If bit-index is larger than capacity, do nothing.

func (*FilterBitArray) ValueAt

func (ba *FilterBitArray) ValueAt(i uint) byte

ValueAt returns the value at the specified bit-index. If bit-index is out of range, return 0. Note that the returned value is in byte, so it may be a power of 2 if not 0.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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