Module Imperative.GenericRelationalValued

Imperative union find

Performs union by size, and path compression in find.

This is fully imperative and mutable.

Parameters

Signature

Existential wrappers for the return types of find

type 'a node_through_relation =
  1. | NodeThoughRelation : 'b Node.Node.t * ('a, 'b) Node.Relation.t -> 'a node_through_relation
type 'a value_through_relation =
  1. | ValueThroughRelation : 'b Node.Value.t * ('a, 'b) Node.Relation.t -> 'a value_through_relation
type 'a node_and_value_through_relation =
  1. | NodeValueThroughRelation : 'b Node.Node.t * 'b Node.Value.t * ('a, 'b) Node.Relation.t -> 'a node_and_value_through_relation

Find operations

val find_representative : 'a Node.Node.t -> 'a node_through_relation

Find the representative of a node, and the associated relation

val find_value : 'a Node.Node.t -> 'a value_through_relation

Find the value of a node, and the associated relation

Find the value and representative of a node, and the associated relation

Other misc operations

check_related a b returns the relation between a and b if they are in the same class.

val add_value : 'a Node.Node.t -> 'a Node.Value.t -> unit

add_value a v adds with the value v added to a (Or more precisely, the value is added to the representative of a, via the relation between a and its representative). Intersects with previous value via Value.meet if one is present

Union operation

val union : 'a Node.Node.t -> 'b Node.Node.t -> ('a, 'b) Node.Relation.t -> unit

union m n r adds the r(m,n) relation to the union find, refining the value of the chosen parent class using that of the chosen child via Value.value_intersection.

  • raises AssertionFailure

    if both nodes are in the same class