structs

package
v5.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: Apache-2.0 Imports: 6 Imported by: 5

Documentation

Overview

Package structs implements helpers to generalize vectors and matrices of structs, as well as their serialization.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BinarySizer

type BinarySizer interface {
	BinarySize() int
}

type CopyNewer

type CopyNewer[V any] interface {
	CopyNew() *V
}

type Equatable

type Equatable[T any] interface {
	Equal(*T) bool
}

type Map

type Map[K constraints.Integer, T any] map[K]*T

Map is a struct storing a map of any value indexed by unsigned integers. The size of the map is limited to 2^32.

func (Map[K, T]) BinarySize

func (m Map[K, T]) BinarySize() (size int)

BinarySize returns the serialized size of the object in bytes.

func (Map[K, T]) CopyNew

func (m Map[K, T]) CopyNew() *Map[K, T]

CopyNew creates a copy of the object.

func (*Map[K, T]) MarshalBinary

func (m *Map[K, T]) MarshalBinary() (p []byte, err error)

MarshalBinary encodes the object into a binary form on a newly allocated slice of bytes.

func (*Map[K, T]) ReadFrom

func (m *Map[K, T]) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads on the object from an io.Writer. It implements the io.ReaderFrom interface.

Unless r implements the buffer.Reader interface (see lattigo/utils/buffer/reader.go), it will be wrapped into a bufio.Reader. Since this requires allocation, it is preferable to pass a buffer.Reader directly:

  • When reading multiple values from a io.Reader, it is preferable to first first wrap io.Reader in a pre-allocated bufio.Reader.
  • When reading from a var b []byte, it is preferable to pass a buffer.NewBuffer(b) as w (see lattigo/utils/buffer/buffer.go).

func (*Map[K, T]) UnmarshalBinary

func (m *Map[K, T]) UnmarshalBinary(p []byte) (err error)

UnmarshalBinary decodes a slice of bytes generated by MarshalBinary or WriteTo on the object.

func (*Map[K, T]) WriteTo

func (m *Map[K, T]) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes the object on an io.Writer. It implements the io.WriterTo interface, and will write exactly object.BinarySize() bytes on w.

Unless w implements the buffer.Writer interface (see lattigo/utils/buffer/writer.go), it will be wrapped into a bufio.Writer. Since this requires allocations, it is preferable to pass a buffer.Writer directly:

  • When writing multiple times to a io.Writer, it is preferable to first wrap the io.Writer in a pre-allocated bufio.Writer.
  • When writing to a pre-allocated var b []byte, it is preferable to pass buffer.NewBuffer(b) as w (see lattigo/utils/buffer/buffer.go).

type Matrix

type Matrix[T any] [][]T

Matrix is a struct wrapping a double slice of components of type T. T can be:

  • uint, uint64, uint32, uint16, uint8/byte, int, int64, int32, int16, int8, float64, float32.
  • Or any object that implements CopyNewer, CopyNewer, BinarySizer, io.WriterTo or io.ReaderFrom depending on the method called.

func (Matrix[T]) BinarySize

func (m Matrix[T]) BinarySize() (size int)

BinarySize returns the serialized size of the object in bytes. If T is a struct, this method requires that T implements BinarySizer.

func (Matrix[T]) CopyNew

func (m Matrix[T]) CopyNew() (mcpy Matrix[T])

CopyNew returns a deep copy of the object. If T is a struct, this method requires that T implements CopyNewer.

func (Matrix[T]) Equal

func (m Matrix[T]) Equal(other Matrix[T]) bool

Equal performs a deep equal. If T is a struct, this method requires that T implements Equatable.

func (Matrix[T]) MarshalBinary

func (m Matrix[T]) MarshalBinary() (p []byte, err error)

MarshalBinary encodes the object into a binary form on a newly allocated slice of bytes. If T is a struct, this method requires that T implements io.WriterTo.

func (*Matrix[T]) ReadFrom

func (m *Matrix[T]) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads on the object from an io.Writer. It implements the io.ReaderFrom interface.

If T is a struct, this method requires that T implements io.ReaderFrom.

