widgets

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2025 License: MIT Imports: 4 Imported by: 0

README

widgets

A type safe way to augment standard types with more information for common operations such as equality and hashing.

What is a Widget?

A widget can be though of as a stateless value that implements methods that perform operations on a given type. Why stateless? Because arbitrary types need to be supported. This includes any builtin types and builtin types cannot be modified with additional methods. For example, you cannot add a method to the builtin int type. The below code will not compile.

func (i int) Eq(other int) bool { ... }

Since the type itself cannot be modified, an external stateless value will be used in concert with a given value to provide the necessary missing information. This external value will need to be stateless to avoid any confusion between it and the actual value. However, it will still need to act on values of the type it is working with. So, then why not use generics to define a sub type that the original type can be casted to and from freely? Because go forbids creating non-instantiated generic types. The code shown below tries to do this. If you try to compile this code it will fail.

type Widget[T any] T

So, that brings us back to having an external type to augment another type to "add methods" to it.

The next question might be "why on earth would you do this?" This is a valid, question but can be simply answered by looking at the containers package. Each container needs to know specific information about a given arbitrary type as well as how to perform basic operations with that type. This is not just for the containers package either, it is easy to image other packages that could make use of this idea (algorithms, generic code in general, ...).

Available Widgets

There are four kinds of widgets, each with an associated interface:

Widget Associated Interface
Base https://github.com/barbell-math/util/blob/d4b081dad4b35c30ca0bb67e6ed603ca04059a3b/src/widgets/Common.go#L8-L21
PartialOrder https://github.com/barbell-math/util/blob/d4b081dad4b35c30ca0bb67e6ed603ca04059a3b/src/widgets/Common.go#L23-L31
Arith https://github.com/barbell-math/util/blob/d4b081dad4b35c30ca0bb67e6ed603ca04059a3b/src/widgets/Common.go#L33-L61
PartialOrderArith https://github.com/barbell-math/util/blob/d4b081dad4b35c30ca0bb67e6ed603ca04059a3b/src/widgets/Common.go#L63-L70

The widgets interfaces are built off of each other, meaning that they can be down casted as needed.

Widget Interface Allowed Down Cast Targets
BaseInterface
PartialOrderInterface BaseInterface
ArithInterface BaseInterface
PartialOrderArithInterface BaseInterface, PartialOrderInterface, ArithInterface

Besides these widget types, all builtin types have an analogous widget defined within this package. All of these widgets will follow the Builtin<type> naming format.

Example Usage

The previously established widget types have been defined to be used like the following examples:

  1. Base widget example

https://github.com/barbell-math/util/blob/d4b081dad4b35c30ca0bb67e6ed603ca04059a3b/src/widgets/Examples_test.go#L8-L18

  1. Partial order widget example

https://github.com/barbell-math/util/blob/d4b081dad4b35c30ca0bb67e6ed603ca04059a3b/src/widgets/Examples_test.go#L22-L27

  1. Arith widget example

https://github.com/barbell-math/util/blob/d4b081dad4b35c30ca0bb67e6ed603ca04059a3b/src/widgets/Examples_test.go#L31-L48

Widgets on Custom Types

Custom user defined types do not suffer from the problem of not being able to add methods. As such, a custom type may choose to implement the widget interface on itself. In this case, the type and the stateless type collapse into one. However, they must still be considered to be separate. The method receiver must not be used in any implementation where a type implements the widget interface on itself. Doing so would violate the stateless nature that predicated the design of widgets. All values that are needed to perform the requested operations will be passed as arguments to the required methods.

The example below shows a custom type implementing the partial order widget interface on itself. Note how the method receivers are not used and the _ character is used as the method receiver. This indicates that it should not be used and is a recommended pattern to follow.

https://github.com/barbell-math/util/blob/d4b081dad4b35c30ca0bb67e6ed603ca04059a3b/src/widgets/CustomWidget_test.go#L10-L26 A custom type implementing the partial order widget on itself.

The example below demonstrates how to use the widget associated with this custom type. This example also demonstrates how the custom type can be used with both the base and partial order widgets. This is due to the down casting rules that were discussed in the previous section. Given this behavior, it is recommended that every custom type implements the largest allowable widget interface which allows it to be used in the greatest number of scenarios.

https://github.com/barbell-math/util/blob/d4b081dad4b35c30ca0bb67e6ed603ca04059a3b/src/widgets/CustomWidget_test.go#L50-L63

What About Pointers??

Pointers are a common thing to use. As such, there needs to be a way for a widget to perform it's operations on the underlying value rather than the pointer value. To do this the pointer widgets can be used as wrappers to peel back the pointer and return the result of the required operation on the underlying value. There are pointer widgets for each of the widget types.

  1. BasePntr
  2. PartialOrderPntr
  3. ArithPntr
  4. PartialOrderArithPntr

The example below shows how to use these pointer widgets.

https://github.com/barbell-math/util/blob/d4b081dad4b35c30ca0bb67e6ed603ca04059a3b/src/widgets/CustomWidget_test.go#L50-L63

Further Reading:

  1. containers

Documentation

Overview

This package defines several widget types that allow logic for certian common operations to be passed arround as state.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// The random seed will be different every time the program runs
	// meaning that between runs the hash values will not be consistent.
	// This was done for security purposes.
	RANDOM_SEED_STRING maphash.Seed = maphash.MakeSeed()
)

Functions

This section is empty.

Types

type Arith

type Arith[T any, I ArithInterface[T]] struct {
	Base[T, I]
}

A concrete arithmitic widget. Internally, this struct will create an interface value of type ArithInterface that points to nil data. All methods on widget are then very thin pass through functions that call the needed methods on the interface value with the supplied values.

Example
v1, v2 := 0, -1
res := 0
w := Arith[int, BuiltinInt]{}
fmt.Println("ZeroVal:", w.ZeroVal())
fmt.Println("UnitVal:", w.UnitVal())
w.Neg(&v2)
fmt.Println("Neg:", v2)
w.Add(&res, &v1, &v2)
fmt.Println("Add:", res)
w.Mul(&res, &v1, &v2)
fmt.Println("Mul:", res)
Output:

ZeroVal: 0
UnitVal: 1
Neg: 1
Add: 1
Mul: 0

func (*Arith[T, I]) Add

func (w *Arith[T, I]) Add(res *T, l *T, r *T)

Adds the supplied values using the function from the interface that was supplied as a generic type.

func (*Arith[T, I]) Div

func (w *Arith[T, I]) Div(res *T, l *T, r *T)

Divides the supplied values using the function from the interface that was supplied as a generic type.

func (*Arith[T, I]) Mul

func (w *Arith[T, I]) Mul(res *T, l *T, r *T)

Multiplies the supplied values using the function from the interface that was supplied as a generic type.

func (*Arith[T, I]) Neg

func (w *Arith[T, I]) Neg(v *T)

