bit256

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: Apache-2.0, MIT Imports: 5 Imported by: 3

Documentation

Overview

Package bit256 provides a 256-bit Kademlia key implementation.

Index

Constants

View Source
const KeyLen = 32

KeyLen is the length of a 256-bit key in bytes.

Variables

This section is empty.

Functions

This section is empty.

Types

type Key

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

Key is a 256-bit Kademlia key.

func NewKey

func NewKey(data []byte) Key

NewKey returns a 256-bit Kademlia key whose bits are set from the supplied bytes.

func NewKeyFromArray

func NewKeyFromArray(arr [KeyLen]byte) Key

NewKeyFromArray creates a Key from a 32-byte array without intermediate copying. This is more efficient than NewKey when the caller already has a [32]byte array.

func ZeroKey

func ZeroKey() Key

ZeroKey returns a 256-bit Kademlia key with all bits zeroed.

func (Key) Bit

func (k Key) Bit(i int) uint

Bit returns the value of the i'th bit of the key from most significant to least.

func (Key) BitLen

func (Key) BitLen() int

BitLen returns the length of the key in bits, which is always 256.

func (Key) CommonPrefixLength

func (k Key) CommonPrefixLength(o Key) int

CommonPrefixLength returns the number of leading bits the key shares with another key of the same type.

func (Key) Compare

func (k Key) Compare(o Key) int

Compare compares the numeric value of the key with another key of the same type.

func (Key) HexString

func (k Key) HexString() string

HexString returns a string containing the hexadecimal representation of the key.

func (Key) MarshalBinary

func (k Key) MarshalBinary() ([]byte, error)

MarshalBinary marshals the key into a byte slice. The bytes may be passed to NewKey to construct a new key with the same value.

func (Key) Xor

func (k Key) Xor(o Key) Key

Xor returns the result of the eXclusive OR operation between the key and another key of the same type.

Jump to

Keyboard shortcuts

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