util: github.com/shenwei356/util/byteutil Index | Files

package byteutil

import "github.com/shenwei356/util/byteutil"

Index

Package Files

alphabet.go byte_coder.go count.go struct.go util.go

Variables

var (
    // ErrInvalideLetter means invalid letter
    ErrInvalideLetter = fmt.Errorf("ByteCoder: invalid letter")
    // ErrInvalideCode means invalid code
    ErrInvalideCode = fmt.Errorf("ByteCoder: invalid code")
)

func Alphabet Uses

func Alphabet(s []byte) []byte

Alphabet returns the alphabet of a byte slice

func AlphabetFromCountOfByte Uses

func AlphabetFromCountOfByte(count map[byte]int) []byte

AlphabetFromCountOfByte returns the alphabet of a byte slice from count

func ByteToLower Uses

func ByteToLower(b byte) byte

ByteToLower lowers a byte

func ByteToUpper Uses

func ByteToUpper(b byte) byte

ByteToUpper upper a byte

func Bytes2Str Uses

func Bytes2Str(b []byte) string

Bytes2Str convert byte slice to string without GC. Warning: it's unsafe!!!

func CountBytes Uses

func CountBytes(seq, letters []byte) int

CountBytes counts given ASCII characters in a byte slice

func CountOfByte Uses

func CountOfByte(s []byte) map[byte]int

CountOfByte returns the count of byte for a byte slice

func MakeQuerySlice Uses

func MakeQuerySlice(letters []byte) []byte

MakeQuerySlice is used to replace map. see: http://blog.shenwei.me/map-is-not-the-fastest-in-go/

func ReverseByteSlice Uses

func ReverseByteSlice(s []byte) []byte

ReverseByteSlice reverses a byte slice

func ReverseByteSliceInplace Uses

func ReverseByteSliceInplace(s []byte)

ReverseByteSliceInplace reverses a byte slice

func Split Uses

func Split(slice []byte, letters []byte) [][]byte

Split splits a byte slice by giveen letters. It's much faster than regexp.Split

func SubSlice Uses

func SubSlice(slice []byte, start int, end int) []byte

SubSlice provides similar slice indexing as python with one exception that end could be equal to 0. So we could get the last element by SubSlice(s, -1, 0) or get the whole element by SubSlice(s, 0, 0)

func WrapByteSlice Uses

func WrapByteSlice(s []byte, width int) []byte

WrapByteSlice wraps byte slice

func WrapByteSliceInplace Uses

func WrapByteSliceInplace(s []byte, width int) []byte

WrapByteSliceInplace wraps byte slice in place. Sadly, it's too slow. Never use this!

type BufferedByteSliceWrapper Uses

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

BufferedByteSliceWrapper is used to wrap byte slice, using a buffer of bytes.Buffer to reduce GC

func NewBufferedByteSliceWrapper Uses

func NewBufferedByteSliceWrapper(size, alloc int) *BufferedByteSliceWrapper

NewBufferedByteSliceWrapper create a new BufferedByteSliceWrapper

func NewBufferedByteSliceWrapper2 Uses

func NewBufferedByteSliceWrapper2(size int, length, width int) *BufferedByteSliceWrapper

NewBufferedByteSliceWrapper2 could pre-alloc space according to length of slice and width

func (*BufferedByteSliceWrapper) Recycle Uses

func (w *BufferedByteSliceWrapper) Recycle(b *bytes.Buffer)

Recycle a buffer

func (*BufferedByteSliceWrapper) Wrap Uses

func (w *BufferedByteSliceWrapper) Wrap(s []byte, width int) ([]byte, *bytes.Buffer)

Wrap a byte slice. DO NOT FORGET call Recycle() with the returned buffer

type ByteCoder Uses

type ByteCoder struct {
    Alphabet []byte
    // contains filtered or unexported fields
}

ByteCoder is used to convert betweeen byte and int

func NewByteCoder Uses

func NewByteCoder(alphabet []byte) (*ByteCoder, error)

NewByteCoder Create a ByteCoder type

func (*ByteCoder) Decode Uses

func (coder *ByteCoder) Decode(code []int) ([]byte, error)

Decode convert []int to []byte

func (*ByteCoder) Encode Uses

func (coder *ByteCoder) Encode(s []byte) ([]int, error)

Encode converts []byte to []int

func (*ByteCoder) String Uses

func (coder *ByteCoder) String() string

type ByteCount Uses

type ByteCount struct {
    Key   byte
    Count int
}

ByteCount is a struct store count of byte

type ByteCountList Uses

type ByteCountList []ByteCount

ByteCountList is slice of ByteCount

func SortCountOfByte Uses

func SortCountOfByte(count map[byte]int, reverse bool) ByteCountList

SortCountOfByte sorts count of byte

func (ByteCountList) Len Uses

func (b ByteCountList) Len() int

func (ByteCountList) Less Uses

func (b ByteCountList) Less(i, j int) bool

func (ByteCountList) Swap Uses

func (b ByteCountList) Swap(i, j int)

type ByteSlice Uses

type ByteSlice []byte

ByteSlice is []byte

func (ByteSlice) Len Uses

func (bs ByteSlice) Len() int

func (ByteSlice) Less Uses

func (bs ByteSlice) Less(i, j int) bool

func (ByteSlice) Swap Uses

func (bs ByteSlice) Swap(i, j int)

type ReversedByteCountList Uses

type ReversedByteCountList struct {
    ByteCountList
}

ReversedByteCountList is Reversed ByteCountList

func (ReversedByteCountList) Less Uses

func (b ReversedByteCountList) Less(i, j int) bool

Less is different from the Less of ByteCountList

type SliceOfByteSlice Uses

type SliceOfByteSlice [][]byte

SliceOfByteSlice is [][]byte

func (SliceOfByteSlice) Len Uses

func (s SliceOfByteSlice) Len() int

func (SliceOfByteSlice) Less Uses

func (s SliceOfByteSlice) Less(i, j int) bool

func (SliceOfByteSlice) Swap Uses

func (s SliceOfByteSlice) Swap(i, j int)

Package byteutil imports 5 packages (graph) and is imported by 6 packages. Updated 2017-06-13. Refresh now. Tools for package owners.