Negates the supplied value using the function from the interface that was supplied as a generic type.

func (*Arith[T, I]) Neq

func (w *Arith[T, I]) Neq(l *T, r *T) bool

Compares the left (l) and right (r) values and returns true is l!=r using the Eq function from the interface that was supplied as a generic type.

func (*Arith[T, I]) Sub

func (w *Arith[T, I]) Sub(res *T, l *T, r *T)

Subtracts the supplied values using the function from the interface that was supplied as a generic type.

func (*Arith[T, I]) UnitVal

func (w *Arith[T, I]) UnitVal() T

Returns the "1" value for the given widget type using the function from the interface that was supplied as a generic type.

func (*Arith[T, I]) ZeroVal

func (w *Arith[T, I]) ZeroVal() T

Returns the "zero" value for the given widget type using the function from the interface that was supplied as a generic type.

type ArithInterface

type ArithInterface[T any] interface {
	BaseInterface[T]
	// Returns the value that represents "zero" for the underlying type.
	ZeroVal() T
	// Returns the value that represent "1" for the underlying type.
	UnitVal() T
	// Negates the value that is supplied to it.
	Neg(v *T)
	// Adds l and r and places the results in res. No uniqueness guarantees
	// are placed on res, l, and r. They may all be the same value. The
	// implementation of this interface needs to recognize this.
	Add(res *T, l *T, r *T)
	// Subtracts l and r and places the results in res. No uniqueness
	// guarantees are placed on res, l, and r. They may all be the same
	// value. The implementation of this interface needs to recognize this.
	Sub(res *T, l *T, r *T)
	// Multiplies l and r and places the results in res. No uniqueness
	// guarantees are placed on res, l, and r. They may all be the same
	// value. The implementation of this interface needs to recognize this.
	Mul(res *T, l *T, r *T)
	// Divides l and r and places the results in res. No uniqueness
	// guarantees are placed on res, l, and r. They may all be the same
	// value. The implementation of this interface needs to recognize this.
	Div(res *T, l *T, r *T)
}

The interface that defines what it means to be a widget that can do basic arithmetic. Implementations of this interface are expected to hold no state that pertains to the widget functions as the methods will not be called in any predetermined order.

type ArithPntr

type ArithPntr[T any, I ArithInterface[T]] struct {
	// contains filtered or unexported fields
}

A pass through widget that represents a pointer to an underlying type that is an arith widget. This is useful for when you need a widget for a pointer. Consider a *int that you need an arith widget for. The ArithPntr struct would be used like this:

ArithPntr[int, widgets.BuiltinInt]

func (ArithPntr[T, I]) Add

func (p ArithPntr[T, I]) Add(res **T, l **T, r **T)

func (ArithPntr[T, I]) Div

func (p ArithPntr[T, I]) Div(res **T, l **T, r **T)

func (ArithPntr[T, I]) Eq

func (p ArithPntr[T, I]) Eq(l **T, r **T) bool

func (ArithPntr[T, I]) Hash

func (p ArithPntr[T, I]) Hash(other **T) hash.Hash

func (ArithPntr[T, I]) Mul

func (p ArithPntr[T, I]) Mul(res **T, l **T, r **T)

func (ArithPntr[T, I]) Neg

func (p ArithPntr[T, I]) Neg(v **T)

func (ArithPntr[T, I]) Sub

func (p ArithPntr[T, I]) Sub(res **T, l **T, r **T)

func (ArithPntr[T, I]) UnitVal

func (p ArithPntr[T, I]) UnitVal() *T

func (ArithPntr[T, I]) Zero

func (p ArithPntr[T, I]) Zero(other **T)

func (ArithPntr[T, I]) ZeroVal

func (p ArithPntr[T, I]) ZeroVal() *T

type Base

type Base[T any, I BaseInterface[T]] struct {
	// contains filtered or unexported fields
}

A concrete base widget. Internally, this struct will create an interface value of type BaseInterface that points to nil data. All methods on widget are then very thin pass through functions that call the needed methods on the interface value with the supplied values.

Example
v1, v2 := 0, 1
w := Base[int, BuiltinInt]{}
fmt.Println("Equality:", w.Eq(&v1, &v2))
fmt.Println("Hash:", w.Hash(&v2))
w.Zero(&v2)
fmt.Println("Zeroed:", v2)
Output:

Equality: false
Hash: 1
Zeroed: 0

func (*Base[T, I]) Eq

func (w *Base[T, I]) Eq(l *T, r *T) bool

Compares the left (l) and right (r) values and returns true is l==r using the Eq function from the interface that was supplied as a generic type.

func (*Base[T, I]) Hash

func (w *Base[T, I]) Hash(v *T) hash.Hash

Generates a hash for the given value using the hash function from the interface that was supplied as a generic type.

func (*Base[T, I]) Neq

func (w *Base[T, I]) Neq(l *T, r *T) bool

Compares the left (l) and right (r) values and returns true is l!=r using the Eq function from the interface that was supplied as a generic type.

func (*Base[T, I]) Zero

func (w *Base[T, I]) Zero(v *T)

Zeros the supplied value using the logic defined by the interface that was supplied as a generic type.

type BaseInterface

type BaseInterface[T any] interface {
	// A function that should return true if the current value equals other.
	Eq(l *T, r *T) bool
	// Returns a hash value that represent the currently wrapped value.
	Hash(v *T) hash.Hash
	// Zero's the supplied value. Equivalent to a destructor except Go does
	// not have manual memory management so this is mainly just to prevent
	// things like dangling pointers.
	Zero(v *T)
}

The interface that defines what it means to be a widget. Implementations of this interface are expected to hold no state that pertains to the widget functions as the methods shown below will not be called in any predetermined order.

type BasePntr

type BasePntr[T any, I BaseInterface[T]] struct {
	// contains filtered or unexported fields
}

A pass through widget that represents a pointer to an underlying type that is a base widget. This is useful for when you need a widget for a pointer. Consider a *int that you need a base widget for. The BasePntr struct would be used like this:

BasePntr[int, widgets.BuiltinInt]

func (BasePntr[T, I]) Eq

func (p BasePntr[T, I]) Eq(l **T, r **T) bool

func (BasePntr[T, I]) Hash

func (p BasePntr[T, I]) Hash(other **T) hash.Hash

func (BasePntr[T, I]) Zero

func (p BasePntr[T, I]) Zero(other **T)

type BuiltinBool

type BuiltinBool struct{}

A widget to represent the built-in bool type

func (BuiltinBool) Eq

func (_ BuiltinBool) Eq(l *bool, r *bool) bool

Returns true if both bool's are equal. Uses the standard == operator internally.

func (BuiltinBool) Hash

func (_ BuiltinBool) Hash(v *bool) hash.Hash

Provides a hash function for the value that it is wrapping.

func (BuiltinBool) Zero

func (_ BuiltinBool) Zero(other *bool)

Zeros the supplied value.

