Skip to content

Commit

Permalink
No default instances anymore.
Browse files Browse the repository at this point in the history
  • Loading branch information
xivk committed May 16, 2023
1 parent 5381a3e commit 9b52155
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Itinero.Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<!--- Package information, Version -->
<PropertyGroup>
<PackageVersion>2.0.0-alpha-090</PackageVersion>
<PackageVersion>2.0.0-alpha-091</PackageVersion>
<NeutralLanguage>en</NeutralLanguage>
<Description>Itinero - Routeplanning for .NET.</Description>
<Copyright>Itinero BV</Copyright>
Expand Down
12 changes: 8 additions & 4 deletions src/Itinero/Routing/Flavours/Dijkstra/Dijkstra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,14 @@ await queued(enumerator.Head))
return paths;
}

private static readonly ThreadLocal<Dijkstra> DefaultLazy = new(() => new Dijkstra());

/// <summary>
/// Gets the default dijkstra instance (for the local thread).
/// Gets a default dijkstra instance.
/// </summary>
public static Dijkstra Default => DefaultLazy.Value;
public static Dijkstra Default
{
get
{
return new Dijkstra();
}
}
}
24 changes: 16 additions & 8 deletions src/Itinero/Routing/Flavours/Dijkstra/EdgeBased/Dijkstra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ internal class Dijkstra
Func<(EdgeId edgeId, VertexId vertexId), Task<bool>>? settled = null,
Func<(EdgeId edgeId, VertexId vertexId), Task<bool>>? queued = null)
{
var paths = await this.RunAsync(network, (source, null), new[] { (target, (bool?)null) }, getDijkstraWeight, settled, queued);
var paths = await this.RunAsync(network, (source, null), new[] { (target, (bool?)null) }, getDijkstraWeight,
settled, queued);

return paths.Length < 1 ? (null, double.MaxValue) : paths[0];
}

public async Task<(Path? path, double cost)> RunAsync(RoutingNetwork network, (SnapPoint sp, bool? direction) source,
public async Task<(Path? path, double cost)> RunAsync(RoutingNetwork network,
(SnapPoint sp, bool? direction) source,
(SnapPoint sp, bool? direction) target,
DijkstraWeightFunc getDijkstraWeight,
Func<(EdgeId edgeId, VertexId vertexId), Task<bool>>? settled = null,
Expand All @@ -52,7 +54,8 @@ internal class Dijkstra
Func<(EdgeId edgeId, VertexId vertexId), Task<bool>>? settled = null,
Func<(EdgeId edgeId, VertexId vertexId), Task<bool>>? queued = null)
{
return await this.RunAsync(network, (source, null), targets.Select(x => (x, (bool?)null)).ToArray(), getDijkstraWeight, settled, queued);
return await this.RunAsync(network, (source, null), targets.Select(x => (x, (bool?)null)).ToArray(),
getDijkstraWeight, settled, queued);
}

/// <summary>
Expand All @@ -66,7 +69,8 @@ internal class Dijkstra
/// <param name="queued">This callback is called before an edge is loaded. Should not be used to influence route planning (but e.g. to load data when needed)</param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public async Task<(Path? path, double cost)[]> RunAsync(RoutingNetwork network, (SnapPoint sp, bool? direction) source,
public async Task<(Path? path, double cost)[]> RunAsync(RoutingNetwork network,
(SnapPoint sp, bool? direction) source,
IReadOnlyList<(SnapPoint sp, bool? direction)> targets,
DijkstraWeightFunc getDijkstraWeight,
Func<(EdgeId edgeId, VertexId vertexId), Task<bool>>? settled = null,
Expand Down Expand Up @@ -443,10 +447,14 @@ await queued((enumerator.EdgeId, enumerator.Head)))
return paths;
}

private static readonly ThreadLocal<Dijkstra> DefaultLazy = new(() => new Dijkstra());

/// <summary>
/// Gets the default dijkstra instance (for the local thread).
/// Gets a default dijkstra instance.
/// </summary>
public static Dijkstra Default => DefaultLazy.Value;
public static Dijkstra Default
{
get
{
return new Dijkstra();
}
}
}
2 changes: 1 addition & 1 deletion src/Itinero/Search/RoutingNetworkQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async IAsyncEnumerable<VertexId> Vertices(
{
await _network.UsageNotifier.NotifyBox(_network, box, cancellationToken);
if (cancellationToken.IsCancellationRequested) yield break;

var vertices = _network.SearchVerticesInBox(box);
foreach (var (vertex, _) in vertices)
{
Expand Down

0 comments on commit 9b52155

Please sign in to comment.