util

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 1 Imported by: 8

Documentation

Index

Constants

View Source
const (
	// AppNameVersion name and URL to app
	AppNameVersion = "https://github.com/diskfs/go-diskfs"
)

Variables

This section is empty.

Functions

func DumpByteSlice added in v1.4.2

func DumpByteSlice(b []byte, bytesPerRow int, showASCII, showPosHex, showPosDec bool, showOnlyBytes []int) (out string)

DumpByteSlice dump a byte slice in hex and optionally ASCII format. Optionally but position at the beginning of each row, like xxd. Optionally convert to ASCII at end of each row, like xxd. Can show positions at beginning of each row in hex, decimal or both. Can filter out all rows except those containing given positions in showOnlyBytes. If showOnlyBytes is nil, all rows are shown. If showOnlyBytes is not nil, even an empty slice, will only show those rows that contain the given positions.

func DumpByteSlicesWithDiffs added in v1.4.2

func DumpByteSlicesWithDiffs(a, b []byte, bytesPerRow int, showASCII, showPosHex, showPosDec bool) (different bool, out string)

DumpByteSlicesWithDiffs show two byte slices in hex and ASCII format, with differences highlighted.

func Uniqify added in v1.4.1

func Uniqify[T comparable](s []T) []T

Types

type Bitmap added in v1.4.1

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

Bitmap is a structure holding a bitmap

func BitmapFromBytes added in v1.4.1

func BitmapFromBytes(b []byte) *Bitmap

BitmapFromBytes create a bitmap struct from bytes

func NewBitmap added in v1.4.1

func NewBitmap(bytes int) *Bitmap

NewBitmap creates a new bitmap of size bytes; it is not in bits to force the caller to have a complete set

func (*Bitmap) Clear added in v1.4.1

func (bm *Bitmap) Clear(location int) error

Clear a specific bit location

func (*Bitmap) FirstFree added in v1.4.1

func (bm *Bitmap) FirstFree(start int) int

FirstFree returns the first free bit in the bitmap Begins at start, so if you want to find the first free bit, pass start=1. Returns -1 if none found.

func (*Bitmap) FirstSet added in v1.4.1

func (bm *Bitmap) FirstSet() int

FirstSet returns location of first set bit in the bitmap

func (*Bitmap) FreeList added in v1.4.1

func (bm *Bitmap) FreeList() []Contiguous

FreeList returns a slicelist of contiguous free locations by location. It is sorted by location. If you want to sort it by size, uses sort.Slice for example, if the bitmap is 10010010 00100000 10000010, it will return

	 1: 2, // 2 free bits at position 1
	 4: 2, // 2 free bits at position 4
	 8: 3, // 3 free bits at position 8
	11: 5  // 5 free bits at position 11
    17: 5  // 5 free bits at position 17
	23: 1, // 1 free bit at position 23

if you want it in reverse order, just reverse the slice.

func (*Bitmap) FromBytes added in v1.4.1

func (bm *Bitmap) FromBytes(b []byte)

FromBytes overwrite the existing map with the contents of the bytes. It is the equivalent of BitmapFromBytes, but uses an existing Bitmap.

func (*Bitmap) IsSet added in v1.4.1

func (bm *Bitmap) IsSet(location int) (bool, error)

IsSet check if a specific bit location is set

func (*Bitmap) Set added in v1.4.1

func (bm *Bitmap) Set(location int) error

Set a specific bit location

func (*Bitmap) ToBytes added in v1.4.1

func (bm *Bitmap) ToBytes() []byte

ToBytes returns raw bytes underlying the bitmap

type Contiguous added in v1.4.1

type Contiguous struct {
	Position int
	Count    int
}

Contiguous a position and count of contiguous bits, either free or set

Jump to

Keyboard shortcuts

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