type BuiltinByte

type BuiltinByte struct{}

A widget to represent the built-in byte type

func (BuiltinByte) Add

func (_ BuiltinByte) Add(res *byte, l *byte, r *byte)

Adds l to r, placing the result in the value that res points to.

func (BuiltinByte) Div

func (_ BuiltinByte) Div(res *byte, l *byte, r *byte)

Divides l to r, placing the result in the value that res points to.

func (BuiltinByte) Eq

func (_ BuiltinByte) Eq(l *byte, r *byte) bool

Returns true if both byte's are equal. Uses the standard == operator internally.

func (BuiltinByte) Hash

func (_ BuiltinByte) Hash(v *byte) hash.Hash

Provides a hash function for the value that it is wrapping.

func (BuiltinByte) Lt

func (_ BuiltinByte) Lt(l *byte, r *byte) bool

Returns true if l<r. Uses the standard < operator internally.

func (BuiltinByte) Mul

func (_ BuiltinByte) Mul(res *byte, l *byte, r *byte)

Multiplies l to r, placing the result in the value that res points to.

func (BuiltinByte) Neg

func (_ BuiltinByte) Neg(v *byte)

Negates v, updating the value that v points to.

func (BuiltinByte) Sub

func (_ BuiltinByte) Sub(res *byte, l *byte, r *byte)

Subtracts l to r, placing the result in the value that res points to.

func (BuiltinByte) UnitVal

func (_ BuiltinByte) UnitVal() byte

Returns the unit value for the byte type.

func (BuiltinByte) Zero

func (_ BuiltinByte) Zero(other *byte)

Zeros the supplied value.

func (BuiltinByte) ZeroVal

func (_ BuiltinByte) ZeroVal() byte

Returns the zero value for the byte type.

type BuiltinComplex128

type BuiltinComplex128 struct{}

A widget to represent the built-in complex128 type

func (BuiltinComplex128) Add

func (_ BuiltinComplex128) Add(res *complex128, l *complex128, r *complex128)

Adds l to r, placing the result in the value that res points to.

func (BuiltinComplex128) Div

func (_ BuiltinComplex128) Div(res *complex128, l *complex128, r *complex128)

Divides l to r, placing the result in the value that res points to.

func (BuiltinComplex128) Eq

Returns true if both complex128's are equal. Uses the standard == operator internally.

func (BuiltinComplex128) Hash

Provides a hash function for the value that it is wrapping.

func (BuiltinComplex128) Mul

func (_ BuiltinComplex128) Mul(res *complex128, l *complex128, r *complex128)

Multiplies l to r, placing the result in the value that res points to.

func (BuiltinComplex128) Neg

func (_ BuiltinComplex128) Neg(v *complex128)

Negates v, updating the value that v points to.

func (BuiltinComplex128) Sub

func (_ BuiltinComplex128) Sub(res *complex128, l *complex128, r *complex128)

Subtracts l to r, placing the result in the value that res points to.

func (BuiltinComplex128) UnitVal

func (_ BuiltinComplex128) UnitVal() complex128

Returns the unit value for the complex128 type.

func (BuiltinComplex128) Zero

func (_ BuiltinComplex128) Zero(other *complex128)

Zeros the supplied value.

func (BuiltinComplex128) ZeroVal

func (_ BuiltinComplex128) ZeroVal() complex128

Returns the zero value for the complex128 type.

type BuiltinComplex64

type BuiltinComplex64 struct{}

A widget to represent the built-in complex64 type

func (BuiltinComplex64) Add

func (_ BuiltinComplex64) Add(res *complex64, l *complex64, r *complex64)

Adds l to r, placing the result in the value that res points to.

func (BuiltinComplex64) Div

func (_ BuiltinComplex64) Div(res *complex64, l *complex64, r *complex64)

Divides l to r, placing the result in the value that res points to.

func (BuiltinComplex64) Eq

Returns true if both complex64's are equal. Uses the standard == operator internally.

func (BuiltinComplex64) Hash

func (_ BuiltinComplex64) Hash(v *complex64) hash.Hash

Provides a hash function for the value that it is wrapping.

func (BuiltinComplex64) Mul

func (_ BuiltinComplex64) Mul(res *complex64, l *complex64, r *complex64)

Multiplies l to r, placing the result in the value that res points to.

func (BuiltinComplex64) Neg

func (_ BuiltinComplex64) Neg(v *complex64)

Negates v, updating the value that v points to.

func (BuiltinComplex64) Sub

func (_ BuiltinComplex64) Sub(res *complex64, l *complex64, r *complex64)

Subtracts l to r, placing the result in the value that res points to.

func (BuiltinComplex64) UnitVal

func (_ BuiltinComplex64) UnitVal() complex64

Returns the unit value for the complex64 type.

func (BuiltinComplex64) Zero

func (_ BuiltinComplex64) Zero(other *complex64)

Zeros the supplied value.

func (BuiltinComplex64) ZeroVal

func (_ BuiltinComplex64) ZeroVal() complex64

Returns the zero value for the complex64 type.

type BuiltinFloat32

type BuiltinFloat32 struct{}

A widget to represent the built-in float32 type

func (BuiltinFloat32) Add

func (_ BuiltinFloat32) Add(res *float32, l *float32, r *float32)

Adds l to r, placing the result in the value that res points to.

func (BuiltinFloat32) Div

func (_ BuiltinFloat32) Div(res *float32, l *float32, r *float32)

Divides l to r, placing the result in the value that res points to.

func (BuiltinFloat32) Eq

func (_ BuiltinFloat32) Eq(l *float32, r *float32) bool

Returns true if both float32's are equal. Uses the standard == operator internally.

func (BuiltinFloat32) Hash

func (_ BuiltinFloat32) Hash(v *float32) hash.Hash

Provides a hash function for the value that it is wrapping.

func (BuiltinFloat32) Lt

func (_ BuiltinFloat32) Lt(l *float32, r *float32) bool

Returns true if l<r. Uses the standard < operator internally.

func (BuiltinFloat32) Mul

func (_ BuiltinFloat32) Mul(res *float32, l *float32, r *float32)

Multiplies l to r, placing the result in the value that res points to.

func (BuiltinFloat32) Neg

func (_ BuiltinFloat32) Neg(v *float32)

Negates v, updating the value that v points to.

func (BuiltinFloat32) Sub

func (_ BuiltinFloat32) Sub(res *float32, l *float32, r *float32)

Subtracts l to r, placing the result in the value that res points to.

func (BuiltinFloat32) UnitVal

func (_ BuiltinFloat32) UnitVal() float32

Returns the unit value for the float32 type.

func (BuiltinFloat32) Zero

func (_ BuiltinFloat32) Zero(other *float32)

Zeros the supplied value.

func (BuiltinFloat32) ZeroVal

func (_ BuiltinFloat32) ZeroVal() float32

Returns the zero value for the float32 type.

