Class InMemoryGraph<TNodeId, TEdgeId, TSource>
- Namespace
- SpatialNET.Imp
- Assembly
- SpatialNET.Imp.dll
A network held in memory (ADR 0049): for tests, small networks and the temporary network of one area that is checked on save. Filled by hand with SpatialNET.Imp.InMemoryGraph`3.Add(SpatialNET.Network.GraphNode{`0}) and SpatialNET.Imp.InMemoryGraph`3.Add(SpatialNET.Network.GraphEdge{`0,`1}), or by the network builder as its SpatialNET.Network.INetworkWriter`3 (ADR 0050). It keeps the source of each edge, if one is given, and may enumerate its nodes and edges.
public sealed class InMemoryGraph<TNodeId, TEdgeId, TSource> : IGraph<TNodeId, TEdgeId>, INetworkWriter<TNodeId, TEdgeId, TSource> where TNodeId : notnull, IEquatable<TNodeId> where TEdgeId : notnull, IEquatable<TEdgeId>Type Parameters
TNodeId-
The node id.
TEdgeId-
The edge id.
TSource-
The host's reference to the source object of an edge, for example table and object id.
Inheritance
Implements
Inherited Members
Extension Methods
Remarks
Edges may be added before the nodes at their ends; a search reports a missing node as an SpatialNET.Network.InvalidGraphException.
Not thread-safe while it is filled; once filled, any number of searches may read it at the same time.
Properties
EdgeCount
The number of edges.
public int EdgeCount { get; }Property Value
Edges
The edges in the order they were added.
public IEnumerable<GraphEdge<TNodeId, TEdgeId>> Edges { get; }Property Value
- IEnumerable<GraphEdge<TNodeId, TEdgeId>>
NodeCount
The number of nodes.
public int NodeCount { get; }Property Value
Nodes
The nodes in the order they were added.
public IEnumerable<GraphNode<TNodeId>> Nodes { get; }Property Value
- IEnumerable<GraphNode<TNodeId>>
Methods
Add(GraphNode<TNodeId>)
Adds a node.
public void Add(GraphNode<TNodeId> node)Parameters
nodeGraphNode<TNodeId>
Exceptions
- ArgumentNullException
-
The id is
null. - ArgumentException
-
A node with this id was added before.
Add(GraphEdge<TNodeId, TEdgeId>)
Adds an edge without a source.
public void Add(GraphEdge<TNodeId, TEdgeId> edge)Parameters
edgeGraphEdge<TNodeId, TEdgeId>
Exceptions
- ArgumentNullException
-
An id is
null. - ArgumentException
-
An edge with this id was added before.
Add(GraphEdge<TNodeId, TEdgeId>, TSource, double, double)
Adds an edge with its source object and its range on the source line.
public void Add(GraphEdge<TNodeId, TEdgeId> edge, TSource source, double fromMeasure, double toMeasure)Parameters
edgeGraphEdge<TNodeId, TEdgeId>-
The edge.
sourceTSource-
The host's reference to the source object.
fromMeasuredouble-
Where the edge starts on the source line.
toMeasuredouble-
Where the edge ends on the source line.
Exceptions
- ArgumentNullException
-
An id is
null. - ArgumentException
-
An edge with this id was added before.
GetEdges(IReadOnlyCollection<TNodeId>)
Returns every edge that touches at least one of the given nodes, each edge once, including edges whose other end lies in another shard of the host.
public IEnumerable<GraphEdge<TNodeId, TEdgeId>> GetEdges(IReadOnlyCollection<TNodeId> nodeIds)Parameters
nodeIdsIReadOnlyCollection<TNodeId>-
The ids of the nodes, distinct.
Returns
- IEnumerable<GraphEdge<TNodeId, TEdgeId>>
GetNodes(IReadOnlyCollection<TNodeId>)
Returns the nodes with the given ids. Unknown ids are left out.
public IEnumerable<GraphNode<TNodeId>> GetNodes(IReadOnlyCollection<TNodeId> ids)Parameters
idsIReadOnlyCollection<TNodeId>-
The ids, distinct.
Returns
- IEnumerable<GraphNode<TNodeId>>
TryGetSource(TEdgeId, out TSource, out double, out double)
The source object and the range of an edge, if it was added with one.
public bool TryGetSource(TEdgeId edge, out TSource source, out double fromMeasure, out double toMeasure)Parameters
Returns
WriteEdge(in BuiltEdge<TNodeId, TEdgeId, TSource>)
Adds an edge written by the network builder, with its source and its range on the source line.
public void WriteEdge(in BuiltEdge<TNodeId, TEdgeId, TSource> edge)Parameters
edgeBuiltEdge<TNodeId, TEdgeId, TSource>
Exceptions
- ArgumentException
-
An edge with this id was added before.
WriteNode(in BuiltNode<TNodeId, TSource>)
Adds a node written by the network builder. The shard and the source are not kept.
public void WriteNode(in BuiltNode<TNodeId, TSource> node)Parameters
nodeBuiltNode<TNodeId, TSource>
Exceptions
- ArgumentException
-
A node with this id was added before.