Documentation ¶
Overview ¶
Package structs implements helpers to generalize vectors and matrices of structs, as well as their serialization.
Index ¶
- type BinarySizer
- type CopyNewer
- type Equatable
- type Map
- func (m Map[K, T]) BinarySize() (size int)
- func (m Map[K, T]) CopyNew() *Map[K, T]
- func (m *Map[K, T]) MarshalBinary() (p []byte, err error)
- func (m *Map[K, T]) ReadFrom(r io.Reader) (n int64, err error)
- func (m *Map[K, T]) UnmarshalBinary(p []byte) (err error)
- func (m *Map[K, T]) WriteTo(w io.Writer) (n int64, err error)
- type Matrix
- func (m Matrix[T]) BinarySize() (size int)
- func (m Matrix[T]) CopyNew() (mcpy Matrix[T])
- func (m Matrix[T]) Equal(other Matrix[T]) bool
- func (m Matrix[T]) MarshalBinary() (p []byte, err error)
- func (m *Matrix[T]) ReadFrom(r io.Reader) (n int64, err error)
- func (m *Matrix[T]) UnmarshalBinary(p []byte) (err error)
- func (m Matrix[T]) WriteTo(w io.Writer) (n int64, err error)
- type Vector
- func (v Vector[T]) BinarySize() (size int)
- func (v Vector[T]) CopyNew() (vcpy Vector[T])
- func (v Vector[T]) Equal(other Vector[T]) (isEqual bool)
- func (v Vector[T]) MarshalBinary() (p []byte, err error)
- func (v *Vector[T]) ReadFrom(r io.Reader) (n int64, err error)
- func (v *Vector[T]) UnmarshalBinary(p []byte) (err error)
- func (v Vector[T]) WriteTo(w io.Writer) (n int64, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BinarySizer ¶
type BinarySizer interface {
BinarySize() int
}
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 ¶
BinarySize returns the serialized size of the object in bytes.
func (*Map[K, T]) MarshalBinary ¶
MarshalBinary encodes the object into a binary form on a newly allocated slice of bytes.
func (*Map[K, T]) ReadFrom ¶
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 ¶
UnmarshalBinary decodes a slice of bytes generated by MarshalBinary or WriteTo on the object.
func (*Map[K, T]) WriteTo ¶
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 ¶
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 ¶
CopyNew returns a deep copy of the object. If T is a struct, this method requires that T implements CopyNewer.
func (Matrix[T]) Equal ¶
Equal performs a deep equal. If T is a struct, this method requires that T implements Equatable.
func (Matrix[T]) MarshalBinary ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
CopyNew returns a deep copy of the object. If T is a struct, this method requires that T implements CopyNewer.
func (Vector[T]) Equal ¶
Equal performs a deep equal. If T is a struct, this method requires that T implements Equatable.
func (Vector[T]) MarshalBinary ¶
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 ¶
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 ¶
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 ¶
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).