Documentation ¶
Index ¶
- type EquivalenceRelation
- func (r *EquivalenceRelation) Add(element string)
- func (r *EquivalenceRelation) AddAll(elements []string)
- func (r *EquivalenceRelation) ElementClass(element string) (int, error)
- func (r *EquivalenceRelation) Map() map[int]([]string)
- func (r *EquivalenceRelation) OrderedClasses() []int
- func (r *EquivalenceRelation) Relate(element1, element2 string) (int, error)
- func (r *EquivalenceRelation) Related(element1, element2 string) (bool, error)
- type UnknownClassError
- type UnknownElementError
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.
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