From 9b521551608480f214d270d205ad2fe5fb0e205b Mon Sep 17 00:00:00 2001 From: xivk Date: Tue, 16 May 2023 13:42:00 +0200 Subject: [PATCH] No default instances anymore. --- Itinero.Common.props | 2 +- .../Routing/Flavours/Dijkstra/Dijkstra.cs | 12 ++++++---- .../Flavours/Dijkstra/EdgeBased/Dijkstra.cs | 24 ++++++++++++------- src/Itinero/Search/RoutingNetworkQuery.cs | 2 +- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/Itinero.Common.props b/Itinero.Common.props index cdf7649a3..2351caf5d 100644 --- a/Itinero.Common.props +++ b/Itinero.Common.props @@ -3,7 +3,7 @@ - 2.0.0-alpha-090 + 2.0.0-alpha-091 en Itinero - Routeplanning for .NET. Itinero BV diff --git a/src/Itinero/Routing/Flavours/Dijkstra/Dijkstra.cs b/src/Itinero/Routing/Flavours/Dijkstra/Dijkstra.cs index f1f9c5def..78a41102c 100644 --- a/src/Itinero/Routing/Flavours/Dijkstra/Dijkstra.cs +++ b/src/Itinero/Routing/Flavours/Dijkstra/Dijkstra.cs @@ -366,10 +366,14 @@ await queued(enumerator.Head)) return paths; } - private static readonly ThreadLocal DefaultLazy = new(() => new Dijkstra()); - /// - /// Gets the default dijkstra instance (for the local thread). + /// Gets a default dijkstra instance. /// - public static Dijkstra Default => DefaultLazy.Value; + public static Dijkstra Default + { + get + { + return new Dijkstra(); + } + } } diff --git a/src/Itinero/Routing/Flavours/Dijkstra/EdgeBased/Dijkstra.cs b/src/Itinero/Routing/Flavours/Dijkstra/EdgeBased/Dijkstra.cs index 47d33a2f2..c0fcb1349 100644 --- a/src/Itinero/Routing/Flavours/Dijkstra/EdgeBased/Dijkstra.cs +++ b/src/Itinero/Routing/Flavours/Dijkstra/EdgeBased/Dijkstra.cs @@ -30,12 +30,14 @@ internal class Dijkstra Func<(EdgeId edgeId, VertexId vertexId), Task>? settled = null, Func<(EdgeId edgeId, VertexId vertexId), Task>? 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>? settled = null, @@ -52,7 +54,8 @@ internal class Dijkstra Func<(EdgeId edgeId, VertexId vertexId), Task>? settled = null, Func<(EdgeId edgeId, VertexId vertexId), Task>? 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); } /// @@ -66,7 +69,8 @@ internal class Dijkstra /// 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) /// /// - 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>? settled = null, @@ -443,10 +447,14 @@ await queued((enumerator.EdgeId, enumerator.Head))) return paths; } - private static readonly ThreadLocal DefaultLazy = new(() => new Dijkstra()); - /// - /// Gets the default dijkstra instance (for the local thread). + /// Gets a default dijkstra instance. /// - public static Dijkstra Default => DefaultLazy.Value; + public static Dijkstra Default + { + get + { + return new Dijkstra(); + } + } } diff --git a/src/Itinero/Search/RoutingNetworkQuery.cs b/src/Itinero/Search/RoutingNetworkQuery.cs index 86b03a18d..fdc11f212 100644 --- a/src/Itinero/Search/RoutingNetworkQuery.cs +++ b/src/Itinero/Search/RoutingNetworkQuery.cs @@ -20,7 +20,7 @@ public async IAsyncEnumerable Vertices( { await _network.UsageNotifier.NotifyBox(_network, box, cancellationToken); if (cancellationToken.IsCancellationRequested) yield break; - + var vertices = _network.SearchVerticesInBox(box); foreach (var (vertex, _) in vertices) {