Class ShardedGraphBase<TNodeId, TEdgeId>
- Namespace
- SpatialNET.Imp
- Assembly
- SpatialNET.Imp.dll
An SpatialNET.Network.IGraph`2 for a host that stores its network in shards, for example one per local network in a database (ADR 0049). It keeps a bounded number of whole shards in memory and drops the one used least recently. The host implements two methods: SpatialNET.Imp.ShardedGraphBase`2.FindShards(System.Collections.Generic.IReadOnlyCollection{`0}) (which shard holds these nodes, in one query) and SpatialNET.Imp.ShardedGraphBase`2.LoadShard(System.Int64) (all nodes of a shard and all edges that touch them).
public abstract class ShardedGraphBase<TNodeId, TEdgeId> : IGraph<TNodeId, TEdgeId> where TNodeId : notnull, IEquatable<TNodeId> where TEdgeId : notnull, IEquatable<TEdgeId>Type Parameters
TNodeId-
The host's node id.
TEdgeId-
The host's edge id.
Inheritance
Implements
Inherited Members
Extension Methods
Remarks
Thread-safe: several searches may use one instance. The two methods of the host are called one at a time.
A shard needed by one call stays in memory for that call, even if the call needs more shards than the cache holds.
Constructors
ShardedGraphBase(int)
Creates the cache.
protected ShardedGraphBase(int maxCachedShards = 32)Parameters
maxCachedShardsint-
How many shards are kept in memory; at least 1.
Exceptions
- ArgumentOutOfRangeException
-
maxCachedShardsis below 1.
Properties
CachedShardCount
How many shards are in memory now.
public int CachedShardCount { get; }Property Value
MaxCachedShards
How many shards are kept in memory.
public int MaxCachedShards { get; }Property Value
Methods
FindShards(IReadOnlyCollection<TNodeId>)
Maps node ids to the shards that hold them, in one query. Ids the host does not know are left out.
protected abstract IReadOnlyDictionary<TNodeId, long> FindShards(IReadOnlyCollection<TNodeId> nodeIds)Parameters
nodeIdsIReadOnlyCollection<TNodeId>-
The ids, distinct; none of them lies in a shard that is in memory.
Returns
- IReadOnlyDictionary<TNodeId, long>
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>>
LoadShard(long)
Loads all nodes of a shard and every edge that touches one of them.
protected abstract ShardData<TNodeId, TEdgeId> LoadShard(long shardId)Parameters
shardIdlong-
A shard that SpatialNET.Imp.ShardedGraphBase`2.FindShards(System.Collections.Generic.IReadOnlyCollection{`0}) returned.
Returns
- ShardData<TNodeId, TEdgeId>