type BuiltinFloat64

type BuiltinFloat64 struct{}

A widget to represent the built-in float64 type

func (BuiltinFloat64) Add

func (_ BuiltinFloat64) Add(res *float64, l *float64, r *float64)

Adds l to r, placing the result in the value that res points to.

func (BuiltinFloat64) Div

func (_ BuiltinFloat64) Div(res *float64, l *float64, r *float64)

Divides l to r, placing the result in the value that res points to.

func (BuiltinFloat64) Eq

func (_ BuiltinFloat64) Eq(l *float64, r *float64) bool

Returns true if both float64's are equal. Uses the standard == operator internally.

func (BuiltinFloat64) Hash

func (_ BuiltinFloat64) Hash(v *float64) hash.Hash

Provides a hash function for the value that it is wrapping.

func (BuiltinFloat64) Lt

func (_ BuiltinFloat64) Lt(l *float64, r *float64) bool

Returns true if l<r. Uses the standard < operator internally.

func (BuiltinFloat64) Mul

func (_ BuiltinFloat64) Mul(res *float64, l *float64, r *float64)

Multiplies l to r, placing the result in the value that res points to.

func (BuiltinFloat64) Neg

func (_ BuiltinFloat64) Neg(v *float64)

Negates v, updating the value that v points to.

func (BuiltinFloat64) Sub

func (_ BuiltinFloat64) Sub(res *float64, l *float64, r *float64)

Subtracts l to r, placing the result in the value that res points to.

func (BuiltinFloat64) UnitVal

func (_ BuiltinFloat64) UnitVal() float64

Returns the unit value for the float64 type.

func (BuiltinFloat64) Zero

func (_ BuiltinFloat64) Zero(other *float64)

Zeros the supplied value.

func (BuiltinFloat64) ZeroVal

func (_ BuiltinFloat64) ZeroVal() float64

Returns the zero value for the float64 type.

type BuiltinHash

type BuiltinHash struct{}

A widget to represent the built-in hash.Hash type

func (BuiltinHash) Add

func (_ BuiltinHash) Add(res *hash.Hash, l *hash.Hash, r *hash.Hash)

Adds l to r, placing the result in the value that res points to.

func (BuiltinHash) Div

func (_ BuiltinHash) Div(res *hash.Hash, l *hash.Hash, r *hash.Hash)

Divides l to r, placing the result in the value that res points to.

func (BuiltinHash) Eq

func (_ BuiltinHash) Eq(l *hash.Hash, r *hash.Hash) bool

Returns true if both hash.Hash's are equal. Uses the standard == operator internally.

func (BuiltinHash) Hash

func (_ BuiltinHash) Hash(v *hash.Hash) hash.Hash

Provides a hash function for the value that it is wrapping.

func (BuiltinHash) Lt

func (_ BuiltinHash) Lt(l *hash.Hash, r *hash.Hash) bool

Returns true if l<r. Uses the standard < operator internally.

func (BuiltinHash) Mul

func (_ BuiltinHash) Mul(res *hash.Hash, l *hash.Hash, r *hash.Hash)

Multiplies l to r, placing the result in the value that res points to.

func (BuiltinHash) Neg

func (_ BuiltinHash) Neg(v *hash.Hash)

Negates v, updating the value that v points to.

func (BuiltinHash) Sub

func (_ BuiltinHash) Sub(res *hash.Hash, l *hash.Hash, r *hash.Hash)

Subtracts l to r, placing the result in the value that res points to.

func (BuiltinHash) UnitVal

func (_ BuiltinHash) UnitVal() hash.Hash

Returns the unit value for the hash.Hash type.

func (BuiltinHash) Zero

func (_ BuiltinHash) Zero(other *hash.Hash)

Zeros the supplied value.

func (BuiltinHash) ZeroVal

func (_ BuiltinHash) ZeroVal() hash.Hash

Returns the zero value for the hash.Hash type.

type BuiltinInt

type BuiltinInt struct{}

A widget to represent the built-in int type

func (BuiltinInt) Add

func (_ BuiltinInt) Add(res *int, l *int, r *int)

Adds l to r, placing the result in the value that res points to.

func (BuiltinInt) Div

func (_ BuiltinInt) Div(res *int, l *int, r *int)

Divides l to r, placing the result in the value that res points to.

func (BuiltinInt) Eq

func (_ BuiltinInt) Eq(l *int, r *int) bool

Returns true if both int's are equal. Uses the standard == operator internally.

func (BuiltinInt) Hash

func (_ BuiltinInt) Hash(v *int) hash.Hash

Provides a hash function for the value that it is wrapping.

func (BuiltinInt) Lt

func (_ BuiltinInt) Lt(l *int, r *int) bool

Returns true if l<r. Uses the standard < operator internally.

func (BuiltinInt) Mul

func (_ BuiltinInt) Mul(res *int, l *int, r *int)

Multiplies l to r, placing the result in the value that res points to.

func (BuiltinInt) Neg

func (_ BuiltinInt) Neg(v *int)

Negates v, updating the value that v points to.

func (BuiltinInt) Sub

func (_ BuiltinInt) Sub(res *int, l *int, r *int)

Subtracts l to r, placing the result in the value that res points to.

func (BuiltinInt) UnitVal

func (_ BuiltinInt) UnitVal() int

Returns the unit value for the int type.

func (BuiltinInt) Zero

func (_ BuiltinInt) Zero(other *int)

Zeros the supplied value.

func (BuiltinInt) ZeroVal

func (_ BuiltinInt) ZeroVal() int

Returns the zero value for the int type.

type BuiltinInt16

type BuiltinInt16 struct{}

A widget to represent the built-in int16 type

func (BuiltinInt16) Add

func (_ BuiltinInt16) Add(res *int16, l *int16, r *int16)

Adds l to r, placing the result in the value that res points to.

func (BuiltinInt16) Div

func (_ BuiltinInt16) Div(res *int16, l *int16, r *int16)

Divides l to r, placing the result in the value that res points to.

func (BuiltinInt16) Eq

func (_ BuiltinInt16) Eq(l *int16, r *int16) bool

Returns true if both int16's are equal. Uses the standard == operator internally.

func (BuiltinInt16) Hash

func (_ BuiltinInt16) Hash(v *int16) hash.Hash

Provides a hash function for the value that it is wrapping.

func (BuiltinInt16) Lt

func (_ BuiltinInt16) Lt(l *int16, r *int16) bool

Returns true if l<r. Uses the standard < operator internally.

func (BuiltinInt16) Mul

func (_ BuiltinInt16) Mul(res *int16, l *int16, r *int16)

Multiplies l to r, placing the result in the value that res points to.

func (BuiltinInt16) Neg

func (_ BuiltinInt16) Neg(v *int16)

Negates v, updating the value that v points to.

func (BuiltinInt16) Sub

func (_ BuiltinInt16) Sub(res *int16, l *int16, r *int16)

