nibbles

package
v0.0.0-...-be09340 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal(nyb1 Nibbles, nyb2 Nibbles) bool

Equal returns true if the two nibble arrays are equal [0x1, 0x2, 0x3], [0x1, 0x2, 0x3] -> true [0x1, 0x2, 0x3], [0x1, 0x2, 0x4] -> false [0x1, 0x2, 0x3], [0x1] -> false [0x1, 0x2, 0x3], [0x1, 0x2, 0x3, 0x4] -> false [], [] -> true [], [0x1] -> false

func Pack

func Pack(nyb Nibbles) ([]byte, bool)

Pack the nibble array into a byte array. Return the byte array and a bool indicating if the last byte is a full byte or only the high 4 bits are part of the encoding the last four bits of a oddLength byte encoding will always be zero. Allocates a new byte slice.

[0x1, 0x2, 0x3] -> [0x12, 0x30], true [0x1, 0x2, 0x3, 0x4] -> [0x12, 0x34], false [0x1] -> [0x10], true [] -> [], false

func Serialize

func Serialize(nyb Nibbles) (data []byte)

Serialize returns a byte array that represents the Nibbles an empty nibble array is serialized as a single byte with value 0x3 as the empty nibble is considered to be full width

[0x1, 0x2, 0x3] -> [0x12, 0x30, 0x01] [0x1, 0x2, 0x3, 0x4] -> [0x12, 0x34, 0x03] [] -> [0x03]

Types

type Nibbles

type Nibbles []byte

Nibbles are 4-bit values stored in an 8-bit byte arrays

func Deserialize

func Deserialize(encoding []byte) (Nibbles, error)

Deserialize returns a nibble array from the byte array.

func SharedPrefix

func SharedPrefix(nyb1 Nibbles, nyb2 Nibbles) Nibbles

SharedPrefix returns a slice from nyb1 that contains the shared prefix between nyb1 and nyb2

func ShiftLeft

func ShiftLeft(nyb1 Nibbles, numNibbles int) Nibbles

ShiftLeft returns a slice of nyb1 that contains the Nibbles after the first numNibbles

Jump to

Keyboard shortcuts

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