byteutil

package
Version: v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2021 License: MIT Imports: 4 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func Alphabet

func Alphabet(s []byte) []byte

Alphabet returns the alphabet of a byte slice

func AlphabetFromCountOfByte

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

AlphabetFromCountOfByte returns the alphabet of a byte slice from count

func ByteToLower

func ByteToLower(b byte) byte

ByteToLower lowers a byte

func ByteToUpper

func ByteToUpper(b byte) byte

ByteToUpper upper a byte

func Bytes2Str

func Bytes2Str(b []byte) string

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

func CountBytes

func CountBytes(seq, letters []byte) int

CountBytes counts given ASCII characters in a byte slice

func CountOfByte

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

CountOfByte returns the count of byte for a byte slice

func MakeQuerySlice

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

func ReverseByteSlice(s []byte) []byte

ReverseByteSlice reverses a byte slice

func ReverseByteSliceInplace

func ReverseByteSliceInplace(s []byte)

ReverseByteSliceInplace reverses a byte slice

func Split added in v0.3.0

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

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

func SubSlice

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

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

WrapByteSlice wraps byte slice

func WrapByteSlice2 added in v0.3.1

func WrapByteSlice2(s []byte, width int, buffer *bytes.Buffer) ([]byte, *bytes.Buffer)

WrapByteSlice2 wraps byte slice, it reuses the bytes.Buffer

Types

type ByteCoder

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

ByteCoder is used to convert betweeen byte and int

func NewByteCoder

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

NewByteCoder Create a ByteCoder type

func (*ByteCoder) Decode

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

Decode convert []int to []byte

func (*ByteCoder) Encode

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

Encode converts []byte to []int

func (*ByteCoder) String

func (coder *ByteCoder) String() string

type ByteCount

type ByteCount struct {
	Key   byte
	Count int
}

ByteCount is a struct store count of byte

type ByteCountList

type ByteCountList []ByteCount

ByteCountList is slice of ByteCount

func SortCountOfByte

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

SortCountOfByte sorts count of byte

func (ByteCountList) Len

func (b ByteCountList) Len() int

func (ByteCountList) Less

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

func (ByteCountList) Swap

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

type ByteSlice

type ByteSlice []byte

ByteSlice is []byte

func (ByteSlice) Len

func (bs ByteSlice) Len() int

func (ByteSlice) Less

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

func (ByteSlice) Swap

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

type ReversedByteCountList

type ReversedByteCountList struct {
	ByteCountList
}

ReversedByteCountList is Reversed ByteCountList

func (ReversedByteCountList) Less

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

Less is different from the Less of ByteCountList

type SliceOfByteSlice

type SliceOfByteSlice [][]byte

SliceOfByteSlice is [][]byte

func (SliceOfByteSlice) Len

func (s SliceOfByteSlice) Len() int

func (SliceOfByteSlice) Less

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

func (SliceOfByteSlice) Swap

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

Jump to

Keyboard shortcuts

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