Subtracts l to r, placing the result in the value that res points to.

func (BuiltinInt16) UnitVal

func (_ BuiltinInt16) UnitVal() int16

Returns the unit value for the int16 type.

func (BuiltinInt16) Zero

func (_ BuiltinInt16) Zero(other *int16)

Zeros the supplied value.

func (BuiltinInt16) ZeroVal

func (_ BuiltinInt16) ZeroVal() int16

Returns the zero value for the int16 type.

type BuiltinInt32

type BuiltinInt32 struct{}

A widget to represent the built-in int32 type

func (BuiltinInt32) Add

func (_ BuiltinInt32) Add(res *int32, l *int32, r *int32)

Adds l to r, placing the result in the value that res points to.

func (BuiltinInt32) Div

func (_ BuiltinInt32) Div(res *int32, l *int32, r *int32)

Divides l to r, placing the result in the value that res points to.

func (BuiltinInt32) Eq

func (_ BuiltinInt32) Eq(l *int32, r *int32) bool

Returns true if both int32's are equal. Uses the standard == operator internally.

func (BuiltinInt32) Hash

func (_ BuiltinInt32) Hash(v *int32) hash.Hash

Provides a hash function for the value that it is wrapping.

func (BuiltinInt32) Lt

func (_ BuiltinInt32) Lt(l *int32, r *int32) bool

Returns true if l<r. Uses the standard < operator internally.

func (BuiltinInt32) Mul

func (_ BuiltinInt32) Mul(res *int32, l *int32, r *int32)

Multiplies l to r, placing the result in the value that res points to.

func (BuiltinInt32) Neg

func (_ BuiltinInt32) Neg(v *int32)

Negates v, updating the value that v points to.

func (BuiltinInt32) Sub

func (_ BuiltinInt32) Sub(res *int32, l *int32, r *int32)

Subtracts l to r, placing the result in the value that res points to.

func (BuiltinInt32) UnitVal

func (_ BuiltinInt32) UnitVal() int32

Returns the unit value for the int32 type.

func (BuiltinInt32) Zero

func (_ BuiltinInt32) Zero(other *int32)

Zeros the supplied value.

func (BuiltinInt32) ZeroVal

func (_ BuiltinInt32) ZeroVal() int32

Returns the zero value for the int32 type.

type BuiltinInt64

type BuiltinInt64 struct{}

A widget to represent the built-in int64 type

func (BuiltinInt64) Add

func (_ BuiltinInt64) Add(res *int64, l *int64, r *int64)

Adds l to r, placing the result in the value that res points to.

func (BuiltinInt64) Div

func (_ BuiltinInt64) Div(res *int64, l *int64, r *int64)

Divides l to r, placing the result in the value that res points to.

func (BuiltinInt64) Eq

func (_ BuiltinInt64) Eq(l *int64, r *int64) bool

Returns true if both int64's are equal. Uses the standard == operator internally.

func (BuiltinInt64) Hash

func (_ BuiltinInt64) Hash(v *int64) hash.Hash

Provides a hash function for the value that it is wrapping.

func (BuiltinInt64) Lt

func (_ BuiltinInt64) Lt(l *int64, r *int64) bool

Returns true if l<r. Uses the standard < operator internally.

func (BuiltinInt64) Mul

func (_ BuiltinInt64) Mul(res *int64, l *int64, r *int64)

Multiplies l to r, placing the result in the value that res points to.

func (BuiltinInt64) Neg

func (_ BuiltinInt64) Neg(v *int64)

Negates v, updating the value that v points to.

func (BuiltinInt64) Sub

func (_ BuiltinInt64) Sub(res *int64, l *int64, r *int64)

Subtracts l to r, placing the result in the value that res points to.

func (BuiltinInt64) UnitVal

func (_ BuiltinInt64) UnitVal() int64

Returns the unit value for the int64 type.

func (BuiltinInt64) Zero

func (_ BuiltinInt64) Zero(other *int64)

Zeros the supplied value.

func (BuiltinInt64) ZeroVal

func (_ BuiltinInt64) ZeroVal() int64

Returns the zero value for the int64 type.

type BuiltinInt8

type BuiltinInt8 struct{}

A widget to represent the built-in int8 type

func (BuiltinInt8) Add

func (_ BuiltinInt8) Add(res *int8, l *int8, r *int8)

Adds l to r, placing the result in the value that res points to.

func (BuiltinInt8) Div

func (_ BuiltinInt8) Div(res *int8, l *int8, r *int8)

Divides l to r, placing the result in the value that res points to.

func (BuiltinInt8) Eq

func (_ BuiltinInt8) Eq(l *int8, r *int8) bool

Returns true if both int8's are equal. Uses the standard == operator internally.

func (BuiltinInt8) Hash

func (_ BuiltinInt8) Hash(v *int8) hash.Hash

Provides a hash function for the value that it is wrapping.

func (BuiltinInt8) Lt

func (_ BuiltinInt8) Lt(l *int8, r *int8) bool

Returns true if l<r. Uses the standard < operator internally.

func (BuiltinInt8) Mul

func (_ BuiltinInt8) Mul(res *int8, l *int8, r *int8)

Multiplies l to r, placing the result in the value that res points to.

func (BuiltinInt8) Neg

func (_ BuiltinInt8) Neg(v *int8)

Negates v, updating the value that v points to.

func (BuiltinInt8) Sub

func (_ BuiltinInt8) Sub(res *int8, l *int8, r *int8)

Subtracts l to r, placing the result in the value that res points to.

func (BuiltinInt8) UnitVal

func (_ BuiltinInt8) UnitVal() int8

Returns the unit value for the int8 type.

func (BuiltinInt8) Zero

func (_ BuiltinInt8) Zero(other *int8)

Zeros the supplied value.

func (BuiltinInt8) ZeroVal

func (_ BuiltinInt8) ZeroVal() int8

Returns the zero value for the int8 type.

type BuiltinString

type BuiltinString struct{}

A widget to represent the built-in string type

func (BuiltinString) Eq

func (_ BuiltinString) Eq(l *string, r *string) bool

Returns true if both string's are equal. Uses the standard == operator internally.

func (BuiltinString) Hash

func (_ BuiltinString) Hash(v *string) hash.Hash

Provides a hash function for the value that it is wrapping.

func (BuiltinString) Lt

func (_ BuiltinString) Lt(l *string, r *string) bool

Returns true if l<r. Uses the standard < operator internally.

func (BuiltinString) Zero

func (_ BuiltinString) Zero(other *string)

Zeros the supplied value.

type BuiltinUint

type BuiltinUint struct{}

A widget to represent the built-in uint type

func (BuiltinUint) Add

func (_ BuiltinUint) Add(res *uint, l *uint, r *uint)

Adds l to r, placing the result in the value that res points to.

func (BuiltinUint) Div

func (_ BuiltinUint) Div(res *uint, l *uint, r *uint)