Unless r implements the buffer.Reader interface (see lattigo/utils/buffer/reader.go), it will be wrapped into a bufio.Reader. Since this requires allocation, it is preferable to pass a buffer.Reader directly:

  • When reading multiple values from a io.Reader, it is preferable to first first wrap io.Reader in a pre-allocated bufio.Reader.
  • When reading from a var b []byte, it is preferable to pass a buffer.NewBuffer(b) as w (see lattigo/utils/buffer/buffer.go).

func (*Matrix[T]) UnmarshalBinary

func (m *Matrix[T]) UnmarshalBinary(p []byte) (err error)

UnmarshalBinary decodes a slice of bytes generated by MarshalBinary or WriteTo on the object. If T is a struct, this method requires that T implements io.ReaderFrom.

func (Matrix[T]) WriteTo

func (m Matrix[T]) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes the object on an io.Writer. It implements the io.WriterTo interface, and will write exactly object.BinarySize() bytes on w.

If T is a struct, this method requires that T implements io.WriterTo.

Unless w implements the buffer.Writer interface (see lattigo/utils/buffer/writer.go), it will be wrapped into a bufio.Writer. Since this requires allocations, it is preferable to pass a buffer.Writer directly:

  • When writing multiple times to a io.Writer, it is preferable to first wrap the io.Writer in a pre-allocated bufio.Writer.
  • When writing to a pre-allocated var b []byte, it is preferable to pass buffer.NewBuffer(b) as w (see lattigo/utils/buffer/buffer.go).

type Vector

type Vector[T any] []T

Vector is a struct wrapping a slice of components of type T. T can be:

  • uint, uint64, uint32, uint16, uint8/byte, int, int64, int32, int16, int8, float64, float32.
  • Or any object that implements CopyNewer, CopyNewer, io.WriterTo or io.ReaderFrom depending on the method called.

func (Vector[T]) BinarySize

func (v Vector[T]) BinarySize() (size int)

BinarySize returns the serialized size of the object in bytes. If T is a struct, this method requires that T implements BinarySizer.

func (Vector[T]) CopyNew

func (v Vector[T]) CopyNew() (vcpy Vector[T])

CopyNew returns a deep copy of the object. If T is a struct, this method requires that T implements CopyNewer.

func (Vector[T]) Equal

func (v Vector[T]) Equal(other Vector[T]) (isEqual bool)

Equal performs a deep equal. If T is a struct, this method requires that T implements Equatable.

func (Vector[T]) MarshalBinary

func (v Vector[T]) MarshalBinary() (p []byte, err error)

MarshalBinary encodes the object into a binary form on a newly allocated slice of bytes. If T is a struct, this method requires that T implements io.WriterTo.

func (*Vector[T]) ReadFrom

func (v *Vector[T]) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads on the object from an io.Writer. It implements the io.ReaderFrom interface.

If T is a struct, this method requires that T implements io.ReaderFrom.

Unless r implements the buffer.Reader interface (see lattigo/utils/buffer/reader.go), it will be wrapped into a bufio.Reader. Since this requires allocation, it is preferable to pass a buffer.Reader directly:

  • When reading multiple values from a io.Reader, it is preferable to first first wrap io.Reader in a pre-allocated bufio.Reader.
  • When reading from a var b []byte, it is preferable to pass a buffer.NewBuffer(b) as w (see lattigo/utils/buffer/buffer.go).

func (*Vector[T]) UnmarshalBinary

func (v *Vector[T]) UnmarshalBinary(p []byte) (err error)

UnmarshalBinary decodes a slice of bytes generated by MarshalBinary or WriteTo on the object. If T is a struct, this method requires that T implements io.ReaderFrom.

func (Vector[T]) WriteTo

func (v Vector[T]) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes the object on an io.Writer. It implements the io.WriterTo interface, and will write exactly object.BinarySize() bytes on w.

If T is a struct, this method requires that T implements io.WriterTo.

Unless w implements the buffer.Writer interface (see lattigo/utils/buffer/writer.go), it will be wrapped into a bufio.Writer. Since this requires allocations, it is preferable to pass a buffer.Writer directly:

  • When writing multiple times to a io.Writer, it is preferable to first wrap the io.Writer in a pre-allocated bufio.Writer.
  • When writing to a pre-allocated var b []byte, it is preferable to pass buffer.NewBuffer(b) as w (see lattigo/utils/buffer/buffer.go).

Jump to

Keyboard shortcuts

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