Struct ScyllaGraphEdge
Lightweight, immutable edge descriptor for use with all Scylla graph structures.
Stores a directed connection from a source node to a target node along with a floating-point weight.
The struct is 12 bytes, fully unmanaged, and allocation-free - suitable for use in
Span<ScyllaGraphEdge> buffers and Unity DOTS NativeArray contexts.
Implements
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public readonly struct ScyllaGraphEdge : IEquatable<ScyllaGraphEdge>
Remarks
For undirected graphs the edge is stored once internally but the graph implementation exposes it from both endpoints. Reverse traversal is available via Reversed().
Equality and hash-code behaviour: two edges are equal when FromID,
ToID, and Weight all match (weight compared with
NumberUtil.Approximately). Because approximate weight comparison is used,
GetHashCode() intentionally excludes Weight to avoid
breaking the Equals/GetHashCode contract in hash-based collections.
Constructors
ScyllaGraphEdge(int, int, float)
Initializes a new ScyllaGraphEdge with the specified endpoints and weight.
Declaration
public ScyllaGraphEdge(int fromID, int toID, float weight = 1)
Parameters
| Type | Name | Description |
|---|---|---|
| int | fromID | ID of the source node. No existence check is performed here; the owning graph is responsible for validating node IDs at insertion time. |
| int | toID | ID of the target node. May equal |
| float | weight | Traversal cost of this edge. Defaults to |
Properties
FromID
ID of the source (origin) node. For directed graphs this is the tail of the arc; for undirected graphs the two endpoints are stored in insertion order.
Declaration
public int FromID { get; }
Property Value
| Type | Description |
|---|---|
| int |
ToID
ID of the target (destination) node. For directed graphs this is the head of the arc; for undirected graphs the two endpoints are stored in insertion order.
Declaration
public int ToID { get; }
Property Value
| Type | Description |
|---|---|
| int |
Weight
Traversal cost of this edge. For unweighted graphs this value is always 1.0f.
In weighted graphs it can represent any domain-specific cost such as distance,
travel time, or movement penalty. Negative weights are representable but note that
Dijkstra-based algorithms in ScyllaGraphAlgorithms require non-negative
weights to guarantee correct shortest-path results.
Declaration
public float Weight { get; }
Property Value
| Type | Description |
|---|---|
| float |
Methods
Equals(ScyllaGraphEdge)
Determines whether this edge equals other by comparing
FromID, ToID, and Weight (weight
is compared with NumberUtil.Approximately to tolerate floating-point rounding).
Declaration
public bool Equals(ScyllaGraphEdge other)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaGraphEdge | other | The edge to compare against. |
Returns
| Type | Description |
|---|---|
| bool |
|
Equals(object)
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj |
Returns
| Type | Description |
|---|---|
| bool |
Overrides
GetHashCode()
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int |
Overrides
Reversed()
Returns a new ScyllaGraphEdge with FromID and ToID swapped, preserving the original Weight. Useful when building undirected adjacency representations that store both directions explicitly, or when reconstructing a path in reverse after a search algorithm.
Declaration
public ScyllaGraphEdge Reversed()
Returns
| Type | Description |
|---|---|
| ScyllaGraphEdge | A new edge whose source is this edge's target and vice versa. |
ToString()
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string |
Overrides
WithWeight(float)
Returns a new ScyllaGraphEdge with the same FromID and ToID but a different Weight. Use this to rescale edge costs without constructing a completely new descriptor - for example when normalising weights across a graph or applying a terrain modifier to a movement cost.
Declaration
public ScyllaGraphEdge WithWeight(float weight)
Parameters
| Type | Name | Description |
|---|---|---|
| float | weight | The replacement weight value for the new edge. |
Returns
| Type | Description |
|---|---|
| ScyllaGraphEdge | A new edge identical to this one except for its weight. |
Operators
operator ==(ScyllaGraphEdge, ScyllaGraphEdge)
Returns true if left and right represent
the same directed connection with approximately equal weights.
Declaration
public static bool operator ==(ScyllaGraphEdge left, ScyllaGraphEdge right)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaGraphEdge | left | |
| ScyllaGraphEdge | right |
Returns
| Type | Description |
|---|---|
| bool |
See Also
operator !=(ScyllaGraphEdge, ScyllaGraphEdge)
Returns true if left and right differ
in endpoint IDs or have weights that are not approximately equal.
Declaration
public static bool operator !=(ScyllaGraphEdge left, ScyllaGraphEdge right)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaGraphEdge | left | |
| ScyllaGraphEdge | right |
Returns
| Type | Description |
|---|---|
| bool |