Divides l to r, placing the result in the value that res points to.

func (BuiltinUint) Eq

func (_ BuiltinUint) Eq(l *uint, r *uint) bool

Returns true if both uint's are equal. Uses the standard == operator internally.

func (BuiltinUint) Hash

func (_ BuiltinUint) Hash(v *uint) hash.Hash

Provides a hash function for the value that it is wrapping.

func (BuiltinUint) Lt

func (_ BuiltinUint) Lt(l *uint, r *uint) bool

Returns true if l<r. Uses the standard < operator internally.

func (BuiltinUint) Mul

func (_ BuiltinUint) Mul(res *uint, l *uint, r *uint)

Multiplies l to r, placing the result in the value that res points to.

func (BuiltinUint) Neg

func (_ BuiltinUint) Neg(v *uint)

Negates v, updating the value that v points to.

func (BuiltinUint) Sub

func (_ BuiltinUint) Sub(res *uint, l *uint, r *uint)

Subtracts l to r, placing the result in the value that res points to.

func (BuiltinUint) UnitVal

func (_ BuiltinUint) UnitVal() uint

Returns the unit value for the uint type.

func (BuiltinUint) Zero

func (_ BuiltinUint) Zero(other *uint)

Zeros the supplied value.

func (BuiltinUint) ZeroVal

func (_ BuiltinUint) ZeroVal() uint

Returns the zero value for the uint type.

type BuiltinUint16

type BuiltinUint16 struct{}

A widget to represent the built-in uint16 type

func (BuiltinUint16) Add

func (_ BuiltinUint16) Add(res *uint16, l *uint16, r *uint16)

Adds l to r, placing the result in the value that res points to.

func (BuiltinUint16) Div

func (_ BuiltinUint16) Div(res *uint16, l *uint16, r *uint16)

Divides l to r, placing the result in the value that res points to.

func (BuiltinUint16) Eq

func (_ BuiltinUint16) Eq(l *uint16, r *uint16) bool

Returns true if both uint16's are equal. Uses the standard == operator internally.

func (BuiltinUint16) Hash

func (_ BuiltinUint16) Hash(v *uint16) hash.Hash

Provides a hash function for the value that it is wrapping.

func (BuiltinUint16) Lt

func (_ BuiltinUint16) Lt(l *uint16, r *uint16) bool

Returns true if l<r. Uses the standard < operator internally.

func (BuiltinUint16) Mul

func (_ BuiltinUint16) Mul(res *uint16, l *uint16, r *uint16)

Multiplies l to r, placing the result in the value that res points to.

func (BuiltinUint16) Neg

func (_ BuiltinUint16) Neg(v *uint16)

Negates v, updating the value that v points to.

func (BuiltinUint16) Sub

func (_ BuiltinUint16) Sub(res *uint16, l *uint16, r *uint16)

Subtracts l to r, placing the result in the value that res points to.

func (BuiltinUint16) UnitVal

func (_ BuiltinUint16) UnitVal() uint16

Returns the unit value for the uint16 type.

func (BuiltinUint16) Zero

func (_ BuiltinUint16) Zero(other *uint16)

Zeros the supplied value.

func (BuiltinUint16) ZeroVal

func (_ BuiltinUint16) ZeroVal() uint16

Returns the zero value for the uint16 type.

type BuiltinUint32

type BuiltinUint32 struct{}

A widget to represent the built-in uint32 type

func (BuiltinUint32) Add

func (_ BuiltinUint32) Add(res *uint32, l *uint32, r *uint32)

Adds l to r, placing the result in the value that res points to.

func (BuiltinUint32) Div

func (_ BuiltinUint32) Div(res *uint32, l *uint32, r *uint32)

Divides l to r, placing the result in the value that res points to.

func (BuiltinUint32) Eq

func (_ BuiltinUint32) Eq(l *uint32, r *uint32) bool

Returns true if both uint32's are equal. Uses the standard == operator internally.

func (BuiltinUint32) Hash

func (_ BuiltinUint32) Hash(v *uint32) hash.Hash

Provides a hash function for the value that it is wrapping.

func (BuiltinUint32) Lt

func (_ BuiltinUint32) Lt(l *uint32, r *uint32) bool

Returns true if l<r. Uses the standard < operator internally.

func (BuiltinUint32) Mul

func (_ BuiltinUint32) Mul(res *uint32, l *uint32, r *uint32)

Multiplies l to r, placing the result in the value that res points to.

func (BuiltinUint32) Neg

func (_ BuiltinUint32) Neg(v *uint32)

Negates v, updating the value that v points to.

func (BuiltinUint32) Sub

func (_ BuiltinUint32) Sub(res *uint32, l *uint32, r *uint32)

Subtracts l to r, placing the result in the value that res points to.

func (BuiltinUint32) UnitVal

func (_ BuiltinUint32) UnitVal() uint32

Returns the unit value for the uint32 type.

func (BuiltinUint32) Zero

func (_ BuiltinUint32) Zero(other *uint32)

Zeros the supplied value.

func (BuiltinUint32) ZeroVal

func (_ BuiltinUint32) ZeroVal() uint32

Returns the zero value for the uint32 type.

type BuiltinUint64

type BuiltinUint64 struct{}

A widget to represent the built-in uint64 type

func (BuiltinUint64) Add

func (_ BuiltinUint64) Add(res *uint64, l *uint64, r *uint64)

Adds l to r, placing the result in the value that res points to.

func (BuiltinUint64) Div

func (_ BuiltinUint64) Div(res *uint64, l *uint64, r *uint64)

Divides l to r, placing the result in the value that res points to.

func (BuiltinUint64) Eq

func (_ BuiltinUint64) Eq(l *uint64, r *uint64) bool

Returns true if both uint64's are equal. Uses the standard == operator internally.

func (BuiltinUint64) Hash

func (_ BuiltinUint64) Hash(v *uint64) hash.Hash

Provides a hash function for the value that it is wrapping.

func (BuiltinUint64) Lt

func (_ BuiltinUint64) Lt(l *uint64, r *uint64) bool

Returns true if l<r. Uses the standard < operator internally.

func (BuiltinUint64) Mul

func (_ BuiltinUint64) Mul(res *uint64, l *uint64, r *uint64)

Multiplies l to r, placing the result in the value that res points to.

func (BuiltinUint64) Neg

func (_ BuiltinUint64) Neg(v *uint64)

Negates v, updating the value that v points to.

func (BuiltinUint64) Sub

func (_ BuiltinUint64) Sub(res *uint64, l *uint64, r *uint64)

Subtracts l to r, placing the result in the value that res points to.

func (BuiltinUint64) UnitVal

func (_ BuiltinUint64) UnitVal() uint64

Returns the unit value for the uint64 type.

func (BuiltinUint64) Zero

func (_ BuiltinUint64) Zero(other *uint64)

Zeros the supplied value.

