mathutil

package
v0.19.8 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EquivalenceRelation

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

EquivalenceRelation implements a mathematical equivalence relation. Elements in this set are named, ie identified by strings. Elements are potentially grouped together in an equivalence relation. Each element belongs in exactly one relation, and each relation has 1 or more elements. If a,b are in the same relation, and if b,c are in the same relation, it follows that a,c are in the same relation. therefore two different entity relations cannot have any shared elements. Functions of this struct are not thread safe.

func NewEquivalenceRelation

func NewEquivalenceRelation() *EquivalenceRelation

func (*EquivalenceRelation) Add

func (r *EquivalenceRelation) Add(element string)

Add adds a single element to the set. The element is associated with its own unique class

func (*EquivalenceRelation) AddAll

func (r *EquivalenceRelation) AddAll(elements []string)

AddAll adds multiple elements to the set. Each element is associated with its own unique class

func (*EquivalenceRelation) ElementClass

func (r *EquivalenceRelation) ElementClass(element string) (int, error)

ElementClass returns the class id for the given element, or errors if the element is unknown

func (*EquivalenceRelation) Map

func (r *EquivalenceRelation) Map() map[int]([]string)

Map returns the complete map of classes to list of elements.

func (*EquivalenceRelation) OrderedClasses

func (r *EquivalenceRelation) OrderedClasses() []int

OrderedClasses returns the list of classes, increasing

func (*EquivalenceRelation) Relate

func (r *EquivalenceRelation) Relate(element1, element2 string) (int, error)

Declare two elements to be associated in the same class. If they're already in the same class, nothing is done. Otherwise, this merges their two classes into one. Specifically, the classes are merged into the lower-valued class of the two, ie the "earlier" class of the two, and the "later" class is erased.

func (*EquivalenceRelation) Related

func (r *EquivalenceRelation) Related(element1, element2 string) (bool, error)

Related returns true when both elements are in the same equivalence class. An error is returned if either element is unknown

type UnknownClassError

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

func (*UnknownClassError) Error

func (e *UnknownClassError) Error() string

type UnknownElementError

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

func (*UnknownElementError) Error

func (e *UnknownElementError) Error() string

Jump to

Keyboard shortcuts

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