com.phasmidsoftware.gryphon.adjunct
Members list
Type members
Classlikes
Abstract base class for disjoint-set implementations that relies on an immutable Map to associate objects with their parent disjoint set.
Abstract base class for disjoint-set implementations that relies on an immutable Map to associate objects with their parent disjoint set.
All operations are purely functional: every "mutation" returns a new instance constructed via unit, leaving the original unchanged. This makes instances persistent data structures — an old reference remains valid after any connect or put.
Each object V in map is associated with a value of type W. The function f extracts an optional parent V from a W value. If f(w) == None the object is the root of its own component.
The F-bound This <: AbstractDisjointSet[V, W, This] ensures that connect, put, and remove all return the concrete subtype without casting at the call site. The only remaining asInstanceOf casts are in the short-circuit cases where this is returned unchanged — these are safe but unavoidable, since the compiler cannot prove this: This without them.
This abstract class does not perform path compression. For path compression, you must extend the subclass AbstractDisjointSetWithCompression.
Type parameters
- This
-
the concrete subtype (F-bounded polymorphism).
- V
-
the underlying object type.
- W
-
the map value type (may equal
Option[V]or compound it with extra data).
Value parameters
- f
-
extracts the optional parent from a
Wvalue. - map
-
the component map: each
Vmaps to its associatedW.
Attributes
- Supertypes
- Known subtypes
Abstract base class for disjoint-set implementations that relies on an immutable Map to associate objects with their parent disjoint set.
Abstract base class for disjoint-set implementations that relies on an immutable Map to associate objects with their parent disjoint set.
All operations are purely functional: every "mutation" returns a new instance constructed via unit, leaving the original unchanged. This makes instances persistent data structures — an old reference remains valid after any connect or put.
Each object V in map is associated with a value of type W. The function f extracts an optional parent V from a W value. If f(w) == None the object is the root of its own component.
The F-bound This <: AbstractDisjointSet[V, W, This] ensures that connect, put, and remove all return the concrete subtype without casting at the call site. The only remaining asInstanceOf casts are in the short-circuit cases where this is returned unchanged — these are safe but unavoidable, since the compiler cannot prove this: This without them.
Subclasses that implement path compression should override findAndCompress. The default implementation simply delegates to getDisjointSet and returns this unchanged, so non-compressing subclasses need not override it. The connect method in this class calls findAndCompress for both arguments, so compression is applied automatically during every merge in subclasses that override it.
Type parameters
- This
-
the concrete subtype (F-bounded polymorphism).
- V
-
the underlying object type.
- W
-
the map value type (may equal
Option[V]or compound it with extra data).
Value parameters
- f
-
extracts the optional parent from a
Wvalue. - map
-
the component map: each
Vmaps to its associatedW.
Attributes
- Supertypes
- Known subtypes
-
class ConnectivityOptimized[V]
Companion object for the AttributedDirectedEdge class.
Companion object for the AttributedDirectedEdge class.
Provides factory methods for creating instances of AttributedDirectedEdge.
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
Represents a directed edge in a graph structure, connecting a starting vertex (from) to an ending vertex (to) while carrying an associated attribute.
Represents a directed edge in a graph structure, connecting a starting vertex (from) to an ending vertex (to) while carrying an associated attribute.
Type parameters
- E
-
the type of the attribute associated with the edge.
- V
-
the type of the vertex attributes connected by the edge.
Value parameters
- attribute
-
a value representing additional information or weight associated with the edge.
- from
-
the vertex where the directed edge originates.
- to
-
the vertex where the directed edge terminates.
Attributes
The Connectivity object provides factory methods for creating instances of Connectivity using different strategies for managing disjoint sets. These strategies include lazy and optimized implementations, each employing the "Weighted Quick Union" algorithm for efficient operations.
The Connectivity object provides factory methods for creating instances of Connectivity using different strategies for managing disjoint sets. These strategies include lazy and optimized implementations, each employing the "Weighted Quick Union" algorithm for efficient operations.
Attributes
- Companion
- trait
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Connectivity.type
A trait that combines the functionalities of a disjoint set and connectivity queries.
A trait that combines the functionalities of a disjoint set and connectivity queries.
Connectivity extends both DisjointSet and Connected, allowing for efficient operations on disjoint sets as well as determining connectivity between elements.
This trait is useful for scenarios where a combination of union-find operations and connectivity checks is required, such as network connectivity, clustering, and graph algorithms like Kruskal's Minimum Spanning Tree (MST).
The type parameter V represents the type of elements in the disjoint set.
Type parameters
- V
-
the type of elements managed by this connectivity structure.
Attributes
- Companion
- object
- Supertypes
- Known subtypes
Companion object for ConnectivityASP.
Companion object for ConnectivityASP.
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
ConnectivityASP.type
Concrete disjoint-set implementation using "Quick Union" (lazy union), with the ASP (Arbitrary Substitution Principle) violation noted in the code.
Concrete disjoint-set implementation using "Quick Union" (lazy union), with the ASP (Arbitrary Substitution Principle) violation noted in the code.
Each object maps to Option[V]: None means the object is a root; Some(parent) means the object's parent in the component tree.
This is O(n) in the worst case due to potentially unbalanced trees. Prefer ConnectivityLazy for production use.
unit and put return ConnectivityASP[V] directly, with no overrides required, courtesy of the F-bounded type parameter.
Type parameters
- V
-
the underlying object type.
Value parameters
- map
-
the component map.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait Connectivity[V]trait Connected[V]class Objecttrait Matchableclass AnyShow all
Concrete disjoint-set implementation using "Weighted Quick Union."
Concrete disjoint-set implementation using "Weighted Quick Union."
Each object maps to a ParentSize[V] carrying both its optional parent and the size of its component tree. When merging, the smaller tree is attached under the larger, keeping tree height O(log n) and all operations O(log n).
This implementation obeys the Arbitrary Substitution Principle (ASP): the choice of which root becomes the child is justified by tree size, not arbitrary.
unit and put return ConnectivityLazy[V] directly, with no overrides required, courtesy of the F-bounded type parameter.
Type parameters
- V
-
the underlying object type.
Value parameters
- map
-
the component map.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait Connectivity[V]trait Connected[V]class Objecttrait Matchableclass AnyShow all
Companion object for ConnectivityLazy.
Companion object for ConnectivityLazy.
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
ConnectivityLazy.type
Concrete disjoint-set implementation using "Weighted Quick Union with Path Compression."
Concrete disjoint-set implementation using "Weighted Quick Union with Path Compression."
Extends ConnectivityLazy with path compression: during every findAndCompress traversal to the root, all nodes along the path are rewired to point directly to the root. This flattens the tree lazily, giving amortized near-O(1) performance (formally O(α(n)), where α is the inverse Ackermann function).
Path compression is implemented purely functionally: the rewired nodes are accumulated into a new immutable Map which is returned alongside the root as a fresh ConnectivityOptimized instance. No mutation occurs.
Note that after path compression, rank (tracked via ParentSize.size) becomes an upper bound on depth rather than the true depth — this is the standard behaviour of union-by-rank with path compression, and is why the field is called size (a weaker proxy) rather than depth.
unit and put return ConnectivityOptimized[V] directly, with no overrides required, courtesy of the F-bounded type parameter.
Type parameters
- V
-
the underlying object type.
Value parameters
- map
-
the component map.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait Connectivity[V]trait Connected[V]class Objecttrait Matchableclass AnyShow all
Companion object for ConnectivityOptimized.
Companion object for ConnectivityOptimized.
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
An abstract trait representing a directed edge in a graph.
An abstract trait representing a directed edge in a graph.
This trait extends the Edge trait, providing a specific implementation for the edgeType method, which always returns Directed. The directed edge represents a one-way connection between two vertices.
Type parameters
- E
-
the type of the attribute associated with the edge.
- V
-
the type of the vertices connected by the edge.
Attributes
- Supertypes
- Known subtypes
-
class OrderedEdge[V]
Factory object for creating instances of DirectedGraph. This object provides utility methods to construct a directed graph from an edge list representation.
Factory object for creating instances of DirectedGraph. This object provides utility methods to construct a directed graph from an edge list representation.
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
DirectedGraph.type
Represents a directed graph structure that supports operations on vertexMap and edges. This class is a concrete implementation of the EdgeGraph trait, and models directed relationships between vertices with edges.
Represents a directed graph structure that supports operations on vertexMap and edges. This class is a concrete implementation of the EdgeGraph trait, and models directed relationships between vertices with edges.
Type parameters
- E
-
the type of attributes for the edges in the graph (invariant).
- V
-
the type of attributes for the vertexMap in the graph (invariant).
Value parameters
- vertexMap
-
the
VertexMapthat represents thisGraph.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass AbstractGraph[V]trait Graph[V]trait Traversable[V]class Objecttrait Matchableclass AnyShow all
- Known subtypes
-
Trait to model the behavior of a disjoint set. Thus, we provide put, connect, getDisjointSet, and size in addition to isConnected (from the super-trait).
Trait to model the behavior of a disjoint set. Thus, we provide put, connect, getDisjointSet, and size in addition to isConnected (from the super-trait).
The purpose of having a disjoint set representation of a "graph" is so that we can answer connectivity questions in close to O(1) time, rather than the O(n + m) time required for a full traversal of an edge-connected graph. The most typical application of this trait is Kruskal's MST algorithm.
The most typical concrete implementation of this trait is the ConnectivityLazy class (usually known as Union-Find).
The type parameter This is the F-bounded self-type, ensuring that put and connect return the concrete subtype rather than DisjointSet[V].
Type parameters
- This
-
the concrete subtype (F-bounded polymorphism).
- V
-
the underlying object type.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
class ConnectivityOptimized[V]class ConnectivityASP[V]class ConnectivityLazy[V]trait Connectivity[V]Show all
Represents a directed edge in a graph connecting two vertices of type V. This implementation specifically models directed edges for graph structures, where the direction is indicated from a from vertex to a to vertex. The edge carries no additional attributes.
Represents a directed edge in a graph connecting two vertices of type V. This implementation specifically models directed edges for graph structures, where the direction is indicated from a from vertex to a to vertex. The edge carries no additional attributes.
Type parameters
- V
-
the type of the vertices connected by the edge.
Value parameters
- from
-
the originating vertex of the edge.
- to
-
the terminating vertex of the edge.
Attributes
Companion object for ParentSize.
Companion object for ParentSize.
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
ParentSize.type
Carries an optional parent reference and the size of the component tree.
Carries an optional parent reference and the size of the component tree.
Type parameters
- V
-
the underlying object type.
Value parameters
- parent
-
Noneif this object is a root;Some(p)otherwise. - size
-
the number of objects in this component tree (meaningful only at the root). With path compression active, this becomes an upper bound on depth (rank) rather than the precise tree size.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Represents an undirected edge in a graph structure, connecting two vertices (white and black) equally, without a defined direction, and carrying an associated attribute.
Represents an undirected edge in a graph structure, connecting two vertices (white and black) equally, without a defined direction, and carrying an associated attribute.
Type parameters
- E
-
the type of the attribute associated with the edge.
- V
-
the type of the vertex attributes connected by the edge.
Value parameters
- attribute
-
a value representing additional information or weight associated with the edge.
- black
-
the other vertex connected by the undirected edge.
- white
-
one of the vertices connected by the undirected edge.
Attributes
- Supertypes
Factory object for creating instances of DirectedGraph. This object provides utility methods to construct a directed graph from an edge list representation.
Factory object for creating instances of DirectedGraph. This object provides utility methods to construct a directed graph from an edge list representation.
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
UndirectedGraph.type
Represents a directed graph structure that supports operations on vertexMap and edges. This class is a concrete implementation of the EdgeGraph trait, and models directed relationships between vertices with edges.
Represents a directed graph structure that supports operations on vertexMap and edges. This class is a concrete implementation of the EdgeGraph trait, and models directed relationships between vertices with edges.
Type parameters
- E
-
the type of attributes for the edges in the graph (invariant).
- V
-
the type of attributes for the vertexMap in the graph (invariant).
Value parameters
- vertexMap
-
the
VertexMapthat represents thisGraph.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass AbstractGraph[V]trait Graph[V]trait Traversable[V]class Objecttrait Matchableclass AnyShow all
Shared weighted-union logic for all ParentSize-based disjoint-set implementations.
Shared weighted-union logic for all ParentSize-based disjoint-set implementations.
Extracted here to avoid duplication between ConnectivityLazy and ConnectivityOptimized, both of which use identical merge strategies. A single point of change ensures the two implementations cannot silently diverge.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
WeightedUnion.type