func (BuiltinUint64) ZeroVal

func (_ BuiltinUint64) ZeroVal() uint64

Returns the zero value for the uint64 type.

type BuiltinUint8

type BuiltinUint8 struct{}

A widget to represent the built-in uint8 type

func (BuiltinUint8) Add

func (_ BuiltinUint8) Add(res *uint8, l *uint8, r *uint8)

Adds l to r, placing the result in the value that res points to.

func (BuiltinUint8) Div

func (_ BuiltinUint8) Div(res *uint8, l *uint8, r *uint8)

Divides l to r, placing the result in the value that res points to.

func (BuiltinUint8) Eq

func (_ BuiltinUint8) Eq(l *uint8, r *uint8) bool

Returns true if both uint8's are equal. Uses the standard == operator internally.

func (BuiltinUint8) Hash

func (_ BuiltinUint8) Hash(v *uint8) hash.Hash

Provides a hash function for the value that it is wrapping.

func (BuiltinUint8) Lt

func (_ BuiltinUint8) Lt(l *uint8, r *uint8) bool

Returns true if l<r. Uses the standard < operator internally.

func (BuiltinUint8) Mul

func (_ BuiltinUint8) Mul(res *uint8, l *uint8, r *uint8)

Multiplies l to r, placing the result in the value that res points to.

func (BuiltinUint8) Neg

func (_ BuiltinUint8) Neg(v *uint8)

Negates v, updating the value that v points to.

func (BuiltinUint8) Sub

func (_ BuiltinUint8) Sub(res *uint8, l *uint8, r *uint8)

Subtracts l to r, placing the result in the value that res points to.

func (BuiltinUint8) UnitVal

func (_ BuiltinUint8) UnitVal() uint8

Returns the unit value for the uint8 type.

func (BuiltinUint8) Zero

func (_ BuiltinUint8) Zero(other *uint8)

Zeros the supplied value.

func (BuiltinUint8) ZeroVal

func (_ BuiltinUint8) ZeroVal() uint8

Returns the zero value for the uint8 type.

type BuiltinUintptr

type BuiltinUintptr struct{}

A widget to represent the built-in uintptr type

func (BuiltinUintptr) Add

func (_ BuiltinUintptr) Add(res *uintptr, l *uintptr, r *uintptr)

Adds l to r, placing the result in the value that res points to.

func (BuiltinUintptr) Div

func (_ BuiltinUintptr) Div(res *uintptr, l *uintptr, r *uintptr)

Divides l to r, placing the result in the value that res points to.

func (BuiltinUintptr) Eq

func (_ BuiltinUintptr) Eq(l *uintptr, r *uintptr) bool

Returns true if both uintptr's are equal. Uses the standard == operator internally.

func (BuiltinUintptr) Hash

func (_ BuiltinUintptr) Hash(v *uintptr) hash.Hash

Provides a hash function for the value that it is wrapping.

func (BuiltinUintptr) Lt

func (_ BuiltinUintptr) Lt(l *uintptr, r *uintptr) bool

Returns true if l<r. Uses the standard < operator internally.

func (BuiltinUintptr) Mul

func (_ BuiltinUintptr) Mul(res *uintptr, l *uintptr, r *uintptr)

Multiplies l to r, placing the result in the value that res points to.

func (BuiltinUintptr) Neg

func (_ BuiltinUintptr) Neg(v *uintptr)

Negates v, updating the value that v points to.

func (BuiltinUintptr) Sub

func (_ BuiltinUintptr) Sub(res *uintptr, l *uintptr, r *uintptr)

Subtracts l to r, placing the result in the value that res points to.

func (BuiltinUintptr) UnitVal

func (_ BuiltinUintptr) UnitVal() uintptr

Returns the unit value for the uintptr type.

func (BuiltinUintptr) Zero

func (_ BuiltinUintptr) Zero(other *uintptr)

Zeros the supplied value.

func (BuiltinUintptr) ZeroVal

func (_ BuiltinUintptr) ZeroVal() uintptr

Returns the zero value for the uintptr type.

type NilWidget

type NilWidget[T any] struct{}

A widget value that is used when values do not necessarily need the methods that the widget interface imposes but still need to be used in scenarios that expect a widget type. The behavior of the widget interface is as follows:

  • Widgets of this type will never be considered equal
  • Widgets of this type will never be considered less than another
  • Widgets of this type will always have a hash of 0
  • Widgets of this type will perform no action with the zero function

func (NilWidget[T]) Eq

func (n NilWidget[T]) Eq(l *T, r *T) bool

func (NilWidget[T]) Hash

func (n NilWidget[T]) Hash(other *T) hash.Hash

func (NilWidget[T]) Lt

func (n NilWidget[T]) Lt(l *T, r *T) bool

func (NilWidget[T]) Zero

func (n NilWidget[T]) Zero(other *T)

type PartialOrder

type PartialOrder[T any, I PartialOrderInterface[T]] struct {
	Base[T, I]
}

A concrete partial order widget. Internally, this struct will create an interface value of type PartialOrderInterface that points to nil data. All methods on widget are then very thin pass through functions that call the needed methods on the interface value with the supplied values.

Example
v1, v2 := 0, 1
w := PartialOrder[int, BuiltinInt]{}
fmt.Println("Lt:", w.Lt(&v1, &v2))
Output:

Lt: true

func (*PartialOrder[T, I]) Gt

func (w *PartialOrder[T, I]) Gt(l *T, r *T) bool

Compares the left (l) and right (r) values and returns true is l>r using the Lt and Eq functions from the interface that was supplied as a generic type.

func (*PartialOrder[T, I]) Gte

func (w *PartialOrder[T, I]) Gte(l *T, r *T) bool

Compares the left (l) and right (r) values and returns true is l>=r using the Lt function from the interface that was supplied as a generic type.

func (*PartialOrder[T, I]) Lt

func (w *PartialOrder[T, I]) Lt(l *T, r *T) bool

Compares the left (l) and right (r) values and returns true is l<r using the Lt function from the interface that was supplied as a generic type.

func (*PartialOrder[T, I]) Lte

func (w *PartialOrder[T, I]) Lte(l *T, r *T) bool

Compares the left (l) and right (r) values and returns true is l<=r using the Lt and Eq functions from the interface that was supplied as a generic type.

type PartialOrderArith

type PartialOrderArith[T any, I PartialOrderArithInterface[T]] struct {
	Base[T, I]
}

A concrete arithmitic widget. Internally, this struct will create an interface value of type PartialOrderArith that points to nil data. All methods on widget are then very thin pass through functions that call the needed methods on the interface value with the supplied values.

func (*PartialOrderArith[T, I]) Add

func (w *PartialOrderArith[T, I]) Add(res *T, l *T, r *T)

Adds the supplied values using the function from the interface that was supplied as a generic type.

func (*PartialOrderArith[T, I]) Div

