impl

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const IDLen = 4

IDLen is the size of an encoded ID struct in bytes

Variables

This section is empty.

Functions

func DatumAsByte

func DatumAsByte(datum Datum) []byte

DatumAsByte encodes a datum as a set of bytes.

func EncodeIDs

func EncodeIDs(ids ...ID) []byte

EncodeIDs encodes IDs into a new slice of bytes. Each id is encoded sequentially using [Encode].

func LabelAsByte

func LabelAsByte(label Label) []byte

LabelAsByte encodes a label as a set of bytes.

func LanguageAsByte added in v0.0.3

func LanguageAsByte(language Language) []byte

LanguageAsByte encodes a language as a set of bytes.

func MarshalID

func MarshalID(value ID) ([]byte, error)

MarshalID is like MarshalIDs, but takes takes only a single value

func MarshalIDs

func MarshalIDs(dst []byte, ids ...ID) error

MarshalIDs is like EncodeIDs, but also takes a []byte to write to

func UnmarshalID

func UnmarshalID(dest *ID, src []byte) error

UnmarshalID behaves like [dest.Decode], but produces an error when there are insufficient number of bytes in src.

func UnmarshalIDs

func UnmarshalIDs(src []byte, dests ...*ID) error

UnmarshalIDs is like UnmarshalID but decodes into every destination passed.

Types

type Datum

type Datum string

Datum is the type of data used across the implementation. It may or may not be comparable.

func ByteAsDatum

func ByteAsDatum(datum []byte) Datum

ByteAsDatum decodes a datum from a set of bytes.

type ID

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

ID uniquely identifies an object within this implementation. Not all IDs are valid, see [Valid].

Example
// create a new zero -- which isn't valid
var zero ID
fmt.Println(zero)
fmt.Println(zero.Valid())

// increment the id -- it is now valid
fmt.Println(zero.Inc())
fmt.Println(zero.Valid())

// create the value 10
var ten ID
for i := 0; i < 10; i++ {
	ten.Inc()
}

// compare it with other ids
fmt.Println(zero.Compare(ten)) // 0 < 10
fmt.Println(ten.Compare(zero)) // 10 > 0
fmt.Println(ten.Compare(ten))  // 10 == 10
Output:

ID(0)
false
ID(1)
true
-1
1
0

func DecodeID

func DecodeID(src []byte, index int) (id ID)

DecodeID works like DecodeIDs, but only decodes the id with index i

func DecodeIDs

func DecodeIDs(src []byte) []ID

DecodeIDs decodes a set of ids encoded with EncodeIDs. The behavior of slices that do not evenly divide into IDs is not defined.

func (ID) Compare

func (id ID) Compare(other ID) int

Compare compares this ID to another id, based on how many times Inc() has been called. The result will be 0 if id == other, -1 if id < other, and +1 if id > other.

func (*ID) Decode

func (id *ID) Decode(src []byte)

Decode sets this id to be the values that has been decoded from src. src must be of at least size IDLen, or a runtime panic occurs.

func (ID) Encode

func (id ID) Encode(dest []byte)

Encode encodes id using a big endian encoding into dest. dest must be of at least size IDLen.

func (*ID) GobDecode

func (id *ID) GobDecode(src []byte) error

func (ID) GobEncode

func (id ID) GobEncode() ([]byte, error)

func (*ID) Inc

func (id *ID) Inc() (next ID)

Inc increments this ID, and then returns a copy of the new value. It is the equivalent of the "++" operator.

When Inc() exceeds the maximum possible value for an ID, panics.

func (ID) Int

func (id ID) Int(value *big.Int) *big.Int

Int writes the numerical value of this id into the given big int. The big.Int is returned for convenience.

func (*ID) LoadInt

func (id *ID) LoadInt(value *big.Int) *ID

LoadInt sets the value of this id as an integer and returns it. Trying to load an integer bigger than the maximal id results in a panic.

The ID is returned for convenience.

func (*ID) Reset

func (id *ID) Reset()

Reset resets this id to an invalid value

func (ID) String

func (id ID) String() string

String formats this id as a string. It is only intended for debugging, and should not be used for production code.

func (ID) Valid

func (id ID) Valid() bool

Valid checks if this ID is valid

type Label

type Label string

Label represents the label of individual triple members. A label is a uri.

func ByteAsLabel

func ByteAsLabel(label []byte) Label

ByteAsLabel returns a label from a []byte

func (Label) AsDatum

func (label Label) AsDatum() Datum

AsDatum returns a Datum representing a label.

type Language added in v0.0.3

type Language string

Language represents a language for a triple.

func ByteAsLanguage added in v0.0.3

func ByteAsLanguage(language []byte) Language

ByteAsLanguage decodes a language from a set of bytes.

Jump to

Keyboard shortcuts

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