func (w *PartialOrderArith[T, I]) Div(res *T, l *T, r *T)

Divides the supplied values using the function from the interface that was supplied as a generic type.

func (*PartialOrderArith[T, I]) Gt

func (w *PartialOrderArith[T, I]) Gt(l *T, r *T) bool

Compares the left (l) and right (r) values and returns true is l>r using the Lt and Eq functions from the interface that was supplied as a generic type.

func (*PartialOrderArith[T, I]) Gte

func (w *PartialOrderArith[T, I]) Gte(l *T, r *T) bool

Compares the left (l) and right (r) values and returns true is l>=r using the Lt function from the interface that was supplied as a generic type.

func (*PartialOrderArith[T, I]) Lt

func (w *PartialOrderArith[T, I]) Lt(l *T, r *T) bool

Compares the left (l) and right (r) values and returns true is l<r using the Lt function from the interface that was supplied as a generic type.

func (*PartialOrderArith[T, I]) Lte

func (w *PartialOrderArith[T, I]) Lte(l *T, r *T) bool

Compares the left (l) and right (r) values and returns true is l<=r using the Lt and Eq functions from the interface that was supplied as a generic type.

func (*PartialOrderArith[T, I]) Mul

func (w *PartialOrderArith[T, I]) Mul(res *T, l *T, r *T)

Multiplies the supplied values using the function from the interface that was supplied as a generic type.

func (*PartialOrderArith[T, I]) Neg

func (w *PartialOrderArith[T, I]) Neg(v *T)

Negates the supplied value using the function from the interface that was supplied as a generic type.

func (*PartialOrderArith[T, I]) Neq

func (w *PartialOrderArith[T, I]) Neq(l *T, r *T) bool

Compares the left (l) and right (r) values and returns true is l!=r using the Eq function from the interface that was supplied as a generic type.

func (*PartialOrderArith[T, I]) Sub

func (w *PartialOrderArith[T, I]) Sub(res *T, l *T, r *T)

Subtracts the supplied values using the function from the interface that was supplied as a generic type.

func (*PartialOrderArith[T, I]) UnitVal

func (w *PartialOrderArith[T, I]) UnitVal() T

Returns the "1" value for the given widget type using the function from the interface that was supplied as a generic type.

func (*PartialOrderArith[T, I]) ZeroVal

func (w *PartialOrderArith[T, I]) ZeroVal() T

Returns the "zero" value for the given widget type using the function from the interface that was supplied as a generic type.

type PartialOrderArithInterface

type PartialOrderArithInterface[T any] interface {
	ArithInterface[T]
	PartialOrderInterface[T]
}

The interface that defines what it means to be a widget that supports both the arithmetic and partial order interface. Implementations of this interface are expected to hold no state that pertains to the widget functions as the methods will not be called in any predetermined order.

type PartialOrderArithPntr

type PartialOrderArithPntr[T any, I PartialOrderArithInterface[T]] struct {
	// contains filtered or unexported fields
}

A pass through widget that represents a pointer to an underlying type that is an arith partial order widget. This is useful for when you need a widget for a pointer. Consider a *int that you need a partial order arith widget for. The PartialOrderArithPntr struct would be used like this:

PartialOrderArithPntr[int, widgets.BuiltinInt]

func (PartialOrderArithPntr[T, I]) Add

func (p PartialOrderArithPntr[T, I]) Add(res **T, l **T, r **T)

func (PartialOrderArithPntr[T, I]) Div

func (p PartialOrderArithPntr[T, I]) Div(res **T, l **T, r **T)

func (PartialOrderArithPntr[T, I]) Eq

func (p PartialOrderArithPntr[T, I]) Eq(l **T, r **T) bool

func (PartialOrderArithPntr[T, I]) Hash

func (p PartialOrderArithPntr[T, I]) Hash(other **T) hash.Hash

func (PartialOrderArithPntr[T, I]) Lt

func (p PartialOrderArithPntr[T, I]) Lt(l **T, r **T) bool

func (PartialOrderArithPntr[T, I]) Mul

func (p PartialOrderArithPntr[T, I]) Mul(res **T, l **T, r **T)

func (PartialOrderArithPntr[T, I]) Neg

func (p PartialOrderArithPntr[T, I]) Neg(v **T)

func (PartialOrderArithPntr[T, I]) Sub

func (p PartialOrderArithPntr[T, I]) Sub(res **T, l **T, r **T)

func (PartialOrderArithPntr[T, I]) UnitVal

func (p PartialOrderArithPntr[T, I]) UnitVal() *T

func (PartialOrderArithPntr[T, I]) Zero

func (p PartialOrderArithPntr[T, I]) Zero(other **T)

func (PartialOrderArithPntr[T, I]) ZeroVal

func (p PartialOrderArithPntr[T, I]) ZeroVal() *T

type PartialOrderInterface

type PartialOrderInterface[T any] interface {
	BaseInterface[T]
	// A function that should return true if l<r.
	Lt(l *T, r *T) bool
}

The interface that defines what it means to be a widget that can be compared to other widgets. Implementations of this interface are expected to hold no state that pertains to the widget functions as the methods shown below will not be called in any predetermined order.

type PartialOrderPntr

type PartialOrderPntr[T any, I PartialOrderInterface[T]] struct {
	// contains filtered or unexported fields
}

A pass through widget that represents a pointer to an underlying type that is a partial order widget. This is useful for when you need a widget for a pointer. Consider a *int that you need a partial order widget for. The PartialOrderPntr struct would be used like this:

PartialOrderPntr[int, widgets.BuiltinInt]

func (PartialOrderPntr[T, I]) Eq

func (p PartialOrderPntr[T, I]) Eq(l **T, r **T) bool

func (PartialOrderPntr[T, I]) Hash

func (p PartialOrderPntr[T, I]) Hash(other **T) hash.Hash

func (PartialOrderPntr[T, I]) Lt

func (p PartialOrderPntr[T, I]) Lt(l **T, r **T) bool

func (PartialOrderPntr[T, I]) Zero

func (p PartialOrderPntr[T, I]) Zero(other **T)

type ZeroStructWidget

type ZeroStructWidget struct{}

A widget value that is used to represent explicitly zero values. The behavior of the widget interface is as follows:

  • Widgets of this type will always be considered equal
  • Widgets of this type will never be considered less than another
  • Widgets of this type will always have a hash of 0
  • Widgets of this type will perform no action with the zero function

func (ZeroStructWidget) Eq

func (z ZeroStructWidget) Eq(l *struct{}, r *struct{}) bool

func (ZeroStructWidget) Hash

func (z ZeroStructWidget) Hash(other *struct{}) hash.Hash

func (ZeroStructWidget) Lt

func (z ZeroStructWidget) Lt(l *struct{}, r *struct{}) bool

func (ZeroStructWidget) Zero

func (z ZeroStructWidget) Zero(other *struct{})

Jump to

Keyboard shortcuts

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